@@ -23,7 +23,6 @@ import (
2323 "github.com/stretchr/testify/assert"
2424 "github.com/stretchr/testify/require"
2525 v1 "k8s.io/api/core/v1"
26- "k8s.io/utils/net"
2726 "sigs.k8s.io/controller-runtime/pkg/client"
2827
2928 "sigs.k8s.io/network-policy-api/apis/v1alpha1"
@@ -35,7 +34,6 @@ func init() {
3534 ConformanceTests = append (ConformanceTests ,
3635 AdminNetworkPolicyEgressNamedPort ,
3736 AdminNetworkPolicyEgressNodePeers ,
38- AdminNetworkPolicyEgressInlineCIDRPeers ,
3937 )
4038}
4139
@@ -143,129 +141,3 @@ var AdminNetworkPolicyEgressNodePeers = suite.ConformanceTest{
143141 })
144142 },
145143}
146-
147- var AdminNetworkPolicyEgressInlineCIDRPeers = suite.ConformanceTest {
148- ShortName : "AdminNetworkPolicyEgressInlineCIDRPeers" ,
149- Description : "Tests support for egress traffic to CIDR peers using admin network policy API based on a server and client model" ,
150- Features : []suite.SupportedFeature {
151- suite .SupportAdminNetworkPolicy ,
152- suite .SupportAdminNetworkPolicyEgressInlineCIDRPeers ,
153- },
154- Manifests : []string {"base/admin_network_policy/experimental-egress-selector-rules.yaml" },
155- Test : func (t * testing.T , s * suite.ConformanceTestSuite ) {
156- ctx , cancel := context .WithTimeout (context .Background (), s .TimeoutConfig .GetTimeout )
157- defer cancel ()
158- // This test uses `node-and-cidr-as-peers-example` ANP
159- t .Run ("Should support a 'deny-egress' rule policy for egress-cidr-peer" , func (t * testing.T ) {
160- // harry-potter-1 is our client pod in gryffindor namespace
161- // Let us pick a pod in ravenclaw namespace and try to connect, it won't work
162- // ensure egress is DENIED to 0.0.0.0/0 from gryffindor; egressRule at index2 should take effect
163- // luna-lovegood-0 is our server pod in ravenclaw namespace
164- serverPod := & v1.Pod {}
165- err := s .Client .Get (ctx , client.ObjectKey {
166- Namespace : "network-policy-conformance-ravenclaw" ,
167- Name : "luna-lovegood-0" ,
168- }, serverPod )
169- require .NoErrorf (t , err , "unable to fetch the server pod" )
170- success := kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "tcp" ,
171- serverPod .Status .PodIP , int32 (80 ), s .TimeoutConfig .RequestTimeout , false )
172- assert .True (t , success )
173- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "udp" ,
174- serverPod .Status .PodIP , int32 (53 ), s .TimeoutConfig .RequestTimeout , false )
175- assert .True (t , success )
176- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "sctp" ,
177- serverPod .Status .PodIP , int32 (9003 ), s .TimeoutConfig .RequestTimeout , false )
178- assert .True (t , success )
179- // Let us pick a pod in hufflepuff namespace and try to connect, it won't work
180- // ensure egress is DENIED to 0.0.0.0/0 from gryffindor; egressRule at index2 should take effect
181- // cedric-diggory-0 is our server pod in hufflepuff namespace
182- serverPod = & v1.Pod {}
183- err = s .Client .Get (ctx , client.ObjectKey {
184- Namespace : "network-policy-conformance-hufflepuff" ,
185- Name : "cedric-diggory-0" ,
186- }, serverPod )
187- require .NoErrorf (t , err , "unable to fetch the server pod" )
188- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "tcp" ,
189- serverPod .Status .PodIP , int32 (80 ), s .TimeoutConfig .RequestTimeout , false )
190- assert .True (t , success )
191- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "udp" ,
192- serverPod .Status .PodIP , int32 (53 ), s .TimeoutConfig .RequestTimeout , false )
193- assert .True (t , success )
194- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "sctp" ,
195- serverPod .Status .PodIP , int32 (9003 ), s .TimeoutConfig .RequestTimeout , false )
196- assert .True (t , success )
197- })
198- // To test allow CIDR rule, insert the following rule at index0
199- //- name: "allow-egress-to-specific-podIPs"
200- // action: "Allow"
201- // to:
202- // - networks:
203- // - luna-lovegood-0.IP
204- // - cedric-diggory-0.IP
205- t .Run ("Should support an 'allow-egress' rule policy for egress-cidr-peer" , func (t * testing.T ) {
206- serverPodRavenclaw := & v1.Pod {}
207- err := s .Client .Get (ctx , client.ObjectKey {
208- Namespace : "network-policy-conformance-ravenclaw" ,
209- Name : "luna-lovegood-0" ,
210- }, serverPodRavenclaw )
211- require .NoErrorf (t , err , "unable to fetch the server pod" )
212- serverPodHufflepuff := & v1.Pod {}
213- err = s .Client .Get (ctx , client.ObjectKey {
214- Namespace : "network-policy-conformance-hufflepuff" ,
215- Name : "cedric-diggory-0" ,
216- }, serverPodHufflepuff )
217- require .NoErrorf (t , err , "unable to fetch the server pod" )
218- anp := & v1alpha1.AdminNetworkPolicy {}
219- err = s .Client .Get (ctx , client.ObjectKey {
220- Name : "node-and-cidr-as-peers-example" ,
221- }, anp )
222- require .NoErrorf (t , err , "unable to fetch the admin network policy" )
223- mutate := anp .DeepCopy ()
224- var mask string
225- if net .IsIPv4String (serverPodRavenclaw .Status .PodIP ) {
226- mask = "/32"
227- } else {
228- mask = "/128"
229- }
230- // insert new rule at index0; append the rest of the rules in the node-and-cidr-as-peers-example
231- newRule := []v1alpha1.AdminNetworkPolicyEgressRule {
232- {
233- Name : "allow-egress-to-specific-podIPs" ,
234- Action : "Allow" ,
235- To : []v1alpha1.AdminNetworkPolicyEgressPeer {
236- {
237- Networks : []v1alpha1.CIDR {
238- v1alpha1 .CIDR (serverPodRavenclaw .Status .PodIP + mask ),
239- v1alpha1 .CIDR (serverPodHufflepuff .Status .PodIP + mask ),
240- },
241- },
242- },
243- },
244- }
245- mutate .Spec .Egress = append (newRule , mutate .Spec .Egress ... )
246- err = s .Client .Patch (ctx , mutate , client .MergeFrom (anp ))
247- require .NoErrorf (t , err , "unable to patch the admin network policy" )
248- // harry-potter-0 is our client pod in gryffindor namespace
249- // ensure egress is ALLOWED to luna-lovegood-0.IP and cedric-diggory-0.IP
250- // new egressRule at index0 should take effect
251- success := kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "tcp" ,
252- serverPodRavenclaw .Status .PodIP , int32 (80 ), s .TimeoutConfig .RequestTimeout , true )
253- assert .True (t , success )
254- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "udp" ,
255- serverPodRavenclaw .Status .PodIP , int32 (53 ), s .TimeoutConfig .RequestTimeout , true )
256- assert .True (t , success )
257- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "sctp" ,
258- serverPodRavenclaw .Status .PodIP , int32 (9003 ), s .TimeoutConfig .RequestTimeout , true )
259- assert .True (t , success )
260- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "tcp" ,
261- serverPodHufflepuff .Status .PodIP , int32 (80 ), s .TimeoutConfig .RequestTimeout , true )
262- assert .True (t , success )
263- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "udp" ,
264- serverPodHufflepuff .Status .PodIP , int32 (53 ), s .TimeoutConfig .RequestTimeout , true )
265- assert .True (t , success )
266- success = kubernetes .PokeServer (t , s .ClientSet , & s .KubeConfig , "network-policy-conformance-gryffindor" , "harry-potter-1" , "sctp" ,
267- serverPodHufflepuff .Status .PodIP , int32 (9003 ), s .TimeoutConfig .RequestTimeout , true )
268- assert .True (t , success )
269- })
270- },
271- }
0 commit comments