Skip to content

Commit 074a452

Browse files
committed
Revert "Merge pull request openshift#572 from openshift-bot/synchronize-upstream"
This reverts commit 24cf078, reversing changes made to 93bf7ab.
1 parent 24cf078 commit 074a452

File tree

9 files changed

+26
-406
lines changed

9 files changed

+26
-406
lines changed

cmd/catalogd/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import (
5959
"github.com/operator-framework/operator-controller/internal/catalogd/storage"
6060
"github.com/operator-framework/operator-controller/internal/catalogd/webhook"
6161
sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers"
62-
cacheutil "github.com/operator-framework/operator-controller/internal/shared/util/cache"
6362
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs"
6463
httputil "github.com/operator-framework/operator-controller/internal/shared/util/http"
6564
imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image"
@@ -255,8 +254,6 @@ func run(ctx context.Context) error {
255254

256255
cacheOptions := crcache.Options{
257256
ByObject: map[client.Object]crcache.ByObject{},
258-
// Memory optimization: strip managed fields and large annotations from cached objects
259-
DefaultTransform: cacheutil.StripManagedFieldsAndAnnotations(),
260257
}
261258

262259
saKey, err := sautil.GetServiceAccount()

cmd/operator-controller/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import (
7878
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1"
7979
"github.com/operator-framework/operator-controller/internal/operator-controller/scheme"
8080
sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers"
81-
cacheutil "github.com/operator-framework/operator-controller/internal/shared/util/cache"
8281
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs"
8382
httputil "github.com/operator-framework/operator-controller/internal/shared/util/http"
8483
imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image"
@@ -258,8 +257,6 @@ func run() error {
258257
cfg.systemNamespace: {LabelSelector: k8slabels.Everything()},
259258
},
260259
DefaultLabelSelector: k8slabels.Nothing(),
261-
// Memory optimization: strip managed fields and large annotations from cached objects
262-
DefaultTransform: cacheutil.StripAnnotations(),
263260
}
264261

265262
if features.OperatorControllerFeatureGate.Enabled(features.BoxcutterRuntime) {

commitchecker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
expectedMergeBase: 4e349e62c5314574f6194d64b1ff4508f2e9331f
1+
expectedMergeBase: 34394ce0a7067e1f1622dc2c381a9a12439b10d2
22
upstreamBranch: main
33
upstreamOrg: operator-framework
44
upstreamRepo: operator-controller

internal/catalogd/controllers/core/clustercatalog_controller.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
ocv1 "github.com/operator-framework/operator-controller/api/v1"
4242
"github.com/operator-framework/operator-controller/internal/catalogd/storage"
4343
imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image"
44-
k8sutil "github.com/operator-framework/operator-controller/internal/shared/util/k8s"
4544
)
4645

4746
const (
@@ -108,16 +107,16 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
108107
// Do checks before any Update()s, as Update() may modify the resource structure!
109108
updateStatus := !equality.Semantic.DeepEqual(existingCatsrc.Status, reconciledCatsrc.Status)
110109
updateFinalizers := !equality.Semantic.DeepEqual(existingCatsrc.Finalizers, reconciledCatsrc.Finalizers)
111-
unexpectedFieldsChanged := k8sutil.CheckForUnexpectedFieldChange(&existingCatsrc, reconciledCatsrc)
110+
unexpectedFieldsChanged := checkForUnexpectedFieldChange(existingCatsrc, *reconciledCatsrc)
112111

113112
if unexpectedFieldsChanged {
114113
panic("spec or metadata changed by reconciler")
115114
}
116115

117116
// Save the finalizers off to the side. If we update the status, the reconciledCatsrc will be updated
118117
// to contain the new state of the ClusterCatalog, which contains the status update, but (critically)
119-
// does not contain the finalizers. After the status update, we will use the saved finalizers in the
120-
// CreateOrPatch()
118+
// does not contain the finalizers. After the status update, we need to re-add the finalizers to the
119+
// reconciledCatsrc before updating the object.
121120
finalizers := reconciledCatsrc.Finalizers
122121

123122
if updateStatus {
@@ -126,12 +125,10 @@ func (r *ClusterCatalogReconciler) Reconcile(ctx context.Context, req ctrl.Reque
126125
}
127126
}
128127

128+
reconciledCatsrc.Finalizers = finalizers
129+
129130
if updateFinalizers {
130-
// Use CreateOrPatch to update finalizers on the server
131-
if _, err := controllerutil.CreateOrPatch(ctx, r.Client, reconciledCatsrc, func() error {
132-
reconciledCatsrc.Finalizers = finalizers
133-
return nil
134-
}); err != nil {
131+
if err := r.Update(ctx, reconciledCatsrc); err != nil {
135132
reconcileErr = errors.Join(reconcileErr, fmt.Errorf("error updating finalizers: %v", err))
136133
}
137134
}
@@ -418,6 +415,13 @@ func (r *ClusterCatalogReconciler) needsPoll(lastSuccessfulPoll time.Time, catal
418415
return nextPoll.Before(time.Now())
419416
}
420417

418+
// Compare resources - ignoring status & metadata.finalizers
419+
func checkForUnexpectedFieldChange(a, b ocv1.ClusterCatalog) bool {
420+
a.Status, b.Status = ocv1.ClusterCatalogStatus{}, ocv1.ClusterCatalogStatus{}
421+
a.Finalizers, b.Finalizers = []string{}, []string{}
422+
return !equality.Semantic.DeepEqual(a, b)
423+
}
424+
421425
type finalizerFunc func(ctx context.Context, obj client.Object) (crfinalizer.Result, error)
422426

423427
func (f finalizerFunc) Finalize(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {

internal/operator-controller/applier/boxcutter.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
ocv1 "github.com/operator-framework/operator-controller/api/v1"
2929
"github.com/operator-framework/operator-controller/internal/operator-controller/labels"
30-
"github.com/operator-framework/operator-controller/internal/shared/util/cache"
3130
)
3231

3332
const (
@@ -67,9 +66,6 @@ func (r *SimpleRevisionGenerator) GenerateRevisionFromHelmRelease(
6766
maps.Copy(labels, objectLabels)
6867
obj.SetLabels(labels)
6968

70-
// Memory optimization: strip large annotations
71-
// Note: ApplyStripTransform never returns an error in practice
72-
_ = cache.ApplyStripAnnotationsTransform(&obj)
7369
sanitizedUnstructured(ctx, &obj)
7470

7571
objs = append(objs, ocv1.ClusterExtensionRevisionObject{
@@ -121,10 +117,6 @@ func (r *SimpleRevisionGenerator) GenerateRevision(
121117
unstr := unstructured.Unstructured{Object: unstrObj}
122118
unstr.SetGroupVersionKind(gvk)
123119

124-
// Memory optimization: strip large annotations
125-
if err := cache.ApplyStripAnnotationsTransform(&unstr); err != nil {
126-
return nil, err
127-
}
128120
sanitizedUnstructured(ctx, &unstr)
129121

130122
objs = append(objs, ocv1.ClusterExtensionRevisionObject{

internal/operator-controller/controllers/clusterextension_controller.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/builder"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737
crcontroller "sigs.k8s.io/controller-runtime/pkg/controller"
38-
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3938
"sigs.k8s.io/controller-runtime/pkg/event"
4039
crhandler "sigs.k8s.io/controller-runtime/pkg/handler"
4140
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -49,7 +48,6 @@ import (
4948
ocv1 "github.com/operator-framework/operator-controller/api/v1"
5049
"github.com/operator-framework/operator-controller/internal/operator-controller/conditionsets"
5150
"github.com/operator-framework/operator-controller/internal/operator-controller/labels"
52-
k8sutil "github.com/operator-framework/operator-controller/internal/shared/util/k8s"
5351
)
5452

5553
const (
@@ -137,28 +135,25 @@ func (r *ClusterExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Req
137135
updateFinalizers := !equality.Semantic.DeepEqual(existingExt.Finalizers, reconciledExt.Finalizers)
138136

139137
// If any unexpected fields have changed, panic before updating the resource
140-
unexpectedFieldsChanged := k8sutil.CheckForUnexpectedFieldChange(existingExt, reconciledExt)
138+
unexpectedFieldsChanged := checkForUnexpectedClusterExtensionFieldChange(*existingExt, *reconciledExt)
141139
if unexpectedFieldsChanged {
142140
panic("spec or metadata changed by reconciler")
143141
}
144142

145143
// Save the finalizers off to the side. If we update the status, the reconciledExt will be updated
146144
// to contain the new state of the ClusterExtension, which contains the status update, but (critically)
147-
// does not contain the finalizers. After the status update, we will use the saved finalizers in the
148-
// CreateOrPatch()
145+
// does not contain the finalizers. After the status update, we need to re-add the finalizers to the
146+
// reconciledExt before updating the object.
149147
finalizers := reconciledExt.Finalizers
150148
if updateStatus {
151149
if err := r.Client.Status().Update(ctx, reconciledExt); err != nil {
152150
reconcileErr = errors.Join(reconcileErr, fmt.Errorf("error updating status: %v", err))
153151
}
154152
}
153+
reconciledExt.Finalizers = finalizers
155154

156155
if updateFinalizers {
157-
// Use CreateOrPatch to update finalizers on the server
158-
if _, err := controllerutil.CreateOrPatch(ctx, r.Client, reconciledExt, func() error {
159-
reconciledExt.Finalizers = finalizers
160-
return nil
161-
}); err != nil {
156+
if err := r.Update(ctx, reconciledExt); err != nil {
162157
reconcileErr = errors.Join(reconcileErr, fmt.Errorf("error updating finalizers: %v", err))
163158
}
164159
}
@@ -184,6 +179,13 @@ func ensureAllConditionsWithReason(ext *ocv1.ClusterExtension, reason v1alpha1.C
184179
}
185180
}
186181

182+
// Compare resources - ignoring status & metadata.finalizers
183+
func checkForUnexpectedClusterExtensionFieldChange(a, b ocv1.ClusterExtension) bool {
184+
a.Status, b.Status = ocv1.ClusterExtensionStatus{}, ocv1.ClusterExtensionStatus{}
185+
a.Finalizers, b.Finalizers = []string{}, []string{}
186+
return !equality.Semantic.DeepEqual(a, b)
187+
}
188+
187189
// SetDeprecationStatus will set the appropriate deprecation statuses for a ClusterExtension
188190
// based on the provided bundle
189191
func SetDeprecationStatus(ext *ocv1.ClusterExtension, bundleName string, deprecation *declcfg.Deprecation) {

internal/shared/util/cache/transform.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

internal/shared/util/k8s/k8s.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)