Skip to content

Commit 277857b

Browse files
aleoliadamjensenbot
authored andcommitted
integrate namespace mapping e2e tests
1 parent cde79c2 commit 277857b

File tree

17 files changed

+221
-136
lines changed

17 files changed

+221
-136
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,4 @@ installer/%:
212212
${PWD}/test/e2e/pipeline/$@.sh
213213

214214
e2e/%:
215-
go test ${PWD}/test/$@ -count=1
215+
go test ${PWD}/test/$@/... -count=1

pkg/liqoctl/common/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ExtractValueFromArgumentList(key string, argumentList []string) (string, er
3434
prefix := key + "="
3535
for _, argument := range argumentList {
3636
if strings.HasPrefix(argument, prefix) {
37-
return strings.Split(argument, "=")[1], nil
37+
return strings.Join(strings.Split(argument, "=")[1:], "="), nil
3838
}
3939
}
4040
return "", fmt.Errorf("argument not found")

pkg/liqoctl/generate/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func processGenerateCommand(ctx context.Context, clientSet client.Client, liqoNa
6565
}
6666

6767
// Retrieve the liqo controller manager deployment args
68-
args, err := retrieveLiqoControllerManagerDeploymentArgs(ctx, clientSet, liqoNamespace)
68+
args, err := RetrieveLiqoControllerManagerDeploymentArgs(ctx, clientSet, liqoNamespace)
6969
if err != nil {
7070
klog.Fatalf(err.Error())
7171
}
@@ -103,8 +103,8 @@ func generateCommandString(commandName, authEP, clusterID, localToken, clusterNa
103103
return strings.Join(command, " ")
104104
}
105105

106-
// retrieveLiqoControllerManagerDeploymentArgs retrieves the list of arguments associated with the liqo controller manager deployment.
107-
func retrieveLiqoControllerManagerDeploymentArgs(ctx context.Context, clientSet client.Client, liqoNamespace string) ([]string, error) {
106+
// RetrieveLiqoControllerManagerDeploymentArgs retrieves the list of arguments associated with the liqo controller manager deployment.
107+
func RetrieveLiqoControllerManagerDeploymentArgs(ctx context.Context, clientSet client.Client, liqoNamespace string) ([]string, error) {
108108
// Retrieve the deployment of the liqo controller manager component
109109
var deployments appsv1.DeploymentList
110110
if err := clientSet.List(ctx, &deployments, client.InNamespace(liqoNamespace), client.MatchingLabelsSelector{

test/e2e/cruise/basic_test.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
. "github.com/onsi/ginkgo"
2525
. "github.com/onsi/ginkgo/extensions/table"
2626
. "github.com/onsi/gomega"
27-
"k8s.io/apimachinery/pkg/labels"
28-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2927

3028
"github.com/liqotech/liqo/test/e2e/testconsts"
3129
"github.com/liqotech/liqo/test/e2e/testutils/microservices"
@@ -37,8 +35,6 @@ import (
3735
const (
3836
// clustersRequired is the number of clusters required in this E2E test.
3937
clustersRequired = 2
40-
// controllerClientPresence indicates if the test use the controller runtime clients.
41-
controllerClientPresence = true
4238
// testName is the name of this E2E test.
4339
testName = "E2E_PEERING"
4440
)
@@ -52,7 +48,7 @@ func TestE2E(t *testing.T) {
5248
var _ = Describe("Liqo E2E", func() {
5349
var (
5450
ctx = context.Background()
55-
testContext = tester.GetTester(ctx, clustersRequired, controllerClientPresence)
51+
testContext = tester.GetTester(ctx)
5652
namespace = "liqo"
5753
interval = 3 * time.Second
5854
timeout = 5 * time.Minute
@@ -189,22 +185,11 @@ var _ = Describe("Liqo E2E", func() {
189185
})
190186

191187
AfterSuite(func() {
192-
193188
for i := range testContext.Clusters {
194-
err := util.DeleteNamespace(ctx, testContext.Clusters[i].NativeClient, testconsts.LiqoTestNamespaceLabels)
195-
Expect(err).ShouldNot(HaveOccurred())
189+
Eventually(func() error {
190+
return util.EnsureNamespaceDeletion(ctx, testContext.Clusters[i].NativeClient, testconsts.LiqoTestNamespaceLabels)
191+
}, timeout, interval).Should(Succeed())
196192
}
197-
Eventually(func() bool {
198-
for i := range testContext.Clusters {
199-
list, err := testContext.Clusters[i].NativeClient.CoreV1().Namespaces().List(ctx, metav1.ListOptions{
200-
LabelSelector: labels.SelectorFromSet(testconsts.LiqoTestNamespaceLabels).String(),
201-
})
202-
if err != nil || len(list.Items) > 0 {
203-
return false
204-
}
205-
}
206-
return true
207-
}, timeout, interval).Should(BeTrue())
208193
})
209194
})
210195

test/e2e/advanced_e2e/cluster_labels_e2e/cluster_labels_test.go renamed to test/e2e/cruise/cluster_labels_e2e/cluster_labels_test.go

Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright 2019-2021 The Liqo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package clusterlabels tests the cluster labels.
116
package clusterlabels
217

318
import (
@@ -13,13 +28,16 @@ import (
1328
apierrors "k8s.io/apimachinery/pkg/api/errors"
1429
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1530
"k8s.io/apimachinery/pkg/types"
31+
"k8s.io/client-go/kubernetes"
1632
k8shelper "k8s.io/component-helpers/scheduling/corev1"
1733
"sigs.k8s.io/controller-runtime/pkg/client"
1834

19-
configv1alpha1 "github.com/liqotech/liqo/apis/config/v1alpha1"
2035
offloadingv1alpha1 "github.com/liqotech/liqo/apis/offloading/v1alpha1"
2136
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
2237
liqoconst "github.com/liqotech/liqo/pkg/consts"
38+
"github.com/liqotech/liqo/pkg/liqoctl/common"
39+
"github.com/liqotech/liqo/pkg/liqoctl/generate"
40+
argsutils "github.com/liqotech/liqo/pkg/utils/args"
2341
liqoutils "github.com/liqotech/liqo/pkg/utils/foreignCluster"
2442
"github.com/liqotech/liqo/test/e2e/testutils/tester"
2543
"github.com/liqotech/liqo/test/e2e/testutils/util"
@@ -28,12 +46,8 @@ import (
2846
const (
2947
// clustersRequired is the number of clusters required in this E2E test.
3048
clustersRequired = 4
31-
// clusterConfigName is the name of the ClusterConfig in every cluster with Liqo.
32-
clusterConfigName = "liqo-configuration"
3349
// testNamespaceName is the name of the test namespace for this test.
3450
testNamespaceName = "test-namespace-labels"
35-
// controllerClientPresence indicates if the test use the controller runtime clients.
36-
controllerClientPresence = true
3751
// testName is the name of this E2E test.
3852
testName = "E2E_CLUSTER_LABELS"
3953
)
@@ -47,32 +61,48 @@ func TestE2E(t *testing.T) {
4761
var _ = Describe("Liqo E2E", func() {
4862
var (
4963
ctx = context.Background()
50-
testContext = tester.GetTester(ctx, clustersRequired, controllerClientPresence)
64+
testContext = tester.GetTester(ctx)
5165
interval = 1 * time.Second
5266
// shortTimeout is used for Consistently statement
5367
shortTimeout = 5 * time.Second
5468
timeout = 10 * time.Second
5569
// longTimeout is used in situations that may take longer to be performed
5670
longTimeout = 2 * time.Minute
5771
localIndex = 0
72+
73+
getTableEntries = func() []TableEntry {
74+
res := []TableEntry{}
75+
for i := 0; i < 4; i++ {
76+
res = append(res, Entry(
77+
fmt.Sprintf("Check the ClusterConfig resource of the cluster %v", i+1),
78+
testContext.Clusters[i],
79+
i,
80+
util.GetClusterLabels(i),
81+
))
82+
}
83+
return res
84+
}
5885
)
5986

60-
Context("Assert that labels inserted at installation time are in the right resources: clusterConfig,"+
87+
Context("Assert that labels inserted at installation time are in the right resources: ControllerManager args,"+
6188
" resourceOffer and virtualNodes", func() {
6289

63-
DescribeTable(" 1 - Check labels presence in the ClusterConfig resources for every cluster",
64-
// Every cluster must have in its ClusterConfig Resource, the labels inserted at installation time.
65-
func(cluster tester.ClusterContext, clusterLabels map[string]string) {
66-
clusterConfig := &configv1alpha1.ClusterConfig{}
67-
Eventually(func() error {
68-
return cluster.ControllerClient.Get(ctx, types.NamespacedName{Name: clusterConfigName}, clusterConfig)
69-
}, timeout, interval).Should(BeNil())
70-
Expect(clusterConfig.Spec.DiscoveryConfig.ClusterLabels).To(Equal(clusterLabels))
90+
DescribeTable(" 1 - Check labels presence in the ControllerManager arguments for every cluster",
91+
func(cluster tester.ClusterContext, index int, clusterLabels map[string]string) {
92+
args, err := generate.RetrieveLiqoControllerManagerDeploymentArgs(ctx, cluster.ControllerClient, "liqo")
93+
Expect(err).ToNot(HaveOccurred())
94+
95+
val, err := common.ExtractValueFromArgumentList("--cluster-labels", args)
96+
Expect(err).ToNot(HaveOccurred())
97+
98+
labels := argsutils.StringMap{}
99+
Expect(labels.Set(val)).To(Succeed())
100+
101+
for key, value := range clusterLabels {
102+
Expect(labels.StringMap).To(HaveKeyWithValue(key, value))
103+
}
71104
},
72-
Entry("Check the ClusterConfig resource of the cluster 1", testContext.Clusters[0], util.GetClusterLabels(0)),
73-
Entry("Check the ClusterConfig resource of the cluster 2", testContext.Clusters[1], util.GetClusterLabels(1)),
74-
Entry("Check the ClusterConfig resource of the cluster 3", testContext.Clusters[2], util.GetClusterLabels(2)),
75-
Entry("Check the ClusterConfig resource of the cluster 4", testContext.Clusters[3], util.GetClusterLabels(3)),
105+
getTableEntries()...,
76106
)
77107

78108
DescribeTable(" 2 - Check labels presence in the ResourceOffer resources for every cluster",
@@ -100,13 +130,12 @@ var _ = Describe("Liqo E2E", func() {
100130
Name: fmt.Sprintf("%s-%s", resourceOfferNamePrefix, cluster.ClusterID),
101131
}, resourceOffer)
102132
}, timeout, interval).Should(BeNil())
103-
Expect(resourceOffer.Spec.Labels).To(Equal(clusterLabels))
133+
for key, value := range clusterLabels {
134+
Expect(resourceOffer.Spec.Labels).To(HaveKeyWithValue(key, value))
135+
}
104136
}
105137
},
106-
Entry("Check the ResourceOffer resources of the cluster 1", testContext.Clusters[0], 0, util.GetClusterLabels(0)),
107-
Entry("Check the ResourceOffer resources of the cluster 2", testContext.Clusters[1], 1, util.GetClusterLabels(1)),
108-
Entry("Check the ResourceOffer resources of the cluster 3", testContext.Clusters[2], 2, util.GetClusterLabels(2)),
109-
Entry("Check the ResourceOffer resources of the cluster 4", testContext.Clusters[3], 3, util.GetClusterLabels(3)),
138+
getTableEntries()...,
110139
)
111140

112141
DescribeTable(" 3 - Check labels presence on the virtual nodes for every cluster",
@@ -130,10 +159,7 @@ var _ = Describe("Liqo E2E", func() {
130159
}
131160

132161
},
133-
Entry("Check the virtual node of the cluster 1", testContext.Clusters[0], 0, util.GetClusterLabels(0)),
134-
Entry("Check the virtual node of the cluster 2", testContext.Clusters[1], 1, util.GetClusterLabels(1)),
135-
Entry("Check the virtual node of the cluster 3", testContext.Clusters[2], 2, util.GetClusterLabels(2)),
136-
Entry("Check the virtual node of the cluster 4", testContext.Clusters[3], 3, util.GetClusterLabels(3)),
162+
getTableEntries()...,
137163
)
138164

139165
})
@@ -172,24 +198,36 @@ var _ = Describe("Liqo E2E", func() {
172198
match, err := k8shelper.MatchNodeSelectorTerms(&virtualNodesList.Items[i], util.GetClusterSelector())
173199
Expect(err).To(BeNil())
174200
remoteClusterID := virtualNodesList.Items[i].Annotations[liqoconst.RemoteClusterID]
201+
202+
var cl kubernetes.Interface
203+
for j := range testContext.Clusters {
204+
cluster := &testContext.Clusters[j]
205+
if cluster.ClusterID == remoteClusterID {
206+
cl = cluster.NativeClient
207+
break
208+
}
209+
}
210+
Expect(cl).ToNot(BeNil())
211+
175212
if match {
176213
// Check if the remote namespace is correctly created.
177214
By(fmt.Sprintf(" 5 - Checking if a remote namespace is correctly created inside cluster '%s'", remoteClusterID))
178215
namespace := &corev1.Namespace{}
216+
179217
Eventually(func() error {
180-
return testContext.ClustersClients[remoteClusterID].Get(ctx,
181-
types.NamespacedName{Name: testNamespaceName}, namespace)
218+
namespace, err = cl.CoreV1().Namespaces().Get(ctx, testNamespaceName, metav1.GetOptions{})
219+
return err
182220
}, timeout, interval).Should(BeNil())
221+
183222
value, ok := namespace.Annotations[liqoconst.RemoteNamespaceAnnotationKey]
184223
Expect(ok).To(BeTrue())
185224
Expect(value).To(Equal(testContext.Clusters[localIndex].ClusterID))
186225
} else {
187226
// Check if the remote namespace does not exists.
188227
By(fmt.Sprintf(" 5 - Checking that no remote namespace is created inside cluster '%s'", remoteClusterID))
189228
Consistently(func() metav1.StatusReason {
190-
namespace := &corev1.Namespace{}
191-
return apierrors.ReasonForError(testContext.ClustersClients[remoteClusterID].Get(ctx,
192-
types.NamespacedName{Name: testNamespaceName}, namespace))
229+
_, err = cl.CoreV1().Namespaces().Get(ctx, testNamespaceName, metav1.GetOptions{})
230+
return apierrors.ReasonForError(err)
193231
}, shortTimeout, interval).Should(Equal(metav1.StatusReasonNotFound))
194232
}
195233

@@ -221,12 +259,6 @@ var _ = Describe("Liqo E2E", func() {
221259
types.NamespacedName{Name: testNamespaceName}, namespace))
222260
}, timeout, interval).Should(Equal(metav1.StatusReasonNotFound))
223261
}
224-
225-
// Cleaning the environment after the test.
226-
By(" 3 - Getting the local namespace and delete it")
227-
Eventually(func() error {
228-
return util.EnsureNamespaceDeletion(ctx, testContext.Clusters[localIndex].NativeClient, util.GetNamespaceLabel(false))
229-
}, timeout, interval).Should(BeNil())
230262
})
231263
})
232264
})

test/e2e/advanced_e2e/conflict_remote_namespace_e2e/conflict_creation_test.go renamed to test/e2e/cruise/conflict_remote_namespace_e2e/conflict_creation_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright 2019-2021 The Liqo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package conflictremotenamespace tests the conflicting creation of remote namespaces.
116
package conflictremotenamespace
217

318
import (
@@ -24,8 +39,6 @@ const (
2439
clustersRequired = 4
2540
// testNamespaceName is the name of the test namespace for this test.
2641
testNamespaceName = "test-namespace-conflict"
27-
// controllerClientPresence indicates if the test use the controller runtime clients.
28-
controllerClientPresence = true
2942
// testName is the name of this E2E test.
3043
testName = "E2E_CONFLICT_CREATION"
3144
)
@@ -39,7 +52,7 @@ func TestE2E(t *testing.T) {
3952
var _ = Describe("Liqo E2E", func() {
4053
var (
4154
ctx = context.Background()
42-
testContext = tester.GetTester(ctx, clustersRequired, controllerClientPresence)
55+
testContext = tester.GetTester(ctx)
4356
interval = 1 * time.Second
4457
timeout = 10 * time.Second
4558
// longTimeout is used in situations that may take longer to be performed
@@ -137,12 +150,6 @@ var _ = Describe("Liqo E2E", func() {
137150
types.NamespacedName{Name: remoteTestNamespaceName}, namespace))
138151
}, timeout, interval).Should(Equal(metav1.StatusReasonNotFound))
139152
}
140-
141-
// Cleaning the environment after the test.
142-
By(" 3 - Getting the local namespace and delete it")
143-
Eventually(func() error {
144-
return util.EnsureNamespaceDeletion(ctx, testContext.Clusters[localIndex].NativeClient, util.GetNamespaceLabel(true))
145-
}, longTimeout, interval).Should(BeNil())
146153
})
147154
})
148155
})

test/e2e/advanced_e2e/remote_namespaces_creation_e2e/remote_namespaces_creation_test.go renamed to test/e2e/cruise/remote_namespaces_creation_e2e/remote_namespaces_creation_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright 2019-2021 The Liqo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package remotenamespacecreation tests the creation of remote namespaces.
116
package remotenamespacecreation
217

318
import (
@@ -25,8 +40,6 @@ const (
2540
clustersRequired = 4
2641
// testNamespaceName is the name of the test namespace for this test.
2742
testNamespaceName = "test-namespace-creation"
28-
// controllerClientPresence indicates if the test use the controller runtime clients.
29-
controllerClientPresence = true
3043
// testName is the name of this E2E test.
3144
testName = "E2E_REMOTE_NAMESPACE_CREATION"
3245
)
@@ -40,7 +53,7 @@ func TestE2E(t *testing.T) {
4053
var _ = Describe("Liqo E2E", func() {
4154
var (
4255
ctx = context.Background()
43-
testContext = tester.GetTester(ctx, clustersRequired, controllerClientPresence)
56+
testContext = tester.GetTester(ctx)
4457
interval = 1 * time.Second
4558
timeout = 10 * time.Second
4659
// longTimeout is used in situations that may take longer to be performed
@@ -190,12 +203,6 @@ var _ = Describe("Liqo E2E", func() {
190203
types.NamespacedName{Name: remoteTestNamespaceName}, namespace))
191204
}, timeout, interval).Should(Equal(metav1.StatusReasonNotFound))
192205
}
193-
194-
// Cleaning the environment after the test.
195-
By(" 3 - Getting the local namespace and delete it")
196-
Eventually(func() error {
197-
return util.EnsureNamespaceDeletion(ctx, testContext.Clusters[localIndex].NativeClient, util.GetNamespaceLabel(false))
198-
}, longTimeout, interval).Should(BeNil())
199206
})
200207
})
201208
})

0 commit comments

Comments
 (0)