mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-04 12:14:00 +00:00
@@ -362,6 +362,7 @@ spec:
|
||||
resourceModifier:
|
||||
description: ResourceModifier specifies the reference to JSON resource
|
||||
patches that should be applied to resources before restoration.
|
||||
nullable: true
|
||||
properties:
|
||||
apiGroup:
|
||||
description: APIGroup is the group for the resource being referenced.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -37,10 +37,12 @@ func (p *ResourceModifiers) Validate() error {
|
||||
}
|
||||
|
||||
func (p *JSONPatch) Validate() error {
|
||||
// TODO validate allowed operation
|
||||
if p.Operation == "" {
|
||||
return fmt.Errorf("operation cannot be empty")
|
||||
}
|
||||
if operation := strings.ToLower(p.Operation); operation != "add" && operation != "remove" && operation != "replace" && operation != "test" && operation != "move" && operation != "copy" {
|
||||
return fmt.Errorf("unsupported operation %s", p.Operation)
|
||||
}
|
||||
if p.Path == "" {
|
||||
return fmt.Errorf("path cannot be empty")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestResourceModifiers_Validate(t *testing.T) {
|
||||
ResourceModifierRules: []ResourceModifierRule{
|
||||
{
|
||||
Conditions: Conditions{
|
||||
GroupKind: "persistentvolumeclaims.storage.k8s.io",
|
||||
GroupKind: "persistentvolumeclaims",
|
||||
ResourceNameRegex: ".*",
|
||||
Namespaces: []string{"bar", "foo"},
|
||||
},
|
||||
@@ -44,7 +44,7 @@ func TestResourceModifiers_Validate(t *testing.T) {
|
||||
ResourceModifierRules: []ResourceModifierRule{
|
||||
{
|
||||
Conditions: Conditions{
|
||||
GroupKind: "persistentvolumeclaims.storage.k8s.io",
|
||||
GroupKind: "persistentvolumeclaims",
|
||||
ResourceNameRegex: ".*",
|
||||
Namespaces: []string{"bar", "foo"},
|
||||
},
|
||||
@@ -121,6 +121,15 @@ func TestJsonPatch_Validate(t *testing.T) {
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid operation throws error",
|
||||
fields: fields{
|
||||
Operation: "invalid",
|
||||
Path: "/spec/storageClassName",
|
||||
Value: "premium",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -151,7 +160,7 @@ func TestConditions_Validate(t *testing.T) {
|
||||
name: "non 0 length namespaces, non empty group kind, non empty resource name regex",
|
||||
fields: fields{
|
||||
Namespaces: []string{"bar", "foo"},
|
||||
GroupKind: "persistentvolumeclaims.storage.k8s.io",
|
||||
GroupKind: "persistentvolumeclaims",
|
||||
ResourceNameRegex: ".*",
|
||||
},
|
||||
wantErr: false,
|
||||
|
||||
Reference in New Issue
Block a user