Skip to content

Commit f690dd8

Browse files
Merge pull request #917 from openshift-cherrypick-robot/cherry-pick-916-to-release-4.15
[release-4.15] OCPBUGS-46479: CRD upgrade existing CR validation fix
2 parents 2a0924f + e25f823 commit f690dd8

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
@@ -2220,11 +2220,11 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gr schema.GroupResourc
22202220
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
22212221
}))
22222222
validationFn := func(obj runtime.Object) error {
2223-
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
2223+
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
2224+
// if it does, it's a programming error
2225+
cr := obj.(*unstructured.Unstructured)
2226+
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
22242227
if err != nil {
2225-
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
2226-
// if it does, it's a programming error
2227-
cr := obj.(*unstructured.Unstructured)
22282228
var namespacedName string
22292229
if cr.GetNamespace() == "" {
22302230
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
@@ -1678,6 +1678,14 @@ func TestValidateV1Beta1CRDCompatibility(t *testing.T) {
16781678
newCRD: unversionedCRDForV1beta1File("testdata/apiextensionsv1beta1/crd.no-versions-list.yaml"),
16791679
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")},
16801680
},
1681+
{
1682+
name: "crd with incorrect comparison",
1683+
existingObjects: []runtime.Object{
1684+
unstructuredForFile("testdata/postgrestolerations/pgadmin.cr.yaml"),
1685+
},
1686+
oldCRD: unversionedCRDForV1beta1File("testdata/postgrestolerations/crd.yaml"),
1687+
newCRD: unversionedCRDForV1beta1File("testdata/postgrestolerations/crd.yaml"),
1688+
},
16811689
}
16821690
for _, tt := range tests {
16831691
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)