1- package networking
1+ package config_operator
22
33import (
44 "context"
@@ -15,6 +15,7 @@ import (
1515 corev1 "k8s.io/api/core/v1"
1616 networkingv1 "k8s.io/api/networking/v1"
1717 "k8s.io/apimachinery/pkg/api/equality"
18+ apierrors "k8s.io/apimachinery/pkg/api/errors"
1819 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920 "k8s.io/apimachinery/pkg/types"
2021 "k8s.io/apimachinery/pkg/util/intstr"
@@ -34,7 +35,7 @@ const (
3435 defaultDenyAllPolicyName = "default-deny-all"
3536)
3637
37- var _ = g .Describe ("[sig-network ][Feature:NetworkPolicy][Skipped:HyperShift][Skipped:MicroShift] Config Operator NetworkPolicy" , func () {
38+ var _ = g .Describe ("[sig-api-machinery ][Feature:NetworkPolicy][Skipped:HyperShift][Skipped:MicroShift] Config Operator NetworkPolicy" , func () {
3839 oc := exutil .NewCLI ("config-operator-networkpolicy-e2e" )
3940 f := oc .KubeFramework ()
4041 f .NamespacePodSecurityLevel = admissionapi .LevelPrivileged
@@ -108,7 +109,16 @@ var _ = g.Describe("[sig-network][Feature:NetworkPolicy][Skipped:HyperShift][Ski
108109
109110 g .By ("Verifying denied ports even from same namespace" )
110111 for _ , port := range []int32 {80 , 443 , 6443 , 9090 } {
111- expectConnectivity (ctx , cs , configOperatorNamespace , operatorLabels , allowedServerIPs , port , false )
112+ serverIPs , cleanup := createServerPod (
113+ ctx ,
114+ cs ,
115+ configOperatorNamespace ,
116+ fmt .Sprintf ("np-operator-denied-%d-%s" , port , rand .String (5 )),
117+ operatorLabels ,
118+ port ,
119+ )
120+ g .DeferCleanup (cleanup )
121+ expectConnectivity (ctx , cs , configOperatorNamespace , operatorLabels , serverIPs , port , false )
112122 }
113123
114124 g .By ("Checking if NetworkPolicy allows DNS egress" )
@@ -768,14 +778,23 @@ func restoreNetworkPolicy(ctx context.Context, client kubernetes.Interface, expe
768778 g .GinkgoHelper ()
769779 namespace := expected .Namespace
770780 name := expected .Name
781+ originalUID := expected .UID
782+ sawDeletion := false
771783 g .GinkgoWriter .Printf ("deleting NetworkPolicy %s/%s\n " , namespace , name )
772784 err := client .NetworkingV1 ().NetworkPolicies (namespace ).Delete (ctx , name , metav1.DeleteOptions {})
773785 o .Expect (err ).NotTo (o .HaveOccurred ())
774786 err = wait .PollUntilContextTimeout (ctx , 5 * time .Second , 10 * time .Minute , true , func (ctx context.Context ) (bool , error ) {
775787 current , err := client .NetworkingV1 ().NetworkPolicies (namespace ).Get (ctx , name , metav1.GetOptions {})
788+ if apierrors .IsNotFound (err ) {
789+ sawDeletion = true
790+ return false , nil
791+ }
776792 if err != nil {
777793 return false , nil
778794 }
795+ if current .UID == originalUID && ! sawDeletion {
796+ return false , nil
797+ }
779798 return equality .Semantic .DeepEqual (expected .Spec , current .Spec ), nil
780799 })
781800 o .Expect (err ).NotTo (o .HaveOccurred (), "timed out waiting for NetworkPolicy %s/%s spec to be restored" , namespace , name )
0 commit comments