Skip to content

Commit 48a856a

Browse files
authored
adds paginating lister for evaluating CRs' upgrade fitness versus new CRDs. (#3387)
* paging lister for CRDs Signed-off-by: Jordan Keister <[email protected]> * review resolutions Signed-off-by: Jordan Keister <[email protected]> --------- Signed-off-by: Jordan Keister <[email protected]>
1 parent a273449 commit 48a856a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Diff for: pkg/controller/operators/catalog/operator.go

+14-8
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"
@@ -2230,15 +2231,15 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
22302231
return fmt.Errorf("error creating validator for schema version %s: %s", version, err)
22312232
}
22322233
gvr := schema.GroupVersionResource{Group: gr.Group, Version: version, Resource: gr.Resource}
2233-
crList, err := dynamicClient.Resource(gvr).List(context.TODO(), metav1.ListOptions{})
2234-
if err != nil {
2235-
return fmt.Errorf("error listing resources in GroupVersionResource %#v: %s", gvr, err)
2236-
}
2237-
2238-
// validate each CR against this version schema
2239-
for _, cr := range crList.Items {
2240-
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
2234+
pager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
2235+
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
2236+
}))
2237+
validationFn := func(obj runtime.Object) error {
2238+
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
22412239
if err != nil {
2240+
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
2241+
// if it does, it's a programming error
2242+
cr := obj.(*unstructured.Unstructured)
22422243
var namespacedName string
22432244
if cr.GetNamespace() == "" {
22442245
namespacedName = cr.GetName()
@@ -2247,6 +2248,11 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
22472248
}
22482249
return validationError{fmt.Errorf("error validating %s %q: updated validation is too restrictive: %v", cr.GroupVersionKind(), namespacedName, err)}
22492250
}
2251+
return nil
2252+
}
2253+
err = pager.EachListItem(context.Background(), metav1.ListOptions{}, validationFn)
2254+
if err != nil {
2255+
return err
22502256
}
22512257
}
22522258
return nil

0 commit comments

Comments
 (0)