Skip to content

Commit de43551

Browse files
Merge pull request #864 from openshift-cherrypick-robot/cherry-pick-863-to-release-4.15
[release-4.15] OCPBUGS-41819: [4.17] adds paginating lister for evaluating CRs' upgrade fitness versus new CRDs.
2 parents b7d4828 + 9f298d6 commit de43551

File tree

2 files changed

+28
-16
lines changed
  • staging/operator-lifecycle-manager/pkg/controller/operators/catalog
  • vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog

2 files changed

+28
-16
lines changed

staging/operator-lifecycle-manager/pkg/controller/operators/catalog/operator.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"k8s.io/client-go/metadata/metadatalister"
4646
"k8s.io/client-go/tools/cache"
4747
"k8s.io/client-go/tools/clientcmd"
48+
"k8s.io/client-go/tools/pager"
4849
"k8s.io/client-go/tools/record"
4950
"k8s.io/client-go/util/retry"
5051
"k8s.io/client-go/util/workqueue"
@@ -2215,15 +2216,15 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
22152216
return fmt.Errorf("error creating validator for schema version %s: %s", version, err)
22162217
}
22172218
gvr := schema.GroupVersionResource{Group: gr.Group, Version: version, Resource: gr.Resource}
2218-
crList, err := dynamicClient.Resource(gvr).List(context.TODO(), metav1.ListOptions{})
2219-
if err != nil {
2220-
return fmt.Errorf("error listing resources in GroupVersionResource %#v: %s", gvr, err)
2221-
}
2222-
2223-
// validate each CR against this version schema
2224-
for _, cr := range crList.Items {
2225-
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
2219+
pager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
2220+
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
2221+
}))
2222+
validationFn := func(obj runtime.Object) error {
2223+
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
22262224
if err != nil {
2225+
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
2226+
// if it does, it's a programming error
2227+
cr := obj.(*unstructured.Unstructured)
22272228
var namespacedName string
22282229
if cr.GetNamespace() == "" {
22292230
namespacedName = cr.GetName()
@@ -2232,6 +2233,11 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
22322233
}
22332234
return validationError{fmt.Errorf("error validating %s %q: updated validation is too restrictive: %v", cr.GroupVersionKind(), namespacedName, err)}
22342235
}
2236+
return nil
2237+
}
2238+
err = pager.EachListItem(context.Background(), metav1.ListOptions{}, validationFn)
2239+
if err != nil {
2240+
return err
22352241
}
22362242
}
22372243
return nil

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog/operator.go

Lines changed: 14 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)