Skip to content

Commit 2fdbb16

Browse files
Merge pull request #370 from csrwng/fix_exclude_clusteroperators
Bug 1838872: Avoid pre-creating clusteroperators that should be excluded
2 parents e318b86 + a9ddd84 commit 2fdbb16

File tree

8 files changed

+31
-13
lines changed

8 files changed

+31
-13
lines changed

hack/cluster-version-util/task_graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func newTaskGraphCmd() *cobra.Command {
3030

3131
func runTaskGraphCmd(cmd *cobra.Command, args []string) error {
3232
manifestDir := args[0]
33-
release, err := payload.LoadUpdate(manifestDir, "")
33+
release, err := payload.LoadUpdate(manifestDir, "", "")
3434
if err != nil {
3535
return err
3636
}

pkg/cvo/cvo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (vcb *verifyClientBuilder) HTTPClient() (*http.Client, error) {
236236
// controller that loads and applies content to the cluster. It returns an error if the payload appears to
237237
// be in error rather than continuing.
238238
func (optr *Operator) InitializeFromPayload(restConfig *rest.Config, burstRestConfig *rest.Config) error {
239-
update, err := payload.LoadUpdate(optr.defaultPayloadDir(), optr.releaseImage)
239+
update, err := payload.LoadUpdate(optr.defaultPayloadDir(), optr.releaseImage, optr.exclude)
240240
if err != nil {
241241
return fmt.Errorf("the local release contents are invalid - no current version can be determined from disk: %v", err)
242242
}

pkg/cvo/cvo_scenarios_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func setupCVOTest(payloadDir string) (*Operator, map[string]runtime.Object, *fak
7676
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "cvo-loop-test"),
7777
client: client,
7878
cvLister: &clientCVLister{client: client},
79+
exclude: "exclude-test",
7980
}
8081

8182
dynamicScheme := runtime.NewScheme()
@@ -90,7 +91,7 @@ func setupCVOTest(payloadDir string) (*Operator, map[string]runtime.Object, *fak
9091
wait.Backoff{
9192
Steps: 1,
9293
},
93-
"",
94+
"exclude-test",
9495
)
9596
o.configSync = worker
9697

pkg/cvo/sync_worker.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func (w *SyncWorker) syncOnce(ctx context.Context, work *SyncWork, maxWorkers in
495495
return err
496496
}
497497

498-
payloadUpdate, err := payload.LoadUpdate(info.Directory, update.Image)
498+
payloadUpdate, err := payload.LoadUpdate(info.Directory, update.Image, w.exclude)
499499
if err != nil {
500500
reporter.Report(SyncWorkerStatus{
501501
Generation: work.Generation,
@@ -653,7 +653,7 @@ func (w *SyncWorker) apply(ctx context.Context, payloadUpdate *payload.Update, w
653653
klog.V(4).Infof("Running sync for %s", task)
654654
klog.V(5).Infof("Manifest: %s", string(task.Manifest.Raw))
655655

656-
ov, ok := getOverrideForManifest(work.Overrides, w.exclude, task.Manifest)
656+
ov, ok := getOverrideForManifest(work.Overrides, task.Manifest)
657657
if ok && ov.Unmanaged {
658658
klog.V(4).Infof("Skipping %s as unmanaged", task)
659659
continue
@@ -945,7 +945,7 @@ func newMultipleError(errs []error) error {
945945
}
946946

947947
// getOverrideForManifest returns the override and true when override exists for manifest.
948-
func getOverrideForManifest(overrides []configv1.ComponentOverride, excludeIdentifier string, manifest *lib.Manifest) (configv1.ComponentOverride, bool) {
948+
func getOverrideForManifest(overrides []configv1.ComponentOverride, manifest *lib.Manifest) (configv1.ComponentOverride, bool) {
949949
for idx, ov := range overrides {
950950
kind, namespace, name := manifest.GVK.Kind, manifest.Object().GetNamespace(), manifest.Object().GetName()
951951
if ov.Kind == kind &&
@@ -954,10 +954,6 @@ func getOverrideForManifest(overrides []configv1.ComponentOverride, excludeIdent
954954
return overrides[idx], true
955955
}
956956
}
957-
excludeAnnotation := fmt.Sprintf("exclude.release.openshift.io/%s", excludeIdentifier)
958-
if annotations := manifest.Object().GetAnnotations(); annotations != nil && annotations[excludeAnnotation] == "true" {
959-
return configv1.ComponentOverride{Unmanaged: true}, true
960-
}
961957
return configv1.ComponentOverride{}, false
962958
}
963959

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Test
2+
apiVersion: v1
3+
metadata:
4+
name: file-20-yml
5+
annotations:
6+
exclude.release.openshift.io/exclude-test: "true"

pkg/payload/payload.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type Update struct {
107107
Manifests []lib.Manifest
108108
}
109109

110-
func LoadUpdate(dir, releaseImage string) (*Update, error) {
110+
func LoadUpdate(dir, releaseImage, excludeIdentifier string) (*Update, error) {
111111
payload, tasks, err := loadUpdatePayloadMetadata(dir, releaseImage)
112112
if err != nil {
113113
return nil, err
@@ -154,6 +154,15 @@ func LoadUpdate(dir, releaseImage string) (*Update, error) {
154154
errs = append(errs, errors.Wrapf(err, "error parsing %s", file.Name()))
155155
continue
156156
}
157+
// Filter out manifests that should be excluded based on annotation
158+
filteredMs := []lib.Manifest{}
159+
for _, manifest := range ms {
160+
if shouldExclude(excludeIdentifier, &manifest) {
161+
continue
162+
}
163+
filteredMs = append(filteredMs, manifest)
164+
}
165+
ms = filteredMs
157166
for i := range ms {
158167
ms[i].OriginalFilename = filepath.Base(file.Name())
159168
}
@@ -179,6 +188,12 @@ func LoadUpdate(dir, releaseImage string) (*Update, error) {
179188
return payload, nil
180189
}
181190

191+
func shouldExclude(excludeIdentifier string, manifest *lib.Manifest) bool {
192+
excludeAnnotation := fmt.Sprintf("exclude.release.openshift.io/%s", excludeIdentifier)
193+
annotations := manifest.Object().GetAnnotations()
194+
return annotations != nil && annotations[excludeAnnotation] == "true"
195+
}
196+
182197
// ValidateDirectory checks if a directory can be a candidate update by
183198
// looking for known files. It returns an error if the directory cannot
184199
// be an update.

pkg/payload/payload_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func Test_loadUpdatePayload(t *testing.T) {
104104
}
105105
for _, tt := range tests {
106106
t.Run(tt.name, func(t *testing.T) {
107-
got, err := LoadUpdate(tt.args.dir, tt.args.releaseImage)
107+
got, err := LoadUpdate(tt.args.dir, tt.args.releaseImage, "exclude-test")
108108
if (err != nil) != tt.wantErr {
109109
t.Errorf("loadUpdatePayload() error = %v, wantErr %v", err, tt.wantErr)
110110
return

pkg/payload/task_graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func Test_TaskGraph_real(t *testing.T) {
487487
if len(path) == 0 {
488488
t.Skip("TEST_GRAPH_PATH unset")
489489
}
490-
p, err := LoadUpdate(path, "arbitrary/image:1")
490+
p, err := LoadUpdate(path, "arbitrary/image:1", "")
491491
if err != nil {
492492
t.Fatal(err)
493493
}

0 commit comments

Comments
 (0)