Skip to content

Commit

Permalink
Refactor policy e2e framework for same labels tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dyanngg <[email protected]>
  • Loading branch information
Dyanngg committed Jan 9, 2023
1 parent 6c6f020 commit cdf7892
Show file tree
Hide file tree
Showing 7 changed files with 644 additions and 585 deletions.
15 changes: 8 additions & 7 deletions multicluster/test/e2e/antreapolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
var (
allPodsPerCluster []antreae2e.Pod
perNamespacePods []string
perClusterNamespaces map[string]string
perClusterNamespaces map[string]antreae2e.TestNamespaceMeta
podsByNamespace map[string][]antreae2e.Pod
clusterK8sUtilsMap map[string]*antreae2e.KubernetesUtils
)
Expand All @@ -51,19 +51,20 @@ func failOnError(err error, t *testing.T) {
// initializeForPolicyTest creates three Pods in three test Namespaces for each test cluster.
func initializeForPolicyTest(t *testing.T, data *MCTestData) {
perNamespacePods = []string{"a", "b", "c"}
perClusterNamespaces = make(map[string]string)
perClusterNamespaces["x"] = "x"
perClusterNamespaces["y"] = "y"
perClusterNamespaces["z"] = "z"
perClusterNamespaces = make(map[string]antreae2e.TestNamespaceMeta)
nss := []string{"x", "y", "z"}
for _, ns := range nss {
perClusterNamespaces[ns] = antreae2e.TestNamespaceMeta{Name: ns}
}

allPodsPerCluster = []antreae2e.Pod{}
podsByNamespace = make(map[string][]antreae2e.Pod)
clusterK8sUtilsMap = make(map[string]*antreae2e.KubernetesUtils)

for _, podName := range perNamespacePods {
for _, ns := range perClusterNamespaces {
allPodsPerCluster = append(allPodsPerCluster, antreae2e.NewPod(ns, podName))
podsByNamespace[ns] = append(podsByNamespace[ns], antreae2e.NewPod(ns, podName))
allPodsPerCluster = append(allPodsPerCluster, antreae2e.NewPod(ns.Name, podName))
podsByNamespace[ns.Name] = append(podsByNamespace[ns.Name], antreae2e.NewPod(ns.Name, podName))
}
}
for clusterName := range data.clusterTestDataMap {
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/networkpolicy/clusternetworkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,14 @@ func (n *NetworkPolicyController) getNamespaceLabels(ns string) map[string]strin
// groupNamespaceByLabelValue groups Namespaces if they have the same label value for all the
// label keys listed. If a Namespace is missing at least one of the label keys, it will be
// not be grouped. Example:
//
// ns1: app=web, tier=test, tenant=t1
// ns2: app=web, tier=test, tenant=t2
// ns3: app=web, tier=production, tenant=t1
// ns4: app=web, tier=production, tenant=t2
// ns5: app=db, tenant=t1
// labelKeys = [app, tier]
// labelKeys = [app, tier]
//
// Result after grouping:
// "web,test,": [ns1, ns2]
// "web,production,": [ns3, ns4]
Expand Down
Loading

0 comments on commit cdf7892

Please sign in to comment.