Skip to content

Commit d9a2dee

Browse files
committed
Fix subresource parsing for declarative validation
1 parent 336a32a commit d9a2dee

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

staging/src/k8s.io/apiserver/pkg/registry/rest/validate.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ func parseSubresourcePath(subresourcePath string) ([]string, error) {
102102
if len(subresourcePath) == 0 {
103103
return nil, nil
104104
}
105-
if subresourcePath[0] != '/' {
106-
return nil, fmt.Errorf("invalid subresource path: %s", subresourcePath)
105+
parts := strings.Split(subresourcePath, "/")
106+
for _, part := range parts {
107+
if len(part) == 0 {
108+
return nil, fmt.Errorf("invalid subresource path: %s", subresourcePath)
109+
}
107110
}
108-
parts := strings.Split(subresourcePath[1:], "/")
109111
return parts, nil
110112
}
111113

staging/src/k8s.io/apiserver/pkg/registry/rest/validate_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,22 @@ func TestValidateDeclaratively(t *testing.T) {
8585
expected: field.ErrorList{invalidRestartPolicyErr, mutatedRestartPolicyErr},
8686
},
8787
{
88-
name: "update subresource",
89-
subresource: "/status",
88+
name: "update subresource with declarative validation",
89+
subresource: "status",
9090
object: valid,
9191
oldObject: valid,
9292
expected: field.ErrorList{invalidStatusErr},
9393
},
94+
{
95+
name: "update subresource without declarative validation",
96+
subresource: "scale",
97+
object: valid,
98+
oldObject: valid,
99+
expected: field.ErrorList{}, // Expect no errors if there is no registered validation
100+
},
94101
{
95102
name: "invalid subresource",
96-
subresource: "invalid/status",
103+
subresource: "/invalid/status",
97104
object: valid,
98105
oldObject: valid,
99106
expected: field.ErrorList{invalidSubresourceErr},

0 commit comments

Comments
 (0)