Skip to content

Commit a50c28e

Browse files
committed
fixup integrations
1 parent 53d0084 commit a50c28e

File tree

9 files changed

+110
-23
lines changed

9 files changed

+110
-23
lines changed

internal/controller/atlas/provider.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,18 @@ func (p *ProductionProvider) SdkClientSet(ctx context.Context, creds *Credential
162162
return nil, err
163163
}
164164

165+
clientv20241113002, err := adminv20250312002.NewClient(
166+
adminv20250312002.UseBaseURL(p.domain),
167+
adminv20250312002.UseHTTPClient(httpClient),
168+
adminv20250312002.UseUserAgent(operatorUserAgent()))
169+
if err != nil {
170+
return nil, err
171+
}
172+
165173
return &ClientSet{
166174
SdkClient20231115008: clientv20231115008,
167175
SdkClient20241113001: clientv20241113001,
176+
SdkClient20250312002: clientv20241113002,
168177
}, nil
169178
}
170179

internal/controller/atlasthirdpartyintegrations/handler.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020

21+
"go.uber.org/zap"
2122
ctrl "sigs.k8s.io/controller-runtime"
2223
"sigs.k8s.io/controller-runtime/pkg/client"
2324
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -45,11 +46,22 @@ type reconcileRequest struct {
4546
Service thirdpartyintegration.ThirdPartyIntegrationService
4647
}
4748

48-
func NewAtlasThirdPartyIntegrationsReconciler() *ctrlstate.Reconciler[akov2next.AtlasThirdPartyIntegration] {
49-
return ctrlstate.NewStateReconciler(&AtlasThirdPartyIntegrationHandler{})
49+
func NewAtlasThirdPartyIntegrationsReconciler(
50+
atlasProvider atlas.Provider,
51+
logger *zap.Logger,
52+
globalSecretRef client.ObjectKey,
53+
) *ctrlstate.Reconciler[akov2next.AtlasThirdPartyIntegration] {
54+
return ctrlstate.NewStateReconciler(&AtlasThirdPartyIntegrationHandler{
55+
AtlasReconciler: reconciler.AtlasReconciler{
56+
AtlasProvider: atlasProvider,
57+
Log: logger.Named("controllers").Named("AtlasThirdPartyIntegration").Sugar(),
58+
GlobalSecretRef: globalSecretRef,
59+
},
60+
})
5061
}
5162

5263
func (h *AtlasThirdPartyIntegrationHandler) SetupWithManager(mgr ctrl.Manager, rec reconcile.Reconciler) error {
64+
// TODO indexers wiring
5365
h.Client = mgr.GetClient()
5466
obj := &akov2next.AtlasThirdPartyIntegration{}
5567
return internalbuilder.NewDefaultSetupWithManager(mgr, rec, obj)
@@ -118,26 +130,28 @@ func (h *AtlasThirdPartyIntegrationHandler) populateIntegration(ctx context.Cont
118130

119131
func fetchIntegrationSecrets(ctx context.Context, kubeClient client.Client, integration *akov2next.AtlasThirdPartyIntegration) (map[string][]byte, error) {
120132
ks := secret.NewKubernetesSecretProvider(kubeClient)
133+
secretName := ""
121134
switch integration.Spec.Type {
122135
case "DATADOG":
123-
return ks.Fetch(ctx, integration.Spec.Datadog.APIKeySecret.Name)
136+
secretName = integration.Spec.Datadog.APIKeySecret.Name
124137
case "MICROSOFT_TEAMS":
125-
return ks.Fetch(ctx, integration.Spec.MicrosoftTeams.URLSecret.Name)
138+
secretName = integration.Spec.MicrosoftTeams.URLSecret.Name
126139
case "NEW_RELIC":
127-
return ks.Fetch(ctx, integration.Spec.NewRelic.CredentialsSecret.Name)
140+
secretName = integration.Spec.NewRelic.CredentialsSecret.Name
128141
case "OPS_GENIE":
129-
return ks.Fetch(ctx, integration.Spec.OpsGenie.APIKeySecret.Name)
142+
secretName = integration.Spec.OpsGenie.APIKeySecret.Name
130143
case "PAGER_DUTY":
131-
return ks.Fetch(ctx, integration.Spec.PagerDuty.ServiceKeySecret.Name)
144+
secretName = integration.Spec.PagerDuty.ServiceKeySecret.Name
132145
case "PROMETHEUS":
133-
return ks.Fetch(ctx, integration.Spec.Prometheus.PrometheusCredentialsSecret.Name)
146+
secretName = integration.Spec.Prometheus.PrometheusCredentialsSecret.Name
134147
case "SLACK":
135-
return ks.Fetch(ctx, integration.Spec.Slack.APITokenSecret.Name)
148+
secretName = integration.Spec.Slack.APITokenSecret.Name
136149
case "VICTOR_OPS":
137-
return ks.Fetch(ctx, integration.Spec.VictorOps.APIKeySecret.Name)
150+
secretName = integration.Spec.VictorOps.APIKeySecret.Name
138151
case "WEBHOOK":
139-
return ks.Fetch(ctx, integration.Spec.Webhook.URLSecret.Name)
152+
secretName = integration.Spec.Webhook.URLSecret.Name
140153
default:
141154
return nil, fmt.Errorf("%w %v", thirdpartyintegration.ErrUnsupportedIntegrationType, integration.Spec.Type)
142155
}
156+
return ks.Fetch(ctx, secretName, integration.Namespace)
143157
}

internal/next-crds/atlas.nextapi.mongodb.com_atlasthirdpartyintegrations.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,11 @@ spec:
409409
description: ID of the third party integration resource in Atlas
410410
type: string
411411
observedGeneration:
412-
description: ObservedGeneration tracks the generation the status value
413-
was derived from
412+
description: |-
413+
ObservedGeneration indicates the generation of the resource specification
414+
that the Atlas Operator is aware of.
415+
The Atlas Operator updates this field to the 'metadata.generation' as
416+
soon as it starts reconciliation of the resource.
414417
format: int64
415418
type: integer
416419
required:

internal/nextapi/v1/status/atlasthirdpartyintegration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package status
1616

17+
// +k8s:deepcopy-gen=true
18+
1719
// AtlasThirdPartyIntegrationStatus holds the status of an integration
1820
type AtlasThirdPartyIntegrationStatus struct {
1921
UnifiedStatus `json:",inline"`
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
// Copyright 2025 MongoDB.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package status
216

317
import (
418
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
519
)
620

7-
// UnifiedStatus
21+
// +k8s:deepcopy-gen=true
22+
23+
// UnifiedStatus is shared by CRDs with Unified State Machine support
824
type UnifiedStatus struct {
925
// Conditions holding the status details
1026
Conditions []metav1.Condition `json:"conditions"`
1127

12-
// ObservedGeneration tracks the generation the status value was derived from
28+
// ObservedGeneration indicates the generation of the resource specification
29+
// that the Atlas Operator is aware of.
30+
// The Atlas Operator updates this field to the 'metadata.generation' as
31+
// soon as it starts reconciliation of the resource.
1332
ObservedGeneration int64 `json:"observedGeneration"`
1433
}

internal/nextapi/v1/status/zz_generated.deepcopy.go

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/translation/thirdpartyintegration/conversion.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewFromSpec(crd *akov2next.AtlasThirdPartyIntegration, secrets map[string][
3838
switch tpi.Type {
3939
case "DATADOG":
4040
tpi.DatadogSecrets = &DatadogSecrets{
41-
APIKey: string(secrets["apikey"]),
41+
APIKey: string(secrets["apiKey"]),
4242
}
4343
case "MICROSOFT_TEAMS":
4444
tpi.MicrosoftTeamsSecrets = &MicrosoftTeamsSecrets{
@@ -53,7 +53,7 @@ func NewFromSpec(crd *akov2next.AtlasThirdPartyIntegration, secrets map[string][
5353
}
5454
case "OPS_GENIE":
5555
tpi.OpsGenieSecrets = &OpsGenieSecrets{
56-
APIKey: string(secrets["apikey"]),
56+
APIKey: string(secrets["apiKey"]),
5757
}
5858
case "PAGER_DUTY":
5959
tpi.PagerDutySecrets = &PagerDutySecrets{
@@ -70,7 +70,7 @@ func NewFromSpec(crd *akov2next.AtlasThirdPartyIntegration, secrets map[string][
7070
}
7171
case "VICTOR_OPS":
7272
tpi.VictorOpsSecrets = &VictorOpsSecrets{
73-
APIKey: string(secrets["apikey"]),
73+
APIKey: string(secrets["apiKey"]),
7474
}
7575
case "WEBHOOK":
7676
tpi.WebhookSecrets = &WebhookSecrets{

pkg/secret/secret.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
type Secret map[string][]byte
2626

2727
type SecretProvider interface {
28-
Fetch(ctx context.Context, name string) (Secret, error)
28+
Fetch(ctx context.Context, name, namespace string) (Secret, error)
2929
}
3030

3131
type kubernetesSecrets struct {
@@ -36,9 +36,9 @@ func NewKubernetesSecretProvider(c client.Client) SecretProvider {
3636
return &kubernetesSecrets{client: c}
3737
}
3838

39-
func (ks *kubernetesSecrets) Fetch(ctx context.Context, secretName string) (Secret, error) {
39+
func (ks *kubernetesSecrets) Fetch(ctx context.Context, secretName, namespace string) (Secret, error) {
4040
secret := v1.Secret{}
41-
err := ks.client.Get(ctx, client.ObjectKey{Name: secretName}, &secret)
41+
err := ks.client.Get(ctx, client.ObjectKey{Name: secretName, Namespace: namespace}, &secret)
4242
if err != nil {
4343
return nil, fmt.Errorf("failed to fetch secret %q: %w", secretName, err)
4444
}

pkg/secret/secret_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestKubernetesSecretProvider(t *testing.T) {
4646
WithObjects(&testSecret).Build()
4747
ctx := context.TODO()
4848

49-
fetched, err := secret.NewKubernetesSecretProvider(fakeClient).Fetch(ctx, testSecret.Name)
49+
fetched, err := secret.NewKubernetesSecretProvider(fakeClient).Fetch(ctx, testSecret.Name, testSecret.Namespace)
5050
require.NoError(t, err)
5151
assert.Equal(t, want, fetched)
5252
}

0 commit comments

Comments
 (0)