44 "context"
55 "fmt"
66 "strings"
7+ "time"
78
89 g "github.com/onsi/ginkgo/v2"
910 o "github.com/onsi/gomega"
@@ -12,6 +13,7 @@ import (
1213 apierrors "k8s.io/apimachinery/pkg/api/errors"
1314 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415 "k8s.io/apimachinery/pkg/util/uuid"
16+ "k8s.io/apimachinery/pkg/util/wait"
1517 e2e "k8s.io/kubernetes/test/e2e/framework"
1618 e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
1719
@@ -155,7 +157,7 @@ func (h *IRITestHelper) DeleteTestPod(namespace, name string) {
155157 }
156158}
157159
158- // CreateSimpleNamespace creates a basic namespace without waiting for service account secrets
160+ // CreateSimpleNamespace creates a basic namespace and waits for SCC annotations
159161func (h * IRITestHelper ) CreateSimpleNamespace () string {
160162 ns := & corev1.Namespace {
161163 ObjectMeta : metav1.ObjectMeta {
@@ -167,6 +169,18 @@ func (h *IRITestHelper) CreateSimpleNamespace() string {
167169 o .Expect (err ).NotTo (o .HaveOccurred (), "Failed to create namespace" )
168170 e2e .Logf ("Created namespace: %s" , createdNs .Name )
169171
172+ // Wait for the namespace controller to set the SCC uid-range annotation,
173+ // which is required by the admission controller before pods can be created.
174+ err = wait .PollUntilContextTimeout (context .Background (), 500 * time .Millisecond , 30 * time .Second , true , func (ctx context.Context ) (bool , error ) {
175+ updatedNs , err := h .oc .AdminKubeClient ().CoreV1 ().Namespaces ().Get (ctx , createdNs .Name , metav1.GetOptions {})
176+ if err != nil {
177+ return false , err
178+ }
179+ _ , exists := updatedNs .Annotations ["openshift.io/sa.scc.uid-range" ]
180+ return exists , nil
181+ })
182+ o .Expect (err ).NotTo (o .HaveOccurred (), "Timed out waiting for namespace %s to get SCC uid-range annotation" , createdNs .Name )
183+
170184 return createdNs .Name
171185}
172186
0 commit comments