Skip to content

Commit 83cde26

Browse files
fix CEL validation error message format introduced by Kubernetes v1.35
Kubernetes v1.35 changed CEL validation error message format to include the actual validated value instead of just the type ("string" or "object"). This provides more helpful error messages for debugging validation failures. Changes: - Update test expectations to include actual values in error messages - Change from "Invalid value: \"string\"" to "Invalid value: \"actual-value\"" - Change from "Invalid value: \"object\"" to "Invalid value:" for object validations - Update 20+ test cases in TestImageSourceCELValidationRules and related tests Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d355e3e commit 83cde26

1 file changed

Lines changed: 156 additions & 156 deletions

File tree

api/v1/clustercatalog_types_test.go

Lines changed: 156 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -32,85 +32,85 @@ func TestImageSourceCELValidationRules(t *testing.T) {
3232
spec ImageSource
3333
wantErrs []string
3434
}{
35-
"valid digest based image ref, poll interval not allowed, poll interval specified": {
36-
spec: ImageSource{
37-
Ref: "docker.io/test-image@sha256:abcdef123456789abcdef123456789abc",
38-
PollIntervalMinutes: ptr.To(1),
39-
},
40-
wantErrs: []string{
41-
"openAPIV3Schema.properties.spec.properties.source.properties.image: Invalid value: \"object\": cannot specify pollIntervalMinutes while using digest-based image",
42-
},
35+
"valid digest based image ref, poll interval not allowed, poll interval specified": {
36+
spec: ImageSource{
37+
Ref: "docker.io/test-image@sha256:abcdef123456789abcdef123456789abc",
38+
PollIntervalMinutes: ptr.To(1),
4339
},
40+
wantErrs: []string{
41+
"openAPIV3Schema.properties.spec.properties.source.properties.image: Invalid value: cannot specify pollIntervalMinutes while using digest-based image",
42+
},
43+
},
4444
"valid digest based image ref, poll interval not allowed, poll interval not specified": {
4545
spec: ImageSource{
4646
Ref: "docker.io/test-image@sha256:abcdef123456789abcdef123456789abc",
4747
},
4848
wantErrs: []string{},
4949
},
50-
"invalid digest based image ref, invalid domain": {
51-
spec: ImageSource{
52-
Ref: "-quay+docker/foo/bar@sha256:abcdef123456789abcdef123456789abc",
53-
},
54-
wantErrs: []string{
55-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": must start with a valid domain. valid domains must be alphanumeric characters (lowercase and uppercase) separated by the \".\" character.",
56-
},
50+
"invalid digest based image ref, invalid domain": {
51+
spec: ImageSource{
52+
Ref: "-quay+docker/foo/bar@sha256:abcdef123456789abcdef123456789abc",
5753
},
58-
"invalid digest based image ref, invalid name": {
59-
spec: ImageSource{
60-
Ref: "docker.io/FOO/BAR@sha256:abcdef123456789abcdef123456789abc",
61-
},
62-
wantErrs: []string{
63-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
64-
},
54+
wantErrs: []string{
55+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"-quay+docker/foo/bar@sha256:abcdef123456789abcdef123456789abc\": must start with a valid domain. valid domains must be alphanumeric characters (lowercase and uppercase) separated by the \".\" character.",
6556
},
66-
"invalid digest based image ref, invalid digest algorithm": {
67-
spec: ImageSource{
68-
Ref: "docker.io/foo/bar@99-problems:abcdef123456789abcdef123456789abc",
69-
},
70-
wantErrs: []string{
71-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": digest algorithm is not valid. valid algorithms must start with an uppercase or lowercase alpha character followed by alphanumeric characters and may contain the \"-\", \"_\", \"+\", and \".\" characters.",
72-
},
57+
},
58+
"invalid digest based image ref, invalid name": {
59+
spec: ImageSource{
60+
Ref: "docker.io/FOO/BAR@sha256:abcdef123456789abcdef123456789abc",
7361
},
74-
"invalid digest based image ref, too short digest encoding": {
75-
spec: ImageSource{
76-
Ref: "docker.io/foo/bar@sha256:abcdef123456789",
77-
},
78-
wantErrs: []string{
79-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": digest is not valid. the encoded string must be at least 32 characters",
80-
},
62+
wantErrs: []string{
63+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io/FOO/BAR@sha256:abcdef123456789abcdef123456789abc\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
8164
},
82-
"invalid digest based image ref, invalid characters in digest encoding": {
83-
spec: ImageSource{
84-
Ref: "docker.io/foo/bar@sha256:XYZxy123456789abcdef123456789abc",
85-
},
86-
wantErrs: []string{
87-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": digest is not valid. the encoded string must only contain hex characters (A-F, a-f, 0-9)",
88-
},
65+
},
66+
"invalid digest based image ref, invalid digest algorithm": {
67+
spec: ImageSource{
68+
Ref: "docker.io/foo/bar@99-problems:abcdef123456789abcdef123456789abc",
8969
},
90-
"invalid image ref, no tag or digest": {
91-
spec: ImageSource{
92-
Ref: "docker.io/foo/bar",
93-
},
94-
wantErrs: []string{
95-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": must end with a digest or a tag",
96-
},
70+
wantErrs: []string{
71+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io/foo/bar@99-problems:abcdef123456789abcdef123456789abc\": digest algorithm is not valid. valid algorithms must start with an uppercase or lowercase alpha character followed by alphanumeric characters and may contain the \"-\", \"_\", \"+\", and \".\" characters.",
9772
},
98-
"invalid tag based image ref, tag too long": {
99-
spec: ImageSource{
100-
Ref: fmt.Sprintf("docker.io/foo/bar:%s", strings.Repeat("x", 128)),
101-
},
102-
wantErrs: []string{
103-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": tag is invalid. the tag must not be more than 127 characters",
104-
},
73+
},
74+
"invalid digest based image ref, too short digest encoding": {
75+
spec: ImageSource{
76+
Ref: "docker.io/foo/bar@sha256:abcdef123456789",
10577
},
106-
"invalid tag based image ref, tag contains invalid characters": {
107-
spec: ImageSource{
108-
Ref: "docker.io/foo/bar:-foo_bar-",
109-
},
110-
wantErrs: []string{
111-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": tag is invalid. valid tags must begin with a word character (alphanumeric + \"_\") followed by word characters or \".\", and \"-\" characters",
112-
},
78+
wantErrs: []string{
79+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io/foo/bar@sha256:abcdef123456789\": digest is not valid. the encoded string must be at least 32 characters",
80+
},
81+
},
82+
"invalid digest based image ref, invalid characters in digest encoding": {
83+
spec: ImageSource{
84+
Ref: "docker.io/foo/bar@sha256:XYZxy123456789abcdef123456789abc",
85+
},
86+
wantErrs: []string{
87+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io/foo/bar@sha256:XYZxy123456789abcdef123456789abc\": digest is not valid. the encoded string must only contain hex characters (A-F, a-f, 0-9)",
88+
},
89+
},
90+
"invalid image ref, no tag or digest": {
91+
spec: ImageSource{
92+
Ref: "docker.io/foo/bar",
93+
},
94+
wantErrs: []string{
95+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io/foo/bar\": must end with a digest or a tag",
96+
},
97+
},
98+
"invalid tag based image ref, tag too long": {
99+
spec: ImageSource{
100+
Ref: fmt.Sprintf("docker.io/foo/bar:%s", strings.Repeat("x", 128)),
101+
},
102+
wantErrs: []string{
103+
fmt.Sprintf("openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io/foo/bar:%s\": tag is invalid. the tag must not be more than 127 characters", strings.Repeat("x", 128)),
113104
},
105+
},
106+
"invalid tag based image ref, tag contains invalid characters": {
107+
spec: ImageSource{
108+
Ref: "docker.io/foo/bar:-foo_bar-",
109+
},
110+
wantErrs: []string{
111+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io/foo/bar:-foo_bar-\": tag is invalid. valid tags must begin with a word character (alphanumeric + \"_\") followed by word characters or \".\", and \"-\" characters",
112+
},
113+
},
114114
"valid tag based image ref": {
115115
spec: ImageSource{
116116
Ref: "docker.io/foo/bar:v1.0.0",
@@ -124,14 +124,14 @@ func TestImageSourceCELValidationRules(t *testing.T) {
124124
},
125125
wantErrs: []string{},
126126
},
127-
"invalid image ref, only domain with port": {
128-
spec: ImageSource{
129-
Ref: "docker.io:8080",
130-
},
131-
wantErrs: []string{
132-
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"string\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
133-
},
127+
"invalid image ref, only domain with port": {
128+
spec: ImageSource{
129+
Ref: "docker.io:8080",
130+
},
131+
wantErrs: []string{
132+
"openAPIV3Schema.properties.spec.properties.source.properties.image.ref: Invalid value: \"docker.io:8080\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
134133
},
134+
},
135135
"valid image ref, domain with port": {
136136
spec: ImageSource{
137137
Ref: "my-subdomain.docker.io:8080/foo/bar:latest",
@@ -174,71 +174,71 @@ func TestResolvedImageSourceCELValidation(t *testing.T) {
174174
},
175175
wantErrs: []string{},
176176
},
177-
"invalid digest based image ref, invalid domain": {
178-
spec: ImageSource{
179-
Ref: "-quay+docker/foo/bar@sha256:abcdef123456789abcdef123456789abc",
180-
},
181-
wantErrs: []string{
182-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": must start with a valid domain. valid domains must be alphanumeric characters (lowercase and uppercase) separated by the \".\" character.",
183-
},
177+
"invalid digest based image ref, invalid domain": {
178+
spec: ImageSource{
179+
Ref: "-quay+docker/foo/bar@sha256:abcdef123456789abcdef123456789abc",
184180
},
185-
"invalid digest based image ref, invalid name": {
186-
spec: ImageSource{
187-
Ref: "docker.io/FOO/BAR@sha256:abcdef123456789abcdef123456789abc",
188-
},
189-
wantErrs: []string{
190-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
191-
},
181+
wantErrs: []string{
182+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"-quay+docker/foo/bar@sha256:abcdef123456789abcdef123456789abc\": must start with a valid domain. valid domains must be alphanumeric characters (lowercase and uppercase) separated by the \".\" character.",
192183
},
193-
"invalid digest based image ref, invalid digest algorithm": {
194-
spec: ImageSource{
195-
Ref: "docker.io/foo/bar@99-problems:abcdef123456789abcdef123456789abc",
196-
},
197-
wantErrs: []string{
198-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": digest algorithm is not valid. valid algorithms must start with an uppercase or lowercase alpha character followed by alphanumeric characters and may contain the \"-\", \"_\", \"+\", and \".\" characters.",
199-
},
184+
},
185+
"invalid digest based image ref, invalid name": {
186+
spec: ImageSource{
187+
Ref: "docker.io/FOO/BAR@sha256:abcdef123456789abcdef123456789abc",
200188
},
201-
"invalid digest based image ref, too short digest encoding": {
202-
spec: ImageSource{
203-
Ref: "docker.io/foo/bar@sha256:abcdef123456789",
204-
},
205-
wantErrs: []string{
206-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": digest is not valid. the encoded string must be at least 32 characters",
207-
},
189+
wantErrs: []string{
190+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io/FOO/BAR@sha256:abcdef123456789abcdef123456789abc\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
208191
},
209-
"invalid digest based image ref, invalid characters in digest encoding": {
210-
spec: ImageSource{
211-
Ref: "docker.io/foo/bar@sha256:XYZxy123456789abcdef123456789abc",
212-
},
213-
wantErrs: []string{
214-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": digest is not valid. the encoded string must only contain hex characters (A-F, a-f, 0-9)",
215-
},
192+
},
193+
"invalid digest based image ref, invalid digest algorithm": {
194+
spec: ImageSource{
195+
Ref: "docker.io/foo/bar@99-problems:abcdef123456789abcdef123456789abc",
216196
},
217-
"invalid image ref, no digest": {
218-
spec: ImageSource{
219-
Ref: "docker.io/foo/bar",
220-
},
221-
wantErrs: []string{
222-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": must end with a digest",
223-
},
197+
wantErrs: []string{
198+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io/foo/bar@99-problems:abcdef123456789abcdef123456789abc\": digest algorithm is not valid. valid algorithms must start with an uppercase or lowercase alpha character followed by alphanumeric characters and may contain the \"-\", \"_\", \"+\", and \".\" characters.",
224199
},
225-
"invalid image ref, only domain with port": {
226-
spec: ImageSource{
227-
Ref: "docker.io:8080",
228-
},
229-
wantErrs: []string{
230-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
231-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": must end with a digest",
232-
},
200+
},
201+
"invalid digest based image ref, too short digest encoding": {
202+
spec: ImageSource{
203+
Ref: "docker.io/foo/bar@sha256:abcdef123456789",
233204
},
234-
"invalid image ref, tag-based ref": {
235-
spec: ImageSource{
236-
Ref: "docker.io/foo/bar:latest",
237-
},
238-
wantErrs: []string{
239-
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"string\": must end with a digest",
240-
},
205+
wantErrs: []string{
206+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io/foo/bar@sha256:abcdef123456789\": digest is not valid. the encoded string must be at least 32 characters",
207+
},
208+
},
209+
"invalid digest based image ref, invalid characters in digest encoding": {
210+
spec: ImageSource{
211+
Ref: "docker.io/foo/bar@sha256:XYZxy123456789abcdef123456789abc",
212+
},
213+
wantErrs: []string{
214+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io/foo/bar@sha256:XYZxy123456789abcdef123456789abc\": digest is not valid. the encoded string must only contain hex characters (A-F, a-f, 0-9)",
215+
},
216+
},
217+
"invalid image ref, no digest": {
218+
spec: ImageSource{
219+
Ref: "docker.io/foo/bar",
220+
},
221+
wantErrs: []string{
222+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io/foo/bar\": must end with a digest",
241223
},
224+
},
225+
"invalid image ref, only domain with port": {
226+
spec: ImageSource{
227+
Ref: "docker.io:8080",
228+
},
229+
wantErrs: []string{
230+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io:8080\": a valid name is required. valid names must contain lowercase alphanumeric characters separated only by the \".\", \"_\", \"__\", \"-\" characters.",
231+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io:8080\": must end with a digest",
232+
},
233+
},
234+
"invalid image ref, tag-based ref": {
235+
spec: ImageSource{
236+
Ref: "docker.io/foo/bar:latest",
237+
},
238+
wantErrs: []string{
239+
"openAPIV3Schema.properties.status.properties.resolvedSource.properties.image.properties.ref: Invalid value: \"docker.io/foo/bar:latest\": must end with a digest",
240+
},
241+
},
242242
} {
243243
t.Run(name, func(t *testing.T) {
244244
errs := validator(tc.spec.Ref, nil)
@@ -266,22 +266,22 @@ func TestClusterCatalogURLsCELValidation(t *testing.T) {
266266
},
267267
wantErrs: []string{},
268268
},
269-
"base is invalid, scheme is not one of http or https": {
270-
urls: ClusterCatalogURLs{
271-
Base: "file://somefilepath",
272-
},
273-
wantErrs: []string{
274-
fmt.Sprintf("%s: Invalid value: \"string\": scheme must be either http or https", pth),
275-
},
269+
"base is invalid, scheme is not one of http or https": {
270+
urls: ClusterCatalogURLs{
271+
Base: "file://somefilepath",
276272
},
277-
"base is invalid": {
278-
urls: ClusterCatalogURLs{
279-
Base: "notevenarealURL",
280-
},
281-
wantErrs: []string{
282-
fmt.Sprintf("%s: Invalid value: \"string\": must be a valid URL", pth),
283-
},
273+
wantErrs: []string{
274+
fmt.Sprintf("%s: Invalid value: \"file://somefilepath\": scheme must be either http or https", pth),
275+
},
276+
},
277+
"base is invalid": {
278+
urls: ClusterCatalogURLs{
279+
Base: "notevenarealURL",
284280
},
281+
wantErrs: []string{
282+
fmt.Sprintf("%s: Invalid value: \"notevenarealURL\": must be a valid URL", pth),
283+
},
284+
},
285285
} {
286286
t.Run(name, func(t *testing.T) {
287287
errs := validator(tc.urls.Base, nil)
@@ -304,14 +304,14 @@ func TestSourceCELValidation(t *testing.T) {
304304
source CatalogSource
305305
wantErrs []string
306306
}{
307-
"image source missing required image field": {
308-
source: CatalogSource{
309-
Type: SourceTypeImage,
310-
},
311-
wantErrs: []string{
312-
fmt.Sprintf("%s: Invalid value: \"object\": image is required when source type is %s, and forbidden otherwise", pth, SourceTypeImage),
313-
},
307+
"image source missing required image field": {
308+
source: CatalogSource{
309+
Type: SourceTypeImage,
310+
},
311+
wantErrs: []string{
312+
fmt.Sprintf("%s: Invalid value: image is required when source type is %s, and forbidden otherwise", pth, SourceTypeImage),
314313
},
314+
},
315315
"image source with required image field": {
316316
source: CatalogSource{
317317
Type: SourceTypeImage,
@@ -346,14 +346,14 @@ func TestResolvedSourceCELValidation(t *testing.T) {
346346
source ResolvedCatalogSource
347347
wantErrs []string
348348
}{
349-
"image source missing required image field": {
350-
source: ResolvedCatalogSource{
351-
Type: SourceTypeImage,
352-
},
353-
wantErrs: []string{
354-
fmt.Sprintf("%s: Invalid value: \"object\": image is required when source type is %s, and forbidden otherwise", pth, SourceTypeImage),
355-
},
349+
"image source missing required image field": {
350+
source: ResolvedCatalogSource{
351+
Type: SourceTypeImage,
352+
},
353+
wantErrs: []string{
354+
fmt.Sprintf("%s: Invalid value: image is required when source type is %s, and forbidden otherwise", pth, SourceTypeImage),
356355
},
356+
},
357357
"image source with required image field": {
358358
source: ResolvedCatalogSource{
359359
Type: SourceTypeImage,

0 commit comments

Comments
 (0)