Skip to content

[release-4.13] OCPBUGS-47507: CRD upgrade existing CR validation fix (#3442) #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1911,15 +1911,15 @@ func validateExistingCRs(dynamicClient dynamic.Interface, gvr schema.GroupVersio
return dynamicClient.Resource(gvr).List(context.TODO(), opts)
}))
validationFn := func(obj runtime.Object) error {
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
// if it does, it's a programming error
cr := obj.(*unstructured.Unstructured)
validator, _, err := validation.NewSchemaValidator(newCRD.Spec.Validation)
if err != nil {
return fmt.Errorf("error creating validator for schema %#v: %s", newCRD.Spec.Validation, err)
}
err = validation.ValidateCustomResource(field.NewPath(""), obj, validator).ToAggregate()
err = validation.ValidateCustomResource(field.NewPath(""), cr.UnstructuredContent(), validator).ToAggregate()
if err != nil {
// lister will only provide unstructured objects as runtime.Object, so this should never fail to convert
// if it does, it's a programming error
cr := obj.(*unstructured.Unstructured)
var namespacedName string
if cr.GetNamespace() == "" {
namespacedName = cr.GetName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,18 @@ func TestValidateExistingCRs(t *testing.T) {
newCRD: unversionedCRDForV1beta1File("testdata/hivebug/crd.yaml"),
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]"),
},
{
name: "crd with incorrect comparison",
existingObjects: []runtime.Object{
unstructuredForFile("testdata/postgrestolerations/pgadmin.cr.yaml"),
},
gvr: schema.GroupVersionResource{
Group: "postgres-operator.crunchydata.com",
Version: "v1beta1",
Resource: "pgadmins",
},
newCRD: unversionedCRDForV1beta1File("testdata/postgrestolerations/crd.yaml"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading