4
4
"fmt"
5
5
"net/http"
6
6
"net/url"
7
- "reflect"
8
7
9
8
"go.mongodb.org/atlas/mongodbatlas"
10
9
@@ -82,11 +81,11 @@ func (r *AtlasProjectReconciler) updateIntegrationsAtlas(ctx *workflow.Context,
82
81
ctx .Log .Warnw ("Update Integrations" , "Can not convert kube integration" , err )
83
82
return workflow .Terminate (workflow .ProjectIntegrationInternal , "Update Integrations: Can not convert kube integration" )
84
83
}
85
- t := mongodbatlas . ThirdPartyIntegration ( atlasIntegration )
86
- if & t != kubeIntegration {
84
+ specIntegration := ( * aliasThirdPartyIntegration )( kubeIntegration )
85
+ if ! areIntegrationsEqual ( specIntegration , & atlasIntegration ) {
87
86
ctx .Log .Debugf ("Try to update integration: %s" , kubeIntegration .Type )
88
87
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 ) )
90
89
}
91
90
}
92
91
}
@@ -136,7 +135,7 @@ func (r *AtlasProjectReconciler) checkIntegrationsReady(ctx *workflow.Context, n
136
135
} else {
137
136
specAsAtlas , _ := spec .ToAtlas (ctx .Context , r .Client , namespace )
138
137
specAlias := aliasThirdPartyIntegration (* specAsAtlas )
139
- areEqual = AreIntegrationsEqual (& atlas , & specAlias )
138
+ areEqual = integrationsApplied (& atlas , & specAlias )
140
139
}
141
140
ctx .Log .Debugw ("checkIntegrationsReady" , "atlas" , atlas , "spec" , spec , "areEqual" , areEqual )
142
141
@@ -148,41 +147,21 @@ func (r *AtlasProjectReconciler) checkIntegrationsReady(ctx *workflow.Context, n
148
147
return true
149
148
}
150
149
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
172
157
}
173
158
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
186
165
}
187
166
188
167
type aliasThirdPartyIntegration mongodbatlas.ThirdPartyIntegration
0 commit comments