Skip to content

Commit 03305c9

Browse files
committed
update name validation patterns to match Kubernetes as close as possible
Signed-off-by: everettraven <[email protected]>
1 parent 5800c7f commit 03305c9

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type ClusterExtensionSpec struct {
6767
// applied to other Namespaces. This Namespace is expected to exist.
6868
//
6969
// installNamespace is required, immutable, and follows the DNS label standard
70-
// as defined in RFC 1123. This means that valid values:
70+
// as defined in [RFC 1123]. This means that valid values:
7171
// - Contain no more than 63 characters
7272
// - Contain only lowercase alphanumeric characters or '-'
7373
// - Start with an alphanumeric character
@@ -85,6 +85,8 @@ type ClusterExtensionSpec struct {
8585
// - thisisareallylongnamespacenamethatisgreaterthanthemaximumlength
8686
// - some.namespace
8787
//
88+
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
89+
//
8890
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
8991
//+kubebuilder:validation:MaxLength:=63
9092
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="installNamespace is immutable"
@@ -140,10 +142,9 @@ type CatalogSource struct {
140142
// packageName is a reference to the name of the package to be installed
141143
// and is used to filter the content from catalogs.
142144
//
143-
// This field is required, immutable and follows the DNS label standard as defined in RFC
144-
// 1123, with a deviation in the maximum length being no more than 48
145-
// characters. This means that valid values:
146-
// - Contain no more than 48 characters
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
147148
// - Contain only lowercase alphanumeric characters or '-'
148149
// - Start with an alphanumeric character
149150
// - End with an alphanumeric character
@@ -160,8 +161,10 @@ type CatalogSource struct {
160161
// - thisisareallylongpackagenamethatisgreaterthanthemaximumlength
161162
// - some.package
162163
//
163-
//+kubebuilder:validation:MaxLength:=48
164-
//+kubebuilder:validation:Pattern:=^[a-z0-9]+(-[a-z0-9]+)*$
164+
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
165+
//
166+
//+kubebuilder:validation:MaxLength:=63
167+
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
165168
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="packageName is immutable"
166169
PackageName string `json:"packageName"`
167170

@@ -259,11 +262,11 @@ type CatalogSource struct {
259262
//
260263
// When unspecified, upgrade edges across all channels will be used to identify valid automatic upgrade paths.
261264
//
262-
// This field follows the DNS subdomain name standard as defined in RFC
263-
// 1123, with a deviation in the maximum length being no more than 48
264-
// characters. This means that valid values:
265-
// - Contain no more than 48 characters
266-
// - Contain only lowercase alphanumeric characters, '-', or '.'
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 '_'
267270
// - Start with an alphanumeric character
268271
// - End with an alphanumeric character
269272
//
@@ -276,14 +279,17 @@ type CatalogSource struct {
276279
// - dev-preview
277280
// - preview
278281
// - community
282+
// - original_40
279283
//
280284
// Some examples of invalid values are:
281285
// - -some-channel
282286
// - some-channel-
283287
// - thisisareallylongchannelnamethatisgreaterthanthemaximumlength
284288
//
285-
//+kubebuilder:validation:MaxLength:=48
286-
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
289+
// [RFC 1123]: https://tools.ietf.org/html/rfc1123
290+
//
291+
//+kubebuilder:validation:MaxLength:=63
292+
//+kubebuilder:validation:Pattern:=^[a-z0-9]([\._\-a-z0-9]*[a-z0-9])?$
287293
//+optional
288294
Channel string `json:"channel,omitempty"`
289295

@@ -348,7 +354,7 @@ type ServiceAccountReference struct {
348354
// - some-serviceaccount-
349355
//
350356
//+kubebuilder:validation:MaxLength:=253
351-
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([.|-][a-z0-9]+)*$
357+
//+kubebuilder:validation:Pattern:=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
352358
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="name is immutable"
353359
Name string `json:"name"`
354360
}

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ spec:
4747
applied to other Namespaces. This Namespace is expected to exist.
4848
4949
installNamespace is required, immutable, and follows the DNS label standard
50-
as defined in RFC 1123. This means that valid values:
50+
as defined in [RFC 1123]. This means that valid values:
5151
- Contain no more than 63 characters
5252
- Contain only lowercase alphanumeric characters or '-'
5353
- Start with an alphanumeric character
@@ -64,6 +64,8 @@ spec:
6464
- some-namespace-
6565
- thisisareallylongnamespacenamethatisgreaterthanthemaximumlength
6666
- some.namespace
67+
68+
[RFC 1123]: https://tools.ietf.org/html/rfc1123
6769
maxLength: 63
6870
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
6971
type: string
@@ -151,7 +153,7 @@ spec:
151153
- -some-serviceaccount
152154
- some-serviceaccount-
153155
maxLength: 253
154-
pattern: ^[a-z0-9]+([.|-][a-z0-9]+)*$
156+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
155157
type: string
156158
x-kubernetes-validations:
157159
- message: name is immutable
@@ -196,11 +198,11 @@ spec:
196198
197199
When unspecified, upgrade edges across all channels will be used to identify valid automatic upgrade paths.
198200
199-
This field follows the DNS subdomain name standard as defined in RFC
200-
1123, with a deviation in the maximum length being no more than 48
201-
characters. This means that valid values:
202-
- Contain no more than 48 characters
203-
- Contain only lowercase alphanumeric characters, '-', or '.'
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 '_'
204206
- Start with an alphanumeric character
205207
- End with an alphanumeric character
206208
@@ -213,23 +215,25 @@ spec:
213215
- dev-preview
214216
- preview
215217
- community
218+
- original_40
216219
217220
Some examples of invalid values are:
218221
- -some-channel
219222
- some-channel-
220223
- thisisareallylongchannelnamethatisgreaterthanthemaximumlength
221-
maxLength: 48
222-
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
224+
225+
[RFC 1123]: https://tools.ietf.org/html/rfc1123
226+
maxLength: 63
227+
pattern: ^[a-z0-9]([\._\-a-z0-9]*[a-z0-9])?$
223228
type: string
224229
packageName:
225230
description: |-
226231
packageName is a reference to the name of the package to be installed
227232
and is used to filter the content from catalogs.
228233
229-
This field is required, immutable and follows the DNS label standard as defined in RFC
230-
1123, with a deviation in the maximum length being no more than 48
231-
characters. This means that valid values:
232-
- Contain no more than 48 characters
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
233237
- Contain only lowercase alphanumeric characters or '-'
234238
- Start with an alphanumeric character
235239
- End with an alphanumeric character
@@ -245,8 +249,10 @@ spec:
245249
- some-package-
246250
- thisisareallylongpackagenamethatisgreaterthanthemaximumlength
247251
- some.package
248-
maxLength: 48
249-
pattern: ^[a-z0-9]+(-[a-z0-9]+)*$
252+
253+
[RFC 1123]: https://tools.ietf.org/html/rfc1123
254+
maxLength: 63
255+
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
250256
type: string
251257
x-kubernetes-validations:
252258
- message: packageName is immutable

internal/controllers/clusterextension_admission_test.go

Lines changed: 5 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 48"
75+
tooLongError := "spec.source.catalog.packageName: Too long: may not be longer than 63"
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", "this-is-a-really-long-package-name-that-is-greater-than-48-characters", tooLongError},
84+
{"long package name", strings.Repeat("x", 64), 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", ""},
@@ -123,6 +123,7 @@ func TestClusterExtensionAdmissionPackageName(t *testing.T) {
123123
})
124124
}
125125
}
126+
126127
func TestClusterExtensionAdmissionVersion(t *testing.T) {
127128
tooLongError := "spec.source.catalog.version: Too long: may not be longer than 64"
128129
regexMismatchError := "spec.source.catalog.version in body should match"
@@ -222,7 +223,7 @@ func TestClusterExtensionAdmissionVersion(t *testing.T) {
222223
}
223224

224225
func TestClusterExtensionAdmissionChannel(t *testing.T) {
225-
tooLongError := "spec.source.catalog.channel: Too long: may not be longer than 48"
226+
tooLongError := "spec.source.catalog.channel: Too long: may not be longer than 63"
226227
regexMismatchError := "spec.source.catalog.channel in body should match"
227228

228229
testCases := []struct {
@@ -234,7 +235,7 @@ func TestClusterExtensionAdmissionChannel(t *testing.T) {
234235
{"hypen-separated", "hyphenated-name", ""},
235236
{"dot-separated", "dotted.name", ""},
236237
{"includes version", "channel-has-version-1.0.1", ""},
237-
{"long channel name", "longname01234567890123456789012345678901234567890", tooLongError},
238+
{"long channel name", strings.Repeat("x", 64), tooLongError},
238239
{"spaces", "spaces spaces", regexMismatchError},
239240
{"capitalized", "Capitalized", regexMismatchError},
240241
{"camel case", "camelCase", regexMismatchError},

0 commit comments

Comments
 (0)