Skip to content

Commit 433ae3e

Browse files
authored
CLOUDP-260438: Fix redacted integrations comparisons (#1691)
* CLOUDP-260438: [Fixed] Fix redacted integrations comparisons Signed-off-by: jose.vazquez <[email protected]> * Allow Gov tests to run on PRs --------- Signed-off-by: jose.vazquez <[email protected]>
1 parent a7d1793 commit 433ae3e

File tree

5 files changed

+347
-43
lines changed

5 files changed

+347
-43
lines changed

.github/workflows/test-e2e-gov.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
jobs:
88
e2e-gov:
99
name: E2E Gov tests
10-
if: github.event_name == 'merge_group' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
1110
runs-on: ubuntu-latest
1211
steps:
1312
- name: Check out code

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ GOMOD_LICENSES_SHA := $(shell cat $(LICENSES_GOMOD_SHA_FILE))
105105
OPERATOR_NAMESPACE=atlas-operator
106106
OPERATOR_POD_NAME=mongodb-atlas-operator
107107
RUN_YAML= # Set to the YAML to run when calling make run
108+
RUN_LOG_LEVEL ?= debug
108109

109110
LOCAL_IMAGE=mongodb-atlas-kubernetes-operator:compiled
110111
CONTAINER_SPEC=.spec.template.spec.containers[0]
@@ -533,7 +534,7 @@ ifdef RUN_YAML
533534
endif
534535
OPERATOR_POD_NAME=$(OPERATOR_POD_NAME) \
535536
OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) \
536-
bin/manager --object-deletion-protection=false --log-level=debug \
537+
bin/manager --object-deletion-protection=false --log-level=$(RUN_LOG_LEVEL) \
537538
--atlas-domain=$(ATLAS_DOMAIN) \
538539
--global-api-secret-name=$(ATLAS_KEY_SECRET_NAME)
539540

internal/mocks/atlas/integrations.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package atlas
2+
3+
import (
4+
"context"
5+
6+
"go.mongodb.org/atlas/mongodbatlas"
7+
)
8+
9+
type IntegrationsMock struct {
10+
CreateFunc func(ctx context.Context, projectID string, integrationType string, integration *mongodbatlas.ThirdPartyIntegration) (*mongodbatlas.ThirdPartyIntegrations, *mongodbatlas.Response, error)
11+
ReplaceFunc func(ctx context.Context, projectID string, integrationType string, integration *mongodbatlas.ThirdPartyIntegration) (*mongodbatlas.ThirdPartyIntegrations, *mongodbatlas.Response, error)
12+
DeleteFunc func(ctx context.Context, projectID string, integrationType string) (*mongodbatlas.Response, error)
13+
GetFunc func(ctx context.Context, projectID string, integrationType string) (*mongodbatlas.ThirdPartyIntegration, *mongodbatlas.Response, error)
14+
ListFunc func(ctx context.Context, projectID string) (*mongodbatlas.ThirdPartyIntegrations, *mongodbatlas.Response, error)
15+
}
16+
17+
func (im *IntegrationsMock) Create(ctx context.Context, projectID string, integrationType string, integration *mongodbatlas.ThirdPartyIntegration) (*mongodbatlas.ThirdPartyIntegrations, *mongodbatlas.Response, error) {
18+
return im.CreateFunc(ctx, projectID, integrationType, integration)
19+
}
20+
21+
func (im *IntegrationsMock) Replace(ctx context.Context, projectID string, integrationType string, integration *mongodbatlas.ThirdPartyIntegration) (*mongodbatlas.ThirdPartyIntegrations, *mongodbatlas.Response, error) {
22+
return im.ReplaceFunc(ctx, projectID, integrationType, integration)
23+
}
24+
25+
func (im *IntegrationsMock) Delete(ctx context.Context, projectID string, integrationType string) (*mongodbatlas.Response, error) {
26+
return im.DeleteFunc(ctx, projectID, integrationType)
27+
}
28+
29+
func (im *IntegrationsMock) Get(ctx context.Context, projectID string, integrationType string) (*mongodbatlas.ThirdPartyIntegration, *mongodbatlas.Response, error) {
30+
return im.GetFunc(ctx, projectID, integrationType)
31+
}
32+
33+
func (im *IntegrationsMock) List(ctx context.Context, projectID string) (*mongodbatlas.ThirdPartyIntegrations, *mongodbatlas.Response, error) {
34+
return im.ListFunc(ctx, projectID)
35+
}

pkg/controller/atlasproject/integrations.go

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"net/http"
66
"net/url"
7-
"reflect"
87

98
"go.mongodb.org/atlas/mongodbatlas"
109

@@ -82,11 +81,11 @@ func (r *AtlasProjectReconciler) updateIntegrationsAtlas(ctx *workflow.Context,
8281
ctx.Log.Warnw("Update Integrations", "Can not convert kube integration", err)
8382
return workflow.Terminate(workflow.ProjectIntegrationInternal, "Update Integrations: Can not convert kube integration")
8483
}
85-
t := mongodbatlas.ThirdPartyIntegration(atlasIntegration)
86-
if &t != kubeIntegration {
84+
specIntegration := (*aliasThirdPartyIntegration)(kubeIntegration)
85+
if !areIntegrationsEqual(specIntegration, &atlasIntegration) {
8786
ctx.Log.Debugf("Try to update integration: %s", kubeIntegration.Type)
8887
if _, _, err := ctx.Client.Integrations.Replace(ctx.Context, projectID, kubeIntegration.Type, kubeIntegration); err != nil {
89-
return workflow.Terminate(workflow.ProjectIntegrationRequest, "Can not convert integration")
88+
return workflow.Terminate(workflow.ProjectIntegrationRequest, fmt.Sprintf("Can not apply integration: %v", err))
9089
}
9190
}
9291
}
@@ -136,7 +135,7 @@ func (r *AtlasProjectReconciler) checkIntegrationsReady(ctx *workflow.Context, n
136135
} else {
137136
specAsAtlas, _ := spec.ToAtlas(ctx.Context, r.Client, namespace)
138137
specAlias := aliasThirdPartyIntegration(*specAsAtlas)
139-
areEqual = AreIntegrationsEqual(&atlas, &specAlias)
138+
areEqual = integrationsApplied(&atlas, &specAlias)
140139
}
141140
ctx.Log.Debugw("checkIntegrationsReady", "atlas", atlas, "spec", spec, "areEqual", areEqual)
142141

@@ -148,41 +147,21 @@ func (r *AtlasProjectReconciler) checkIntegrationsReady(ctx *workflow.Context, n
148147
return true
149148
}
150149

151-
func AreIntegrationsEqual(atlas, specAsAtlas *aliasThirdPartyIntegration) bool {
152-
return reflect.DeepEqual(cleanCopyToCompare(atlas), cleanCopyToCompare(specAsAtlas))
153-
}
154-
155-
func cleanCopyToCompare(input *aliasThirdPartyIntegration) *aliasThirdPartyIntegration {
156-
if input == nil {
157-
return input
158-
}
159-
160-
result := *input
161-
keepLastFourChars(&result.APIKey)
162-
keepLastFourChars(&result.APIToken)
163-
keepLastFourChars(&result.LicenseKey)
164-
keepLastFourChars(&result.Password)
165-
keepLastFourChars(&result.ReadToken)
166-
keepLastFourChars(&result.RoutingKey)
167-
keepLastFourChars(&result.Secret)
168-
keepLastFourChars(&result.ServiceKey)
169-
keepLastFourChars(&result.WriteToken)
170-
171-
return &result
150+
func integrationsApplied(_, _ *aliasThirdPartyIntegration) bool {
151+
// As integration secrets are redacted from Alas, we cannot properly compare them,
152+
// so as a simple fix here we assume changes were applied correctly as we would
153+
// have otherwise errored out as are always needed
154+
// TODO: remove and replace calls to this with areIntegrationsEqual when
155+
// that code is properly comparing fields
156+
return true
172157
}
173158

174-
func keepLastFourChars(strPtr *string) {
175-
if strPtr == nil {
176-
return
177-
}
178-
179-
charCount := 4
180-
str := *strPtr
181-
if len(str) <= charCount {
182-
return
183-
}
184-
185-
*strPtr = str[len(str)-charCount:]
159+
func areIntegrationsEqual(_, _ *aliasThirdPartyIntegration) bool {
160+
// As integration secrets are redacted from Alas, we cannot properly compare them,
161+
// so as a simple fix we assume changes are always needed
162+
// TODO: Compare using Atlas redacted fields with checksums if accepted OR
163+
// move to implicit state checks if Atlas cannot help with this.
164+
return false
186165
}
187166

188167
type aliasThirdPartyIntegration mongodbatlas.ThirdPartyIntegration

0 commit comments

Comments
 (0)