@@ -39,6 +39,7 @@ import (
3939// The Validating Admission Policy feature gate is GA and enabled by default from OCP v4.17 (k8s v1.30)
4040
4141var (
42+ err error
4243 ns * corev1.Namespace
4344 nsNoLabel * corev1.Namespace
4445 rf * kueuev1beta1.ResourceFlavor
@@ -56,20 +57,19 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
5657
5758 Tags (t , Sanity )
5859
59- // Create a namespace
60- ns = CreateTestNamespaceWithName (test , uniqueSuffix ("vap" ))
61- defer test .Client ().Core ().CoreV1 ().Namespaces ().Delete (test .Ctx (), ns .Name , metav1.DeleteOptions {})
62-
63- // Get the latest version of the namespace
64- ns , err := test .Client ().Core ().CoreV1 ().Namespaces ().Get (test .Ctx (), ns .Name , metav1.GetOptions {})
65- test .Expect (err ).ToNot (HaveOccurred ())
66-
67- // Add the 'kueue.openshift.io/managed' label
68- ns .Labels = map [string ]string {
69- "kueue.openshift.io/managed" : "true" ,
70- }
71- _ , err = test .Client ().Core ().CoreV1 ().Namespaces ().Update (test .Ctx (), ns , metav1.UpdateOptions {})
72- test .Expect (err ).ToNot (HaveOccurred ())
60+ // Create namespace with unique name and required labels
61+ var AsDefaultQueueNamespace = ErrorOption [* corev1.Namespace ](func (ns * corev1.Namespace ) error {
62+ if ns .Labels == nil {
63+ ns .Labels = make (map [string ]string )
64+ }
65+ ns .Labels ["kueue.openshift.io/managed" ] = "true"
66+ return nil
67+ })
68+ ns = CreateTestNamespaceWithName (
69+ test ,
70+ uniqueSuffix ("vap" ),
71+ AsDefaultQueueNamespace ,
72+ )
7373
7474 // Create a namespace that will not receive the `kueue.x-k8s.io/queue-name` label
7575 nsNoLabel = CreateTestNamespaceWithName (test , uniqueSuffix ("vap-nl" ))
0 commit comments