Skip to content

Commit d35ad80

Browse files
Merge pull request #924 from openshift-cherrypick-robot/cherry-pick-921-to-release-4.13
[release-4.13] OCPBUGS-47507: CRD upgrade existing CR validation fix (#3442)
2 parents 7f911e3 + 298a70c commit d35ad80

File tree

5 files changed

+1961
-8
lines changed

5 files changed

+1961
-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
@@ -1911,15 +1911,15 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gvr schema.GroupVersio
19111911
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
19121912
}))
19131913
validationFn := func(obj runtime.Object) error {
1914+
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
1915+
// if it does, it's a programming error
1916+
cr := obj.(*unstructured.Unstructured)
19141917
validator, _, err := validation.NewSchemaValidator(newCRD.Spec.Validation)
19151918
if err != nil {
19161919
return fmt.Errorf("error creating validator for schema %#v: %s", newCRD.Spec.Validation, err)
19171920
}
1918-
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
1921+
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
19191922
if err != nil {
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)
19231923
var namespacedName string
19241924
if cr.GetNamespace() == "" {
19251925
namespacedName = cr.GetName()

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,18 @@ func TestValidateExistingCRs(t *testing.T) {
14041404
newCRD: unversionedCRDForV1beta1File("testdata/hivebug/crd.yaml"),
14051405
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
},
1407+
{
1408+
name: "crd with incorrect comparison",
1409+
existingObjects: []runtime.Object{
1410+
unstructuredForFile("testdata/postgrestolerations/pgadmin.cr.yaml"),
1411+
},
1412+
gvr: schema.GroupVersionResource{
1413+
Group: "postgres-operator.crunchydata.com",
1414+
Version: "v1beta1",
1415+
Resource: "pgadmins",
1416+
},
1417+
newCRD: unversionedCRDForV1beta1File("testdata/postgrestolerations/crd.yaml"),
1418+
},
14071419
}
14081420
for _, tt := range tests {
14091421
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)