Skip to content

Commit 7692cc5

Browse files
committed
Fix hash code reconciliation
1 parent d524a6f commit 7692cc5

File tree

3 files changed

+68
-63
lines changed

3 files changed

+68
-63
lines changed

controllers/coherence_controller.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -208,38 +208,12 @@ func (in *CoherenceReconciler) Reconcile(ctx context.Context, request ctrl.Reque
208208
}
209209

210210
hash := deployment.GetLabels()[coh.LabelCoherenceHash]
211+
storeHash, _ := storage.GetHash()
211212
var desiredResources coh.Resources
212213

213-
storeHash, found := storage.GetHash()
214-
if !found || storeHash != hash || deployment.Status.Phase != coh.ConditionTypeReady {
215-
// Storage state was saved with no hash or a different hash so is not in the desired state
216-
// or the Coherence resource is not in the Ready state
217-
// Create the desired resources the deployment
218-
if desiredResources, err = deployment.CreateKubernetesResources(); err != nil {
219-
return in.HandleErrAndRequeue(ctx, err, nil, fmt.Sprintf(createResourcesFailedMessage, request.Name, request.Namespace, err), in.Log)
220-
}
221-
222-
if found {
223-
// 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.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") {
228-
// the AnnotationOperatorVersion annotation was added in the 3.2.8 web-hook, so if it is missing
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.
231-
// There is an edge case where the Coherence resource could have legitimately been updated whilst
232-
// the Operator and web-hooks were uninstalled. In that case we would ignore the update until another
233-
// update is made. The simplest way for the customer to work around this is to add the
234-
// AnnotationOperatorVersion annotation with some value, which will then be overwritten by the web-hook
235-
// and the Coherence resource will be correctly processes.
236-
desiredResources = storage.GetLatest()
237-
log.Info("Ignoring hash difference for pre-3.4.2 resource", "hash", hash, "store", storeHash)
238-
}
239-
}
240-
} else {
241-
// storage state was saved with the current hash so is already in the desired state
242-
desiredResources = storage.GetLatest()
214+
desiredResources, err = checkCoherenceHash(deployment, storage, log)
215+
if err != nil {
216+
return in.HandleErrAndRequeue(ctx, err, nil, fmt.Sprintf(createResourcesFailedMessage, request.Name, request.Namespace, err), in.Log)
243217
}
244218

245219
// create the result
@@ -284,9 +258,6 @@ func (in *CoherenceReconciler) Reconcile(ctx context.Context, request ctrl.Reque
284258
}
285259
return reconcile.Result{}, fmt.Errorf("one or more secondary resource reconcilers failed to reconcile")
286260
}
287-
//} else {
288-
// log.Info("Skipping updates for Coherence resource, annotation " + coh.AnnotationOperatorIgnore + " is set to true")
289-
//}
290261

291262
// if replica count is zero update the status to Stopped
292263
if deployment.GetReplicas() == 0 {

controllers/coherencejob_controller.go

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,12 @@ func (in *CoherenceJobReconciler) ReconcileDeployment(ctx context.Context, reque
160160
}
161161

162162
hash := deployment.GetLabels()[coh.LabelCoherenceHash]
163+
storeHash, _ := storage.GetHash()
163164
var desiredResources coh.Resources
164165

165-
storeHash, found := storage.GetHash()
166-
if !found || storeHash != hash || deployment.Status.Phase != coh.ConditionTypeReady {
167-
// Storage state was saved with no hash or a different hash so is not in the desired state
168-
// or the Coherence resource is not in the Ready state
169-
// Create the desired resources the deployment
170-
if desiredResources, err = deployment.CreateKubernetesResources(); err != nil {
171-
return in.HandleErrAndRequeue(ctx, err, nil, fmt.Sprintf(createResourcesFailedMessage, request.Name, request.Namespace, err), in.Log)
172-
}
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-
}
192-
} else {
193-
// storage state was saved with the current hash so is already in the desired state
194-
desiredResources = storage.GetLatest()
166+
desiredResources, err = checkJobHash(deployment, storage, log)
167+
if err != nil {
168+
return in.HandleErrAndRequeue(ctx, err, nil, fmt.Sprintf(createResourcesFailedMessage, request.Name, request.Namespace, err), in.Log)
195169
}
196170

197171
// create the result

controllers/common.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
3+
* Licensed under the Universal Permissive License v 1.0 as shown at
4+
* http://oss.oracle.com/licenses/upl.
5+
*/
6+
7+
package controllers
8+
9+
import (
10+
"github.com/go-logr/logr"
11+
coh "github.com/oracle/coherence-operator/api/v1"
12+
"github.com/oracle/coherence-operator/pkg/utils"
13+
)
14+
15+
func checkCoherenceHash(deployment *coh.Coherence, storage utils.Storage, log logr.Logger) (coh.Resources, error) {
16+
return checkHash(deployment, deployment.Status.Phase, storage, log)
17+
}
18+
19+
func checkJobHash(deployment *coh.CoherenceJob, storage utils.Storage, log logr.Logger) (coh.Resources, error) {
20+
return checkHash(deployment, deployment.Status.Phase, storage, log)
21+
}
22+
23+
func checkHash(deployment coh.CoherenceResource, phase coh.ConditionType, storage utils.Storage, log logr.Logger) (coh.Resources, error) {
24+
hash := deployment.GetLabels()[coh.LabelCoherenceHash]
25+
var desiredResources coh.Resources
26+
var err error
27+
28+
storeHash, found := storage.GetHash()
29+
if !found || storeHash != hash || phase != coh.ConditionTypeReady {
30+
// Storage state was saved with no hash or a different hash so is not in the desired state
31+
// or the Coherence resource is not in the Ready state
32+
// Create the desired resources the deployment
33+
if desiredResources, err = deployment.CreateKubernetesResources(); err != nil {
34+
return desiredResources, err
35+
}
36+
37+
if found {
38+
// The "storeHash" is not "", so it must have been processed by the Operator (could have been a previous version).
39+
// There was a bug prior to 3.4.2 where the hash was calculated at the wrong point in the defaulting web-hook,
40+
// and the has used only a portion of the spec, so the "currentHash" may be wrong, and hence differ from the
41+
// recalculated "hash".
42+
if deployment.IsBeforeVersion("3.4.2") {
43+
// the AnnotationOperatorVersion annotation was added in the 3.2.8 web-hook, so if it is missing
44+
// the Coherence resource was added or updated prior to 3.2.8, or the version is present but is
45+
// prior to 3.4.2. In this case we just ignore the difference in hash.
46+
// There is an edge case where the Coherence resource could have legitimately been updated whilst
47+
// the Operator and web-hooks were uninstalled. In that case we would ignore the update until another
48+
// update is made. The simplest way for the customer to work around this is to add the
49+
// AnnotationOperatorVersion annotation with some value, which will then be overwritten by the web-hook
50+
// and the Coherence resource will be correctly processes.
51+
desiredResources = storage.GetLatest()
52+
log.Info("Ignoring hash difference for pre-3.4.2 resource", "hash", hash, "store", storeHash)
53+
}
54+
}
55+
} else {
56+
// storage state was saved with the current hash so is already in the desired state
57+
desiredResources = storage.GetLatest()
58+
}
59+
return desiredResources, err
60+
}

0 commit comments

Comments
 (0)