Skip to content

Commit

Permalink
adds paginating lister for evaluating CRs' upgrade fitness versus new…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
grokspawn authored Sep 5, 2024
1 parent a273449 commit 48a856a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"k8s.io/client-go/metadata/metadatalister"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/pager"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/retry"
"k8s.io/client-go/util/workqueue"
Expand Down Expand Up @@ -2230,15 +2231,15 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
return fmt.Errorf("error creating validator for schema version %s: %s", version, err)
}
gvr := schema.GroupVersionResource{Group: gr.Group, Version: version, Resource: gr.Resource}
crList, err := dynamicClient.Resource(gvr).List(context.TODO(), metav1.ListOptions{})
if err != nil {
return fmt.Errorf("error listing resources in GroupVersionResource %#v: %s", gvr, err)
}

// validate each CR against this version schema
for _, cr := range crList.Items {
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
pager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
}))
validationFn := func(obj runtime.Object) error {
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
if err != nil {
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
// if it does, it's a programming error
cr := obj.(*unstructured.Unstructured)
var namespacedName string
if cr.GetNamespace() == "" {
namespacedName = cr.GetName()
Expand All @@ -2247,6 +2248,11 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
}
return validationError{fmt.Errorf("error validating %s %q: updated validation is too restrictive: %v", cr.GroupVersionKind(), namespacedName, err)}
}
return nil
}
err = pager.EachListItem(context.Background(), metav1.ListOptions{}, validationFn)
if err != nil {
return err
}
}
return nil
Expand Down

0 comments on commit 48a856a

Please sign in to comment.