Skip to content

Commit 8682cd3

Browse files
committed
fixup! Use Patch instead of Update for finalizer operations
Signed-off-by: Todd Short <[email protected]>
1 parent 53b8f70 commit 8682cd3

File tree

3 files changed

+25
-44
lines changed

3 files changed

+25
-44
lines changed

internal/catalogd/controllers/core/clustercatalog_controller.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ const (
4848
fbcDeletionFinalizer = "olm.operatorframework.io/delete-server-cache"
4949
// CatalogSources are polled if PollInterval is mentioned, in intervals of wait.Jitter(pollDuration, maxFactor)
5050
// wait.Jitter returns a time.Duration between pollDuration and pollDuration + maxFactor * pollDuration.
51-
requeueJitterMaxFactor = 0.01
52-
lastAppliedConfiguration = "kubectl.kubernetes.io/last-applied-configuration"
51+
requeueJitterMaxFactor = 0.01
5352
)
5453

5554
// ClusterCatalogReconciler reconciles a Catalog object
@@ -106,7 +105,7 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
106105

107106
// Do checks before any Update()s, as Update() may modify the resource structure!
108107
updateStatus := !equality.Semantic.DeepEqual(existingCatsrc.Status, reconciledCatsrc.Status)
109-
unexpectedFieldsChanged := checkForUnexpectedFieldChange(existingCatsrc, *reconciledCatsrc)
108+
unexpectedFieldsChanged := checkForUnexpectedFieldChange(&existingCatsrc, reconciledCatsrc)
110109

111110
if unexpectedFieldsChanged {
112111
panic("spec or metadata changed by reconciler")
@@ -407,20 +406,15 @@ func (r *ClusterCatalogReconciler) needsPoll(lastSuccessfulPoll time.Time, catal
407406
return nextPoll.Before(time.Now())
408407
}
409408

410-
// Compare resources - ignoring status & metadata.finalizers
411-
func checkForUnexpectedFieldChange(a, b ocv1.ClusterCatalog) bool {
412-
a.Status, b.Status = ocv1.ClusterCatalogStatus{}, ocv1.ClusterCatalogStatus{}
413-
a.Finalizers, b.Finalizers = []string{}, []string{}
414-
a.ManagedFields, b.ManagedFields = nil, nil
415-
a.ResourceVersion, b.ResourceVersion = "", ""
416-
// Remove kubectl's last-applied-configuration annotation which may be added by the API server
417-
if a.Annotations != nil {
418-
delete(a.Annotations, lastAppliedConfiguration)
409+
// Compare resources - Annotations/Labels/Spec
410+
func checkForUnexpectedFieldChange(a, b *ocv1.ClusterCatalog) bool {
411+
if !equality.Semantic.DeepEqual(a.ObjectMeta.Annotations, b.ObjectMeta.Annotations) {
412+
return true
419413
}
420-
if b.Annotations != nil {
421-
delete(b.Annotations, lastAppliedConfiguration)
414+
if !equality.Semantic.DeepEqual(a.ObjectMeta.Labels, b.ObjectMeta.Labels) {
415+
return true
422416
}
423-
return !equality.Semantic.DeepEqual(a, b)
417+
return !equality.Semantic.DeepEqual(a.Spec, b.Spec)
424418
}
425419

426420
func (r *ClusterCatalogReconciler) deleteStoredCatalog(catalogName string) {

internal/operator-controller/controllers/clusterextension_controller.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (r *ClusterExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Req
117117
updateStatus := !equality.Semantic.DeepEqual(existingExt.Status, reconciledExt.Status)
118118

119119
// If any unexpected fields have changed, panic before updating the resource
120-
unexpectedFieldsChanged := checkForUnexpectedClusterExtensionFieldChange(*existingExt, *reconciledExt)
120+
unexpectedFieldsChanged := checkForUnexpectedClusterExtensionFieldChange(existingExt, reconciledExt)
121121
if unexpectedFieldsChanged {
122122
panic("spec or metadata changed by reconciler")
123123
}
@@ -149,20 +149,15 @@ func ensureAllConditionsWithReason(ext *ocv1.ClusterExtension, reason v1alpha1.C
149149
}
150150
}
151151

152-
// Compare resources - ignoring status, metadata.finalizers, metadata.resourceVersion, and metadata.managedFields
153-
func checkForUnexpectedClusterExtensionFieldChange(a, b ocv1.ClusterExtension) bool {
154-
a.Status, b.Status = ocv1.ClusterExtensionStatus{}, ocv1.ClusterExtensionStatus{}
155-
a.Finalizers, b.Finalizers = []string{}, []string{}
156-
a.ResourceVersion, b.ResourceVersion = "", ""
157-
a.ManagedFields, b.ManagedFields = nil, nil
158-
// Remove kubectl's last-applied-configuration annotation which may be added by the API server
159-
if a.Annotations != nil {
160-
delete(a.Annotations, "kubectl.kubernetes.io/last-applied-configuration")
152+
// Compare resources - Annotations/Labels/Spec
153+
func checkForUnexpectedClusterExtensionFieldChange(a, b *ocv1.ClusterExtension) bool {
154+
if !equality.Semantic.DeepEqual(a.ObjectMeta.Annotations, b.ObjectMeta.Annotations) {
155+
return true
161156
}
162-
if b.Annotations != nil {
163-
delete(b.Annotations, "kubectl.kubernetes.io/last-applied-configuration")
157+
if !equality.Semantic.DeepEqual(a.ObjectMeta.Labels, b.ObjectMeta.Labels) {
158+
return true
164159
}
165-
return !equality.Semantic.DeepEqual(a, b)
160+
return !equality.Semantic.DeepEqual(a.Spec, b.Spec)
166161
}
167162

168163
// Helper function to do the actual reconcile

internal/operator-controller/controllers/clusterextensionrevision_controller.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c *ClusterExtensionRevisionReconciler) Reconcile(ctx context.Context, req
8282
// Do checks before any Update()s, as Update() may modify the resource structure!
8383
updateStatus := !equality.Semantic.DeepEqual(existingRev.Status, reconciledRev.Status)
8484

85-
unexpectedFieldsChanged := checkForUnexpectedClusterExtensionRevisionFieldChange(*existingRev, *reconciledRev)
85+
unexpectedFieldsChanged := checkForUnexpectedClusterExtensionRevisionFieldChange(existingRev, reconciledRev)
8686
if unexpectedFieldsChanged {
8787
panic("spec or metadata changed by reconciler")
8888
}
@@ -100,21 +100,13 @@ func (c *ClusterExtensionRevisionReconciler) Reconcile(ctx context.Context, req
100100
return res, reconcileErr
101101
}
102102

103-
// Compare resources - ignoring status & metadata.finalizers
104-
func checkForUnexpectedClusterExtensionRevisionFieldChange(a, b ocv1.ClusterExtensionRevision) bool {
105-
a.Status, b.Status = ocv1.ClusterExtensionRevisionStatus{}, ocv1.ClusterExtensionRevisionStatus{}
106-
107-
// when finalizers are updated during reconcile, we expect finalizers, managedFields, and resourceVersion
108-
// to be updated, so we ignore changes in these fields.
109-
a.Finalizers, b.Finalizers = []string{}, []string{}
110-
a.ManagedFields, b.ManagedFields = nil, nil
111-
a.ResourceVersion, b.ResourceVersion = "", ""
112-
// Remove kubectl's last-applied-configuration annotation which may be added by the API server
113-
if a.Annotations != nil {
114-
delete(a.Annotations, "kubectl.kubernetes.io/last-applied-configuration")
115-
}
116-
if b.Annotations != nil {
117-
delete(b.Annotations, "kubectl.kubernetes.io/last-applied-configuration")
103+
// Compare resources - Annotations/Labels/Spec
104+
func checkForUnexpectedClusterExtensionRevisionFieldChange(a, b *ocv1.ClusterExtensionRevision) bool {
105+
if !equality.Semantic.DeepEqual(a.ObjectMeta.Annotations, b.ObjectMeta.Annotations) {
106+
return true
107+
}
108+
if !equality.Semantic.DeepEqual(a.ObjectMeta.Labels, b.ObjectMeta.Labels) {
109+
return true
118110
}
119111
return !equality.Semantic.DeepEqual(a.Spec, b.Spec)
120112
}

0 commit comments

Comments
 (0)