Skip to content

Commit bfaf8cb

Browse files
committed
update validations to dns subdomain
Signed-off-by: everettraven <[email protected]>
1 parent 03305c9 commit bfaf8cb

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ type CatalogSource struct {
142142
// packageName is a reference to the name of the package to be installed
143143
// and is used to filter the content from catalogs.
144144
//
145-
// This field is required, immutable and follows the DNS label standard as
146-
// defined in [RFC 1123]. This means that valid values:
147-
// - Contain no more than 63 characters
148-
// - Contain only lowercase alphanumeric characters or '-'
145+
// This field is required, immutable and follows the DNS subdomain name
146+
// standard as defined in [RFC 1123]. This means that valid entries:
147+
// - Contain no more than 253 characters
148+
// - Contain only lowercase alphanumeric characters, '-', or '.'
149149
// - Start with an alphanumeric character
150150
// - End with an alphanumeric character
151151
//
@@ -163,8 +163,8 @@ type CatalogSource struct {
163163
//
164164
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
165165
//
166-
//+kubebuilder:validation:MaxLength:=63
167-
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
166+
//+kubebuilder:validation:MaxLength:=253
167+
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
168168
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="packageName is immutable"
169169
PackageName string `json:"packageName"`
170170

@@ -262,11 +262,10 @@ type CatalogSource struct {
262262
//
263263
// When unspecified, upgrade edges across all channels will be used to identify valid automatic upgrade paths.
264264
//
265-
// This field follows the DNS label name standard as defined in [RFC 1123]
266-
// with the addition of '.' and '_' characters being allowed.
267-
// This means that valid values:
268-
// - Contain no more than 63 characters
269-
// - Contain only lowercase alphanumeric characters, '-', '.', or '_'
265+
// This field follows the DNS subdomain name standard as defined in [RFC
266+
// 1123]. This means that valid entries:
267+
// - Contain no more than 253 characters
268+
// - Contain only lowercase alphanumeric characters, '-', or '.'
270269
// - Start with an alphanumeric character
271270
// - End with an alphanumeric character
272271
//
@@ -279,17 +278,18 @@ type CatalogSource struct {
279278
// - dev-preview
280279
// - preview
281280
// - community
282-
// - original_40
283281
//
284282
// Some examples of invalid values are:
285283
// - -some-channel
286284
// - some-channel-
287285
// - thisisareallylongchannelnamethatisgreaterthanthemaximumlength
286+
// - original_40
287+
// - --default-channel
288288
//
289289
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
290290
//
291-
//+kubebuilder:validation:MaxLength:=63
292-
//+kubebuilder:validation:Pattern:=^[a-z0-9]([\._\-a-z0-9]*[a-z0-9])?$
291+
//+kubebuilder:validation:MaxLength:=253
292+
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
293293
//+optional
294294
Channel string `json:"channel,omitempty"`
295295

@@ -335,8 +335,8 @@ type ServiceAccountReference struct {
335335
//
336336
// This ServiceAccount is expected to exist in the installNamespace.
337337
//
338-
// This field follows the DNS subdomain name standard as defined in RFC
339-
// 1123. This means that valid values:
338+
// This field follows the DNS subdomain name standard as defined in [RFC
339+
// 1123]. This means that valid values:
340340
// - Contain no more than 253 characters
341341
// - Contain only lowercase alphanumeric characters, '-', or '.'
342342
// - Start with an alphanumeric character
@@ -353,6 +353,8 @@ type ServiceAccountReference struct {
353353
// - -some-serviceaccount
354354
// - some-serviceaccount-
355355
//
356+
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
357+
//
356358
//+kubebuilder:validation:MaxLength:=253
357359
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
358360
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"

config/base/crd/bases/olm.operatorframework.io_clusterextensions.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ spec:
135135
136136
This ServiceAccount is expected to exist in the installNamespace.
137137
138-
This field follows the DNS subdomain name standard as defined in RFC
139-
1123. This means that valid values:
138+
This field follows the DNS subdomain name standard as defined in [RFC
139+
1123]. This means that valid values:
140140
- Contain no more than 253 characters
141141
- Contain only lowercase alphanumeric characters, '-', or '.'
142142
- Start with an alphanumeric character
@@ -152,6 +152,8 @@ spec:
152152
Some examples of invalid values are:
153153
- -some-serviceaccount
154154
- some-serviceaccount-
155+
156+
[RFC 1123]: https://tools.ietf.org/html/rfc1123
155157
maxLength: 253
156158
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
157159
type: string
@@ -198,11 +200,10 @@ spec:
198200
199201
When unspecified, upgrade edges across all channels will be used to identify valid automatic upgrade paths.
200202
201-
This field follows the DNS label name standard as defined in [RFC 1123]
202-
with the addition of '.' and '_' characters being allowed.
203-
This means that valid values:
204-
- Contain no more than 63 characters
205-
- Contain only lowercase alphanumeric characters, '-', '.', or '_'
203+
This field follows the DNS subdomain name standard as defined in [RFC
204+
1123]. This means that valid entries:
205+
- Contain no more than 253 characters
206+
- Contain only lowercase alphanumeric characters, '-', or '.'
206207
- Start with an alphanumeric character
207208
- End with an alphanumeric character
208209
@@ -215,26 +216,27 @@ spec:
215216
- dev-preview
216217
- preview
217218
- community
218-
- original_40
219219
220220
Some examples of invalid values are:
221221
- -some-channel
222222
- some-channel-
223223
- thisisareallylongchannelnamethatisgreaterthanthemaximumlength
224+
- original_40
225+
- --default-channel
224226
225227
[RFC 1123]: https://tools.ietf.org/html/rfc1123
226-
maxLength: 63
227-
pattern: ^[a-z0-9]([\._\-a-z0-9]*[a-z0-9])?$
228+
maxLength: 253
229+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
228230
type: string
229231
packageName:
230232
description: |-
231233
packageName is a reference to the name of the package to be installed
232234
and is used to filter the content from catalogs.
233235
234-
This field is required, immutable and follows the DNS label standard as
235-
defined in [RFC 1123]. This means that valid values:
236-
- Contain no more than 63 characters
237-
- Contain only lowercase alphanumeric characters or '-'
236+
This field is required, immutable and follows the DNS subdomain name
237+
standard as defined in [RFC 1123]. This means that valid entries:
238+
- Contain no more than 253 characters
239+
- Contain only lowercase alphanumeric characters, '-', or '.'
238240
- Start with an alphanumeric character
239241
- End with an alphanumeric character
240242
@@ -251,8 +253,8 @@ spec:
251253
- some.package
252254
253255
[RFC 1123]: https://tools.ietf.org/html/rfc1123
254-
maxLength: 63
255-
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
256+
maxLength: 253
257+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
256258
type: string
257259
x-kubernetes-validations:
258260
- message: packageName is immutable

internal/controllers/clusterextension_admission_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestClusterExtensionSourceConfig(t *testing.T) {
7272
}
7373

7474
func TestClusterExtensionAdmissionPackageName(t *testing.T) {
75-
tooLongError := "spec.source.catalog.packageName: Too long: may not be longer than 63"
75+
tooLongError := "spec.source.catalog.packageName: Too long: may not be longer than 253"
7676
regexMismatchError := "spec.source.catalog.packageName in body should match"
7777

7878
testCases := []struct {
@@ -81,7 +81,7 @@ func TestClusterExtensionAdmissionPackageName(t *testing.T) {
8181
errMsg string
8282
}{
8383
{"no package name", "", regexMismatchError},
84-
{"long package name", strings.Repeat("x", 64), tooLongError},
84+
{"long package name", strings.Repeat("x", 254), tooLongError},
8585
{"leading digits with hypens", "0my-1package-9name", ""},
8686
{"trailing digits with hypens", "my0-package1-name9", ""},
8787
{"digits with hypens", "012-345-678-9", ""},
@@ -94,6 +94,8 @@ func TestClusterExtensionAdmissionPackageName(t *testing.T) {
9494
{"single hypen", "-", regexMismatchError},
9595
{"uppercase letters", "ABC-DEF-GHI-JKL", regexMismatchError},
9696
{"special characters", "my-$pecial-package-name", regexMismatchError},
97+
{"dot separated", "some.package", ""},
98+
{"underscore separated", "some_package", regexMismatchError},
9799
}
98100

99101
t.Parallel()
@@ -223,7 +225,7 @@ func TestClusterExtensionAdmissionVersion(t *testing.T) {
223225
}
224226

225227
func TestClusterExtensionAdmissionChannel(t *testing.T) {
226-
tooLongError := "spec.source.catalog.channel: Too long: may not be longer than 63"
228+
tooLongError := "spec.source.catalog.channel: Too long: may not be longer than 253"
227229
regexMismatchError := "spec.source.catalog.channel in body should match"
228230

229231
testCases := []struct {
@@ -235,7 +237,7 @@ func TestClusterExtensionAdmissionChannel(t *testing.T) {
235237
{"hypen-separated", "hyphenated-name", ""},
236238
{"dot-separated", "dotted.name", ""},
237239
{"includes version", "channel-has-version-1.0.1", ""},
238-
{"long channel name", strings.Repeat("x", 64), tooLongError},
240+
{"long channel name", strings.Repeat("x", 254), tooLongError},
239241
{"spaces", "spaces spaces", regexMismatchError},
240242
{"capitalized", "Capitalized", regexMismatchError},
241243
{"camel case", "camelCase", regexMismatchError},
@@ -244,6 +246,7 @@ func TestClusterExtensionAdmissionChannel(t *testing.T) {
244246
{"ends with hyphen", "end-with-hyphen-", regexMismatchError},
245247
{"starts with period", ".start-with-period", regexMismatchError},
246248
{"ends with period", "end-with-period.", regexMismatchError},
249+
{"contains underscore", "some_thing", regexMismatchError},
247250
}
248251

249252
t.Parallel()

0 commit comments

Comments
 (0)