Skip to content

Commit 80f23f1

Browse files
Merge pull request #869 from grokspawn/paginating-4.14
OCPBUGS-42017: adds paginating lister for evaluating CRs' upgrade fitness versus new CRDs.
2 parents cf12580 + 202ddc0 commit 80f23f1

File tree

3 files changed

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

3 files changed

+45
-17
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"k8s.io/client-go/informers"
3737
"k8s.io/client-go/tools/cache"
3838
"k8s.io/client-go/tools/clientcmd"
39+
"k8s.io/client-go/tools/pager"
3940
"k8s.io/client-go/tools/record"
4041
"k8s.io/client-go/util/retry"
4142
"k8s.io/client-go/util/workqueue"
@@ -1913,21 +1914,34 @@ func validateV1Beta1CRDCompatibility(dynamicClient dynamic.Interface, oldCRD *ap
19131914
}
19141915

19151916
func validateExistingCRs(dynamicClient dynamic.Interface, gvr schema.GroupVersionResource, newCRD *apiextensions.CustomResourceDefinition) error {
1916-
// make dynamic client
1917-
crList, err := dynamicClient.Resource(gvr).List(context.TODO(), metav1.ListOptions{})
1918-
if err != nil {
1919-
return fmt.Errorf("error listing resources in GroupVersionResource %#v: %s", gvr, err)
1920-
}
1921-
for _, cr := range crList.Items {
1917+
pager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
1918+
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
1919+
}))
1920+
validationFn := func(obj runtime.Object) error {
19221921
validator, _, err := validation.NewSchemaValidator(newCRD.Spec.Validation)
19231922
if err != nil {
19241923
return fmt.Errorf("error creating validator for schema %#v: %s", newCRD.Spec.Validation, err)
19251924
}
1926-
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
1925+
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
19271926
if err != nil {
1928-
return fmt.Errorf("error validating custom resource against new schema for %s %s/%s: %v", newCRD.Spec.Names.Kind, cr.GetNamespace(), cr.GetName(), err)
1927+
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
1928+
// if it does, it's a programming error
1929+
cr := obj.(*unstructured.Unstructured)
1930+
var namespacedName string
1931+
if cr.GetNamespace() == "" {
1932+
namespacedName = cr.GetName()
1933+
} else {
1934+
namespacedName = fmt.Sprintf("%s/%s", cr.GetNamespace(), cr.GetName())
1935+
}
1936+
return fmt.Errorf("error validating %s %q: updated validation is too restrictive: %v", cr.GroupVersionKind(), namespacedName, err)
19291937
}
1938+
return nil
19301939
}
1940+
err := pager.EachListItem(context.Background(), metav1.ListOptions{}, validationFn)
1941+
if err != nil {
1942+
return err
1943+
}
1944+
19311945
return nil
19321946
}
19331947

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ func TestValidateExistingCRs(t *testing.T) {
16141614
Resource: "machinepools",
16151615
},
16161616
newCRD: unversionedCRDForV1beta1File("testdata/hivebug/crd.yaml"),
1617-
want: fmt.Errorf("error validating custom resource against new schema for MachinePool /test: [[].spec.clusterDeploymentRef: Invalid value: \"null\": spec.clusterDeploymentRef in body must be of type object: \"null\", [].spec.name: Required value, [].spec.platform: Required value]"),
1617+
want: fmt.Errorf("error validating hive.openshift.io/v1, Kind=MachinePool \"test\": updated validation is too restrictive: [[].spec.clusterDeploymentRef: Invalid value: \"null\": spec.clusterDeploymentRef in body must be of type object: \"null\", [].spec.name: Required value, [].spec.platform: Required value]"),
16181618
},
16191619
}
16201620
for _, tt := range tests {

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

Lines changed: 22 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)