@@ -60,15 +60,51 @@ var staticOpenPortsToIgnore = []types.ComDetails{
6060 },
6161}
6262
63+ // port used only interanly just on ci.
64+ var staticOpenPortsToIgnoreInStaticEntry = []types.ComDetails {
65+ {
66+ Direction : "Ingress" ,
67+ Protocol : "TCP" ,
68+ Port : 10250 ,
69+ NodeRole : "worker" ,
70+ Optional : false ,
71+ },
72+ {
73+ Direction : "Ingress" ,
74+ Protocol : "TCP" ,
75+ Port : 10250 ,
76+ NodeRole : "master" ,
77+ Optional : false ,
78+ },
79+ {
80+ Direction : "Ingress" ,
81+ Protocol : "TCP" ,
82+ Port : 6385 ,
83+ NodeRole : "master" ,
84+ Optional : false ,
85+ },
86+ }
87+
88+ var (
89+ cs * client.ClientSet
90+ epExporter * endpointslices.EndpointSlicesExporter
91+ isSNO bool
92+ infraType configv1.PlatformType
93+ deployment types.Deployment
94+ utilsHelpers utils.UtilsInterface
95+ artifactsDir string
96+ commMatrixCreator * commatrixcreator.CommunicationMatrixCreator
97+ )
98+
6399var _ = Describe ("[sig-network][Feature:commatrix][apigroup:config.openshift.io][Serial]" , func () {
64- It ( "generated communication matrix should be equal to documented communication matrix" , func () {
100+ BeforeEach ( func () {
65101 kubeconfig := os .Getenv ("KUBECONFIG" )
66102 if kubeconfig == "" {
67103 Fail ("KUBECONFIG not set" )
68104 }
69105
70106 By ("Creating output folder" )
71- artifactsDir : = os .Getenv ("ARTIFACT_DIR" )
107+ artifactsDir = os .Getenv ("ARTIFACT_DIR" )
72108 if artifactsDir == "" {
73109 log .Println ("env var ARTIFACT_DIR is not set, using default value" )
74110 }
@@ -78,47 +114,50 @@ var _ = Describe("[sig-network][Feature:commatrix][apigroup:config.openshift.io]
78114 Expect (err ).NotTo (HaveOccurred ())
79115
80116 By ("Creating the clients for the Generating step" )
81- cs , err : = client .New ()
117+ cs , err = client .New ()
82118 Expect (err ).NotTo (HaveOccurred ())
83119
84- utilsHelpers := utils .New (cs )
85-
86- epExporter , err := endpointslices .New (cs )
87- Expect (err ).ToNot (HaveOccurred ())
88-
89- By ("Get cluster's version and check if it's suitable for test" )
90- clusterVersionStr , err := cluster .GetClusterVersion (cs )
120+ utilsHelpers = utils .New (cs )
121+ epExporter , err = endpointslices .New (cs )
91122 Expect (err ).NotTo (HaveOccurred ())
92- clusterVersion , err := version .NewVersion (clusterVersionStr )
93- Expect (err ).ToNot (HaveOccurred ())
94-
95- minimalDocCommatrixVersion , err := version .NewVersion (minimalDocCommatrixVersionStr )
96- Expect (err ).ToNot (HaveOccurred ())
97-
98- if clusterVersion .LessThan (minimalDocCommatrixVersion ) {
99- Skip (fmt .Sprintf ("Cluster version is lower than the lowest version that has a documented communication matrix (%v)" , minimalDocCommatrixVersionStr ))
100- }
101123
102124 By ("Get cluster's deployment and infrastructure types" )
103- deployment : = types .Standard
104- isSNO , err : = utilsHelpers .IsSNOCluster ()
125+ deployment = types .Standard
126+ isSNO , err = utilsHelpers .IsSNOCluster ()
105127 Expect (err ).NotTo (HaveOccurred ())
128+
106129 if isSNO {
107130 deployment = types .SNO
108131 }
109132
110- platformType , err : = utilsHelpers .GetPlatformType ()
133+ infraType , err = utilsHelpers .GetPlatformType ()
111134 Expect (err ).NotTo (HaveOccurred ())
112135
113136 // if cluster's type is not supported by the commatrix app, skip tests
114- if ! slices .Contains (types .SupportedPlatforms , platformType ) {
115- Skip (fmt .Sprintf ("unsupported platform type: %s. Supported platform types are: %v" , platformType , types .SupportedPlatforms ))
137+ if ! slices .Contains (types .SupportedPlatforms , infraType ) {
138+ Skip (fmt .Sprintf ("unsupported platform type: %s. Supported platform types are: %v" , infraType , types .SupportedPlatforms ))
116139 }
117140
118- By ("Generating cluster's communication matrix" )
119- commMatrixCreator , err := commatrixcreator .New (epExporter , "" , "" , platformType , deployment )
141+ By ("Generating cluster's communication matrix creator" )
142+ commMatrixCreator , err = commatrixcreator .New (epExporter , "" , "" , infraType , deployment )
143+ Expect (err ).NotTo (HaveOccurred ())
144+ })
145+
146+ It ("generated communication matrix should be equal to documented communication matrix" , func () {
147+ By ("Get cluster's version and check if it's suitable for test" )
148+ clusterVersionStr , err := cluster .GetClusterVersion (cs )
120149 Expect (err ).NotTo (HaveOccurred ())
150+ clusterVersion , err := version .NewVersion (clusterVersionStr )
151+ Expect (err ).ToNot (HaveOccurred ())
152+
153+ minimalDocCommatrixVersion , err := version .NewVersion (minimalDocCommatrixVersionStr )
154+ Expect (err ).ToNot (HaveOccurred ())
155+
156+ if clusterVersion .LessThan (minimalDocCommatrixVersion ) {
157+ Skip (fmt .Sprintf ("Cluster version is lower than the lowest version that has a documented communication matrix (%v)" , minimalDocCommatrixVersionStr ))
158+ }
121159
160+ By ("Create endpoint matrix " )
122161 commatrix , err := commMatrixCreator .CreateEndpointMatrix ()
123162 Expect (err ).NotTo (HaveOccurred ())
124163
@@ -130,7 +169,7 @@ var _ = Describe("[sig-network][Feature:commatrix][apigroup:config.openshift.io]
130169
131170 // clusters with unsupported platform types had skip the test, so we assume the platform type is supported
132171 var docType string
133- switch platformType {
172+ switch infraType {
134173 case configv1 .AWSPlatformType :
135174 docType = "aws"
136175 case configv1 .BareMetalPlatformType :
@@ -214,4 +253,40 @@ var _ = Describe("[sig-network][Feature:commatrix][apigroup:config.openshift.io]
214253 Expect (err ).ToNot (HaveOccurred ())
215254 }
216255 })
256+
257+ It ("Static entries should not overlap with those in the EndpointSlice; any shared entries must be removed" , func () {
258+ By ("Get EndpointSlice matrix" )
259+ err := epExporter .LoadExposedEndpointSlicesInfo ()
260+ Expect (err ).NotTo (HaveOccurred ())
261+
262+ epSliceComDetails , err := epExporter .ToComDetails ()
263+ Expect (err ).NotTo (HaveOccurred ())
264+
265+ By ("Get static entries list" )
266+ staticEntries , err := commMatrixCreator .GetStaticEntries ()
267+ Expect (err ).NotTo (HaveOccurred ())
268+
269+ staticEntriesMat := & types.ComMatrix {Matrix : staticEntries }
270+ epSliceComDetailsMat := & types.ComMatrix {Matrix : epSliceComDetails }
271+
272+ By ("Write the matrix to files" )
273+ err = staticEntriesMat .WriteMatrixToFileByType (utilsHelpers , "static-entry-matrix" , types .FormatCSV , deployment , artifactsDir )
274+ Expect (err ).ToNot (HaveOccurred ())
275+
276+ err = epSliceComDetailsMat .WriteMatrixToFileByType (utilsHelpers , "expose-communication-matrix" , types .FormatCSV , deployment , artifactsDir )
277+ Expect (err ).ToNot (HaveOccurred ())
278+
279+ By ("Generating the Diff between the static entris and the expose communication matrix" )
280+ endpointslicesDiffWithstaticEntrieMat := matrixdiff .Generate (epSliceComDetailsMat , staticEntriesMat )
281+ sharedEntries := endpointslicesDiffWithstaticEntrieMat .GetSharedEntries ()
282+
283+ portsToIgnoreMat := & types.ComMatrix {Matrix : staticOpenPortsToIgnoreInStaticEntry }
284+ sharedEntriesDiffWithIgnoredPorts := matrixdiff .Generate (sharedEntries , portsToIgnoreMat )
285+ staticEntryNeedToRemove := sharedEntriesDiffWithIgnoredPorts .GetUniquePrimary ()
286+
287+ if len (staticEntryNeedToRemove .Matrix ) > 0 {
288+ err := fmt .Errorf ("the following ports must be removed from the static entry file, as they already exist in an EndpointSlice:\n %s" , staticEntryNeedToRemove )
289+ Expect (err ).NotTo (HaveOccurred ())
290+ }
291+ })
217292})
0 commit comments