Skip to content

Commit

Permalink
Revert "Draft triage (#1684)" (#1690)
Browse files Browse the repository at this point in the history
This reverts commit 2711915.
  • Loading branch information
josvazg authored Jul 12, 2024
1 parent 2711915 commit a7d1793
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 347 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ GOMOD_LICENSES_SHA := $(shell cat $(LICENSES_GOMOD_SHA_FILE))
OPERATOR_NAMESPACE=atlas-operator
OPERATOR_POD_NAME=mongodb-atlas-operator
RUN_YAML= # Set to the YAML to run when calling make run
RUN_LOG_LEVEL ?= debug

LOCAL_IMAGE=mongodb-atlas-kubernetes-operator:compiled
CONTAINER_SPEC=.spec.template.spec.containers[0]
Expand Down Expand Up @@ -534,7 +533,7 @@ ifdef RUN_YAML
endif
OPERATOR_POD_NAME=$(OPERATOR_POD_NAME) \
OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) \
bin/manager --object-deletion-protection=false --log-level=$(RUN_LOG_LEVEL) \
bin/manager --object-deletion-protection=false --log-level=debug \
--atlas-domain=$(ATLAS_DOMAIN) \
--global-api-secret-name=$(ATLAS_KEY_SECRET_NAME)

Expand Down
35 changes: 0 additions & 35 deletions internal/mocks/atlas/integrations.go

This file was deleted.

55 changes: 38 additions & 17 deletions pkg/controller/atlasproject/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/url"
"reflect"

"go.mongodb.org/atlas/mongodbatlas"

Expand Down Expand Up @@ -81,11 +82,11 @@ func (r *AtlasProjectReconciler) updateIntegrationsAtlas(ctx *workflow.Context,
ctx.Log.Warnw("Update Integrations", "Can not convert kube integration", err)
return workflow.Terminate(workflow.ProjectIntegrationInternal, "Update Integrations: Can not convert kube integration")
}
specIntegration := (*aliasThirdPartyIntegration)(kubeIntegration)
if !areIntegrationsEqual(specIntegration, &atlasIntegration) {
t := mongodbatlas.ThirdPartyIntegration(atlasIntegration)
if &t != kubeIntegration {
ctx.Log.Debugf("Try to update integration: %s", kubeIntegration.Type)
if _, _, err := ctx.Client.Integrations.Replace(ctx.Context, projectID, kubeIntegration.Type, kubeIntegration); err != nil {
return workflow.Terminate(workflow.ProjectIntegrationRequest, fmt.Sprintf("Can not apply integration: %v", err))
return workflow.Terminate(workflow.ProjectIntegrationRequest, "Can not convert integration")
}
}
}
Expand Down Expand Up @@ -135,7 +136,7 @@ func (r *AtlasProjectReconciler) checkIntegrationsReady(ctx *workflow.Context, n
} else {
specAsAtlas, _ := spec.ToAtlas(ctx.Context, r.Client, namespace)
specAlias := aliasThirdPartyIntegration(*specAsAtlas)
areEqual = integrationsApplied(&atlas, &specAlias)
areEqual = AreIntegrationsEqual(&atlas, &specAlias)
}
ctx.Log.Debugw("checkIntegrationsReady", "atlas", atlas, "spec", spec, "areEqual", areEqual)

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

func integrationsApplied(_, _ *aliasThirdPartyIntegration) bool {
// As integration secrets are redacted from Alas, we cannot properly compare them,
// so as a simple fix here we assume changes were applied correctly as we would
// have otherwise errored out as are always needed
// TODO: remove and replace calls to this with areIntegrationsEqual when
// that code is properly comparing fields
return true
func AreIntegrationsEqual(atlas, specAsAtlas *aliasThirdPartyIntegration) bool {
return reflect.DeepEqual(cleanCopyToCompare(atlas), cleanCopyToCompare(specAsAtlas))
}

func cleanCopyToCompare(input *aliasThirdPartyIntegration) *aliasThirdPartyIntegration {
if input == nil {
return input
}

result := *input
keepLastFourChars(&result.APIKey)
keepLastFourChars(&result.APIToken)
keepLastFourChars(&result.LicenseKey)
keepLastFourChars(&result.Password)
keepLastFourChars(&result.ReadToken)
keepLastFourChars(&result.RoutingKey)
keepLastFourChars(&result.Secret)
keepLastFourChars(&result.ServiceKey)
keepLastFourChars(&result.WriteToken)

return &result
}

func areIntegrationsEqual(_, _ *aliasThirdPartyIntegration) bool {
// As integration secrets are redacted from Alas, we cannot properly compare them,
// so as a simple fix we assume changes are always needed
// TODO: Compare using Atlas redacted fields with checksums if accepted OR
// move to implicit state checks if Atlas cannot help with this.
return false
func keepLastFourChars(strPtr *string) {
if strPtr == nil {
return
}

charCount := 4
str := *strPtr
if len(str) <= charCount {
return
}

*strPtr = str[len(str)-charCount:]
}

type aliasThirdPartyIntegration mongodbatlas.ThirdPartyIntegration
Expand Down
Loading

0 comments on commit a7d1793

Please sign in to comment.