Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 0 additions & 30 deletions pkg/services/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,9 @@ func ValidateManifestBundleUpdate(new, old datatypes.JSONMap) error {
if oldManifestBundleWrapper == nil {
return fmt.Errorf("old manifest bundle is empty")
}
if len(newManifestBundleWrapper.Manifests) != len(oldManifestBundleWrapper.Manifests) {
return fmt.Errorf("new and old manifest have different number of objects")
}
for i := range newManifestBundleWrapper.Manifests {
if err := ValidateObjectUpdate(newManifestBundleWrapper.Manifests[i], oldManifestBundleWrapper.Manifests[i]); err != nil {
return err
}
}

return nil
}

func ValidateObjectUpdate(new, old datatypes.JSONMap) error {
fldPath := field.NewPath("metadata")

newObj := unstructured.Unstructured{Object: new}
oldObj := unstructured.Unstructured{Object: old}

errs := field.ErrorList{}

errs = append(errs, apivalidation.ValidateImmutableField(newObj.GetAPIVersion(), oldObj.GetAPIVersion(), field.NewPath("apiVersion"))...)
errs = append(errs, apivalidation.ValidateImmutableField(newObj.GetKind(), oldObj.GetKind(), field.NewPath("kind"))...)
errs = append(errs, apivalidation.ValidateImmutableField(newObj.GetName(), oldObj.GetName(), fldPath.Child("name"))...)
errs = append(errs, apivalidation.ValidateImmutableField(newObj.GetNamespace(), oldObj.GetNamespace(), fldPath.Child("namespace"))...)
errs = append(errs, validateMetaData(newObj)...)

if len(errs) == 0 {
return nil
}

return fmt.Errorf("%s", errs.ToAggregate().Error())
}

// validatedAPIVersion tests whether the value passed is a valid apiVersion. A
// valid apiVersion contains a version string that matches DNS_LABEL format,
// with an optional group/ prefix, where the group string matches DNS_SUBDOMAIN
Expand Down
Loading
Loading