@@ -76,6 +76,42 @@ var _ = Describe("Hardened profile (External TLS + Transit auto-unseal + SelfIni
7676 }, framework .DefaultWaitTimeout , framework .DefaultPollInterval ).Should (Succeed ())
7777 }
7878
79+ waitForNetworkPolicy := func (name types.NamespacedName , timeout , pollInterval time.Duration ) error {
80+ deadline := time .Now ().Add (timeout )
81+ var lastErr error
82+
83+ for {
84+ np := & networkingv1.NetworkPolicy {}
85+ err := c .Get (ctx , name , np )
86+ if err == nil {
87+ return nil
88+ }
89+ if ! apierrors .IsNotFound (err ) {
90+ return err
91+ }
92+ lastErr = err
93+
94+ if time .Now ().After (deadline ) {
95+ return fmt .Errorf ("timed out waiting for NetworkPolicy %s/%s: %w" , name .Namespace , name .Name , lastErr )
96+ }
97+
98+ select {
99+ case <- ctx .Done ():
100+ return ctx .Err ()
101+ case <- time .After (pollInterval ):
102+ }
103+ }
104+ }
105+
106+ dumpNetworkPolicyDiagnostics := func (namespace , clusterName string ) {
107+ _ , _ = fmt .Fprintf (GinkgoWriter , "\n ========== NetworkPolicy Diagnostics (%s/%s) ==========\n " , namespace , clusterName )
108+ dumpKubectlOutput ("get" , "openbaocluster" , clusterName , "-n" , namespace , "-o" , "yaml" )
109+ dumpKubectlOutput ("get" , "networkpolicies" , "-n" , namespace , "-o" , "wide" )
110+ dumpKubectlOutput ("get" , "pods" , "-n" , namespace , "-l" , fmt .Sprintf ("%s=%s" , constants .LabelOpenBaoCluster , clusterName ), "-o" , "wide" )
111+ dumpKubectlOutput ("get" , "events" , "-n" , namespace , "--sort-by=.lastTimestamp" )
112+ dumpKubectlOutput ("logs" , "deployment/openbao-operator-controller" , "-n" , operatorNamespace , "--tail=400" )
113+ }
114+
79115 ensureTransitTokenSecret := func () {
80116 By ("creating transit token secret with CA certificate for TLS verification" )
81117 infraBaoCACert , err := e2ehelpers .ReadInfraBaoTLSCACert (ctx , c , f .Namespace , infraBaoName )
@@ -409,11 +445,12 @@ var _ = Describe("Hardened profile (External TLS + Transit auto-unseal + SelfIni
409445 _ , _ = fmt .Fprintf (GinkgoWriter , "OpenBaoCluster %q observed by API server\n " , clusterName )
410446
411447 By ("verifying NetworkPolicy was created" )
412- Eventually (func (g Gomega ) {
413- np := & networkingv1.NetworkPolicy {}
414- npName := types.NamespacedName {Name : clusterName + "-network-policy" , Namespace : f .Namespace }
415- g .Expect (c .Get (ctx , npName , np )).To (Succeed ())
416- }, 30 * time .Second , 2 * time .Second ).Should (Succeed ())
448+ npName := types.NamespacedName {Name : clusterName + "-network-policy" , Namespace : f .Namespace }
449+ err = waitForNetworkPolicy (npName , framework .DefaultWaitTimeout , framework .DefaultPollInterval )
450+ if err != nil {
451+ dumpNetworkPolicyDiagnostics (f .Namespace , clusterName )
452+ }
453+ Expect (err ).NotTo (HaveOccurred ())
417454 _ , _ = fmt .Fprintf (GinkgoWriter , "NetworkPolicy created successfully\n " )
418455
419456 By ("checking for prerequisite resources (ConfigMap and TLS Secrets)" )
0 commit comments