@@ -45,9 +45,6 @@ func TestClusterExtensionSourceConfig(t *testing.T) {
4545 },
4646 },
4747 Namespace : "default" ,
48- ServiceAccount : ocv1.ServiceAccountReference {
49- Name : "default" ,
50- },
5148 }))
5249 }
5350 if tc .unionField == "" {
@@ -56,9 +53,6 @@ func TestClusterExtensionSourceConfig(t *testing.T) {
5653 SourceType : tc .sourceType ,
5754 },
5855 Namespace : "default" ,
59- ServiceAccount : ocv1.ServiceAccountReference {
60- Name : "default" ,
61- },
6256 }))
6357 }
6458
@@ -123,9 +117,6 @@ func TestClusterExtensionAdmissionPackageName(t *testing.T) {
123117 },
124118 },
125119 Namespace : "default" ,
126- ServiceAccount : ocv1.ServiceAccountReference {
127- Name : "default" ,
128- },
129120 }))
130121 if tc .errMsg == "" {
131122 require .NoError (t , err , "unexpected error for package name %q: %w" , tc .pkgName , err )
@@ -221,9 +212,6 @@ func TestClusterExtensionAdmissionVersion(t *testing.T) {
221212 },
222213 },
223214 Namespace : "default" ,
224- ServiceAccount : ocv1.ServiceAccountReference {
225- Name : "default" ,
226- },
227215 }))
228216 if tc .errMsg == "" {
229217 require .NoError (t , err , "unexpected error for version %q: %w" , tc .version , err )
@@ -245,7 +233,7 @@ func TestClusterExtensionAdmissionChannel(t *testing.T) {
245233 errMsg string
246234 }{
247235 {"no channel name" , []string {"" }, regexMismatchError },
248- {"hypen -separated" , []string {"hyphenated-name" }, "" },
236+ {"hyphen -separated" , []string {"hyphenated-name" }, "" },
249237 {"dot-separated" , []string {"dotted.name" }, "" },
250238 {"includes version" , []string {"channel-has-version-1.0.1" }, "" },
251239 {"long channel name" , []string {strings .Repeat ("x" , 254 )}, tooLongError },
@@ -276,9 +264,6 @@ func TestClusterExtensionAdmissionChannel(t *testing.T) {
276264 },
277265 },
278266 Namespace : "default" ,
279- ServiceAccount : ocv1.ServiceAccountReference {
280- Name : "default" ,
281- },
282267 }))
283268 if tc .errMsg == "" {
284269 require .NoError (t , err , "unexpected error for channel %q: %w" , tc .channels , err )
@@ -300,7 +285,7 @@ func TestClusterExtensionAdmissionInstallNamespace(t *testing.T) {
300285 errMsg string
301286 }{
302287 {"just alphanumeric" , "justalphanumberic1" , "" },
303- {"hypen -separated" , "hyphenated-name" , "" },
288+ {"hyphen -separated" , "hyphenated-name" , "" },
304289 {"no install namespace" , "" , regexMismatchError },
305290 {"dot-separated" , "dotted.name" , regexMismatchError },
306291 {"longest valid install namespace" , strings .Repeat ("x" , 63 ), "" },
@@ -329,9 +314,6 @@ func TestClusterExtensionAdmissionInstallNamespace(t *testing.T) {
329314 },
330315 },
331316 Namespace : tc .namespace ,
332- ServiceAccount : ocv1.ServiceAccountReference {
333- Name : "default" ,
334- },
335317 }))
336318 if tc .errMsg == "" {
337319 require .NoError (t , err , "unexpected error for namespace %q: %w" , tc .namespace , err )
@@ -343,38 +325,43 @@ func TestClusterExtensionAdmissionInstallNamespace(t *testing.T) {
343325 }
344326}
345327
328+ // TestClusterExtensionAdmissionServiceAccount validates the deprecated spec.serviceAccount field:
329+ // - CRD-level validation (format, length) still works
330+ // - ValidatingAdmissionPolicy emits a deprecation warning for valid non-empty values
346331func TestClusterExtensionAdmissionServiceAccount (t * testing.T ) {
347332 tooLongError := "spec.serviceAccount.name: Too long: may not be more than 253"
348333 regexMismatchError := "name must be a valid DNS1123 subdomain"
334+ deprecationWarning := "spec.serviceAccount is deprecated"
349335
350336 testCases := []struct {
351337 name string
352338 serviceAccount string
353339 errMsg string
340+ warnMsg string
354341 }{
355- {"just alphanumeric" , "justalphanumeric1" , "" },
356- {"hypen -separated" , "hyphenated-name" , "" },
357- {"dot-separated" , "dotted.name" , "" },
358- {"longest valid service account name" , strings .Repeat ("x" , 253 ), "" },
359- {"too long service account name" , strings .Repeat ("x" , 254 ), tooLongError },
360- {"no service account name" , "" , regexMismatchError },
361- {"spaces" , "spaces spaces" , regexMismatchError },
362- {"capitalized" , "Capitalized" , regexMismatchError },
363- {"camel case" , "camelCase" , regexMismatchError },
364- {"invalid characters" , "many/invalid$characters+in_name" , regexMismatchError },
365- {"starts with hyphen" , "-start-with-hyphen" , regexMismatchError },
366- {"ends with hyphen" , "end-with-hyphen-" , regexMismatchError },
367- {"starts with period" , ".start-with-period" , regexMismatchError },
368- {"ends with period" , "end-with-period." , regexMismatchError },
369- {"multiple sequential separators" , "a.-b" , regexMismatchError },
342+ {"just alphanumeric" , "justalphanumeric1" , "" , deprecationWarning },
343+ {"hyphen -separated" , "hyphenated-name" , "" , deprecationWarning },
344+ {"dot-separated" , "dotted.name" , "" , deprecationWarning },
345+ {"longest valid service account name" , strings .Repeat ("x" , 253 ), "" , deprecationWarning },
346+ {"too long service account name" , strings .Repeat ("x" , 254 ), tooLongError , "" },
347+ {"no service account name" , "" , "" , "" },
348+ {"spaces" , "spaces spaces" , regexMismatchError , "" },
349+ {"capitalized" , "Capitalized" , regexMismatchError , "" },
350+ {"camel case" , "camelCase" , regexMismatchError , "" },
351+ {"invalid characters" , "many/invalid$characters+in_name" , regexMismatchError , "" },
352+ {"starts with hyphen" , "-start-with-hyphen" , regexMismatchError , "" },
353+ {"ends with hyphen" , "end-with-hyphen-" , regexMismatchError , "" },
354+ {"starts with period" , ".start-with-period" , regexMismatchError , "" },
355+ {"ends with period" , "end-with-period." , regexMismatchError , "" },
356+ {"multiple sequential separators" , "a.-b" , regexMismatchError , "" },
370357 }
371358
372359 t .Parallel ()
373360 for _ , tc := range testCases {
374361 tc := tc
375362 t .Run (tc .name , func (t * testing.T ) {
376363 t .Parallel ()
377- cl := newClient (t )
364+ cl , collector := newWarningCapturingClient (t )
378365 err := cl .Create (context .Background (), buildClusterExtension (ocv1.ClusterExtensionSpec {
379366 Source : ocv1.SourceConfig {
380367 SourceType : "Catalog" ,
@@ -383,7 +370,7 @@ func TestClusterExtensionAdmissionServiceAccount(t *testing.T) {
383370 },
384371 },
385372 Namespace : "default" ,
386- ServiceAccount : ocv1.ServiceAccountReference {
373+ ServiceAccount : ocv1.ServiceAccountReference { //nolint:staticcheck // testing deprecated field
387374 Name : tc .serviceAccount ,
388375 },
389376 }))
@@ -393,6 +380,9 @@ func TestClusterExtensionAdmissionServiceAccount(t *testing.T) {
393380 require .Error (t , err )
394381 require .Contains (t , err .Error (), tc .errMsg )
395382 }
383+ if tc .warnMsg != "" {
384+ require .True (t , collector .hasWarning (tc .warnMsg ), "expected deprecation warning containing %q" , tc .warnMsg )
385+ }
396386 })
397387 }
398388}
@@ -442,10 +432,7 @@ func TestClusterExtensionAdmissionInstall(t *testing.T) {
442432 },
443433 },
444434 Namespace : "default" ,
445- ServiceAccount : ocv1.ServiceAccountReference {
446- Name : "default" ,
447- },
448- Install : tc .installConfig ,
435+ Install : tc .installConfig ,
449436 }))
450437 if tc .errMsg == "" {
451438 require .NoError (t , err , "unexpected error for install configuration %v: %w" , tc .installConfig , err )
@@ -494,9 +481,6 @@ func Test_ClusterExtensionAdmissionInlineConfig(t *testing.T) {
494481 },
495482 },
496483 Namespace : "default" ,
497- ServiceAccount : ocv1.ServiceAccountReference {
498- Name : "default" ,
499- },
500484 Config : & ocv1.ClusterExtensionConfig {
501485 ConfigType : ocv1 .ClusterExtensionConfigTypeInline ,
502486 Inline : & apiextensionsv1.JSON {
0 commit comments