mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Fix subresource parsing for declarative validation
This commit is contained in:
parent
336a32a270
commit
d9a2dee622
@ -102,10 +102,12 @@ func parseSubresourcePath(subresourcePath string) ([]string, error) {
|
|||||||
if len(subresourcePath) == 0 {
|
if len(subresourcePath) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if subresourcePath[0] != '/' {
|
parts := strings.Split(subresourcePath, "/")
|
||||||
return nil, fmt.Errorf("invalid subresource path: %s", 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
|
return parts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,15 +85,22 @@ func TestValidateDeclaratively(t *testing.T) {
|
|||||||
expected: field.ErrorList{invalidRestartPolicyErr, mutatedRestartPolicyErr},
|
expected: field.ErrorList{invalidRestartPolicyErr, mutatedRestartPolicyErr},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "update subresource",
|
name: "update subresource with declarative validation",
|
||||||
subresource: "/status",
|
subresource: "status",
|
||||||
object: valid,
|
object: valid,
|
||||||
oldObject: valid,
|
oldObject: valid,
|
||||||
expected: field.ErrorList{invalidStatusErr},
|
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",
|
name: "invalid subresource",
|
||||||
subresource: "invalid/status",
|
subresource: "/invalid/status",
|
||||||
object: valid,
|
object: valid,
|
||||||
oldObject: valid,
|
oldObject: valid,
|
||||||
expected: field.ErrorList{invalidSubresourceErr},
|
expected: field.ErrorList{invalidSubresourceErr},
|
||||||
|
Loading…
Reference in New Issue
Block a user