minor fixes

Signed-off-by: Anshul Ahuja <anshulahuja@microsoft.com>
This commit is contained in:
Anshul Ahuja
2023-07-11 10:00:08 +05:30
parent 700a34901a
commit f5b6cf5b93
4 changed files with 17 additions and 5 deletions

View File

@@ -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

View File

@@ -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")
}

View File

@@ -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,