Skip to content

Commit a8acb3d

Browse files
Merge pull request #913 from openshift-cherrypick-robot/cherry-pick-912-to-release-4.17
[release-4.17] OCPBUGS-46054: CRD upgrade existing CR validation fix
2 parents 649dfc4 + 794452a commit a8acb3d

File tree

5 files changed

+1957
-8
lines changed

5 files changed

+1957
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,11 +2219,11 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
22192219
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
22202220
}))
22212221
validationFn := func(obj runtime.Object) error {
2222-
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
2222+
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
2223+
// if it does, it's a programming error
2224+
cr := obj.(*unstructured.Unstructured)
2225+
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
22232226
if err != nil {
2224-
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
2225-
// if it does, it's a programming error
2226-
cr := obj.(*unstructured.Unstructured)
22272227
var namespacedName string
22282228
if cr.GetNamespace() == "" {
22292229
namespacedName = cr.GetName()

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,14 @@ func TestValidateV1Beta1CRDCompatibility(t *testing.T) {
18351835
newCRD: unversionedCRDForV1beta1File("testdata/apiextensionsv1beta1/crd.no-versions-list.yaml"),
18361836
want: validationError{fmt.Errorf("error validating cluster.com/v1alpha1, Kind=testcrd \"my-cr-1\": updated validation is too restrictive: [].spec.scalar: Invalid value: 2: spec.scalar in body should be greater than or equal to 3")},
18371837
},
1838+
{
1839+
name: "crd with incorrect comparison",
1840+
existingObjects: []runtime.Object{
1841+
unstructuredForFile("testdata/postgrestolerations/pgadmin.cr.yaml"),
1842+
},
1843+
oldCRD: unversionedCRDForV1beta1File("testdata/postgrestolerations/crd.yaml"),
1844+
newCRD: unversionedCRDForV1beta1File("testdata/postgrestolerations/crd.yaml"),
1845+
},
18381846
}
18391847
for _, tt := range tests {
18401848
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)