Skip to content

Commit d524a6f

Browse files
committed
Fix hash code reconciliation
1 parent 6dd198f commit d524a6f

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

api/v1/hasher.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,3 @@ func ComputeHash(in interface{}, collisionCount *int32) string {
6262

6363
return rand.SafeEncodeString(fmt.Sprint(hasher.Sum32()))
6464
}
65-
66-
//// DeepHashObject writes specified object to hash using the spew library
67-
//// which follows pointers and prints actual values of the nested objects
68-
//// ensuring the hash does not change when a pointer changes.
69-
//func DeepHashObject(hasher hash.Hash, objectToWrite interface{}) {
70-
// b, _ := json.Marshal(objectToWrite)
71-
// hasher.Write(b)
72-
//}

controllers/coherence_controller.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,20 @@ func (in *CoherenceReconciler) Reconcile(ctx context.Context, request ctrl.Reque
221221

222222
if found {
223223
// The "storeHash" is not "", so it must have been processed by the Operator (could have been a previous version).
224-
// There was a bug prior to 3.2.8 where the hash was calculated at the wrong point in the defaulting web-hook,
225-
// so the "currentHash" may be wrong, and hence differ from the recalculated "hash".
226-
if deployment.IsBeforeVersion("3.3.0") {
224+
// There was a bug prior to 3.4.2 where the hash was calculated at the wrong point in the defaulting web-hook,
225+
// and the has used only a portion of the spec, so the "currentHash" may be wrong, and hence differ from the
226+
// recalculated "hash".
227+
if deployment.IsBeforeVersion("3.4.2") {
227228
// the AnnotationOperatorVersion annotation was added in the 3.2.8 web-hook, so if it is missing
228-
// the Coherence resource was added or updated prior to 3.2.8
229-
// In this case we just ignore the difference in hash.
229+
// the Coherence resource was added or updated prior to 3.2.8, or the version is present but is
230+
// prior to 3.4.2. In this case we just ignore the difference in hash.
230231
// There is an edge case where the Coherence resource could have legitimately been updated whilst
231232
// the Operator and web-hooks were uninstalled. In that case we would ignore the update until another
232233
// update is made. The simplest way for the customer to work around this is to add the
233234
// AnnotationOperatorVersion annotation with some value, which will then be overwritten by the web-hook
234235
// and the Coherence resource will be correctly processes.
235236
desiredResources = storage.GetLatest()
236-
log.Info("Ignoring hash difference for pre-3.2.8 resource", "hash", hash, "store", storeHash)
237+
log.Info("Ignoring hash difference for pre-3.4.2 resource", "hash", hash, "store", storeHash)
237238
}
238239
}
239240
} else {
@@ -340,6 +341,7 @@ func (in *CoherenceReconciler) SetupWithManager(mgr ctrl.Manager, cs clients.Cli
340341
func (in *CoherenceReconciler) GetReconciler() reconcile.Reconciler { return in }
341342

342343
// ensureHashApplied ensures that the hash label is present in the Coherence resource, patching it if required
344+
// Returns true if the hash label was applied to the Coherence resource, or false if the label was already present
343345
func (in *CoherenceReconciler) ensureHashApplied(ctx context.Context, c *coh.Coherence) (bool, error) {
344346
currentHash := ""
345347
labels := c.GetLabels()

controllers/coherencejob_controller.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,32 @@ func (in *CoherenceJobReconciler) ReconcileDeployment(ctx context.Context, reque
163163
var desiredResources coh.Resources
164164

165165
storeHash, found := storage.GetHash()
166-
if !found || storeHash != hash || status.Phase != coh.ConditionTypeReady {
166+
if !found || storeHash != hash || deployment.Status.Phase != coh.ConditionTypeReady {
167167
// Storage state was saved with no hash or a different hash so is not in the desired state
168-
// or the CoherenceJob resource is not in the Ready state
168+
// or the Coherence resource is not in the Ready state
169169
// Create the desired resources the deployment
170170
if desiredResources, err = deployment.CreateKubernetesResources(); err != nil {
171171
return in.HandleErrAndRequeue(ctx, err, nil, fmt.Sprintf(createResourcesFailedMessage, request.Name, request.Namespace, err), in.Log)
172172
}
173+
174+
if found {
175+
// The "storeHash" is not "", so it must have been processed by the Operator (could have been a previous version).
176+
// There was a bug prior to 3.4.2 where the hash was calculated at the wrong point in the defaulting web-hook,
177+
// and the has used only a portion of the spec, so the "currentHash" may be wrong, and hence differ from the
178+
// recalculated "hash".
179+
if deployment.IsBeforeVersion("3.4.2") {
180+
// the AnnotationOperatorVersion annotation was added in the 3.2.8 web-hook, so if it is missing
181+
// the Coherence resource was added or updated prior to 3.2.8, or the version is present but is
182+
// prior to 3.4.2. In this case we just ignore the difference in hash.
183+
// There is an edge case where the Coherence resource could have legitimately been updated whilst
184+
// the Operator and web-hooks were uninstalled. In that case we would ignore the update until another
185+
// update is made. The simplest way for the customer to work around this is to add the
186+
// AnnotationOperatorVersion annotation with some value, which will then be overwritten by the web-hook
187+
// and the Coherence resource will be correctly processes.
188+
desiredResources = storage.GetLatest()
189+
log.Info("Ignoring hash difference for pre-3.4.2 resource", "hash", hash, "store", storeHash)
190+
}
191+
}
173192
} else {
174193
// storage state was saved with the current hash so is already in the desired state
175194
desiredResources = storage.GetLatest()

0 commit comments

Comments
 (0)