Skip to content

Commit 38d8424

Browse files
Merge pull request #871 from openshift-cherrypick-robot/cherry-pick-869-to-release-4.13
[release-4.13] OCPBUGS-42146: adds paginating lister for evaluating CRs' upgrade fitness versus new CRDs.
2 parents 42d01eb + 660fb2b commit 38d8424

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"
@@ -1906,21 +1907,34 @@ func validateV1Beta1CRDCompatibility(dynamicClient dynamic.Interface, oldCRD *ap
19061907
}
19071908

19081909
func validateExistingCRs(dynamicClient dynamic.Interface, gvr schema.GroupVersionResource, newCRD *apiextensions.CustomResourceDefinition) error {
1909-
// make dynamic client
1910-
crList, err := dynamicClient.Resource(gvr).List(context.TODO(), metav1.ListOptions{})
1911-
if err != nil {
1912-
return fmt.Errorf("error listing resources in GroupVersionResource %#v: %s", gvr, err)
1913-
}
1914-
for _, cr := range crList.Items {
1910+
pager := pager.New(pager.SimplePageFunc(func(opts metav1.ListOptions) (runtime.Object, error) {
1911+
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
1912+
}))
1913+
validationFn := func(obj runtime.Object) error {
19151914
validator, _, err := validation.NewSchemaValidator(newCRD.Spec.Validation)
19161915
if err != nil {
19171916
return fmt.Errorf("error creating validator for schema %#v: %s", newCRD.Spec.Validation, err)
19181917
}
1919-
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
1918+
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
19201919
if err != nil {
1921-
return fmt.Errorf("error validating custom resource against new schema for %s %s/%s: %v", newCRD.Spec.Names.Kind, cr.GetNamespace(), cr.GetName(), err)
1920+
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
1921+
// if it does, it's a programming error
1922+
cr := obj.(*unstructured.Unstructured)
1923+
var namespacedName string
1924+
if cr.GetNamespace() == "" {
1925+
namespacedName = cr.GetName()
1926+
} else {
1927+
namespacedName = fmt.Sprintf("%s/%s", cr.GetNamespace(), cr.GetName())
1928+
}
1929+
return fmt.Errorf("error validating %s %q: updated validation is too restrictive: %v", cr.GroupVersionKind(), namespacedName, err)
19221930
}
1931+
return nil
19231932
}
1933+
err := pager.EachListItem(context.Background(), metav1.ListOptions{}, validationFn)
1934+
if err != nil {
1935+
return err
1936+
}
1937+
19241938
return nil
19251939
}
19261940

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
@@ -1402,7 +1402,7 @@ func TestValidateExistingCRs(t *testing.T) {
14021402
Resource: "machinepools",
14031403
},
14041404
newCRD: unversionedCRDForV1beta1File("testdata/hivebug/crd.yaml"),
1405-
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]"),
1405+
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]"),
14061406
},
14071407
}
14081408
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)