Fix subresource parsing for declarative validation
Kubernetes-commit: d9a2dee622c0d2f2079194ff9700310041c10ed2
This commit is contained in:
parent
543428d1c4
commit
24d512c91f
|
|
@ -102,10 +102,12 @@ func parseSubresourcePath(subresourcePath string) ([]string, error) {
|
|||
if len(subresourcePath) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if subresourcePath[0] != '/' {
|
||||
return nil, fmt.Errorf("invalid subresource path: %s", subresourcePath)
|
||||
parts := strings.Split(subresourcePath, "/")
|
||||
for _, part := range parts {
|
||||
if len(part) == 0 {
|
||||
return nil, fmt.Errorf("invalid subresource path: %s", subresourcePath)
|
||||
}
|
||||
}
|
||||
parts := strings.Split(subresourcePath[1:], "/")
|
||||
return parts, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,15 +85,22 @@ func TestValidateDeclaratively(t *testing.T) {
|
|||
expected: field.ErrorList{invalidRestartPolicyErr, mutatedRestartPolicyErr},
|
||||
},
|
||||
{
|
||||
name: "update subresource",
|
||||
subresource: "/status",
|
||||
name: "update subresource with declarative validation",
|
||||
subresource: "status",
|
||||
object: valid,
|
||||
oldObject: valid,
|
||||
expected: field.ErrorList{invalidStatusErr},
|
||||
},
|
||||
{
|
||||
name: "update subresource without declarative validation",
|
||||
subresource: "scale",
|
||||
object: valid,
|
||||
oldObject: valid,
|
||||
expected: field.ErrorList{}, // Expect no errors if there is no registered validation
|
||||
},
|
||||
{
|
||||
name: "invalid subresource",
|
||||
subresource: "invalid/status",
|
||||
subresource: "/invalid/status",
|
||||
object: valid,
|
||||
oldObject: valid,
|
||||
expected: field.ErrorList{invalidSubresourceErr},
|
||||
|
|
|
|||
Loading…
Reference in New Issue