mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #130788 from jpbetz/fix-subresources
Fix subresource parsing for declarative validation
This commit is contained in:
commit
dabb4e2445
@ -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
Block a user