Skip to content

Commit ccf190a

Browse files
Merge pull request #29782 from aabughosh/staticEntryTest
CNF-17748: Add a comparing between static entry test
2 parents 2116b0f + 0577e99 commit ccf190a

File tree

3 files changed

+110
-30
lines changed

3 files changed

+110
-30
lines changed

go.mod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ require (
9393
sigs.k8s.io/yaml v1.4.0
9494
)
9595

96+
require (
97+
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
98+
github.com/gocarina/gocsv v0.0.0-20231116093920-b87c2d0e983a // indirect
99+
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
100+
)
101+
96102
require (
97103
cel.dev/expr v0.18.0 // indirect
98104
git.sr.ht/~sbinet/gg v0.5.0 // indirect
@@ -154,7 +160,6 @@ require (
154160
github.com/emirpasic/gods v1.12.0 // indirect
155161
github.com/euank/go-kmsg-parser v2.0.0+incompatible // indirect
156162
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
157-
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
158163
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
159164
github.com/fatih/camelcase v1.0.0 // indirect
160165
github.com/felixge/fgprof v0.9.4 // indirect
@@ -172,7 +177,6 @@ require (
172177
github.com/go-openapi/swag v0.23.0 // indirect
173178
github.com/go-pdf/fpdf v0.8.0 // indirect
174179
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
175-
github.com/gocarina/gocsv v0.0.0-20231116093920-b87c2d0e983a // indirect
176180
github.com/godbus/dbus/v5 v5.1.0 // indirect
177181
github.com/gogo/protobuf v1.3.2 // indirect
178182
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
@@ -290,7 +294,6 @@ require (
290294
golang.org/x/text v0.23.0 // indirect
291295
golang.org/x/time v0.7.0 // indirect
292296
golang.org/x/tools v0.26.0 // indirect
293-
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
294297
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
295298
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
296299
google.golang.org/genproto/googleapis/rpc v0.0.0-20240924160255-9d4c2d233b61 // indirect

test/extended/networking/commatrix.go

Lines changed: 102 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
6399
var _ = 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
})

test/extended/util/annotate/generated/zz_generated.annotations.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)