Skip to content

Commit

Permalink
Some fixes:
Browse files Browse the repository at this point in the history
- EnforceNamespace function now create a namespace with a set of predefined labels passed as parameter.
- EnsureNamespaceDeletion now delete the namespace with a set of predefined labels and check if the namespaces are really deleted.
- Tester is modified in order to support different number of clusters for different tests.
- The tests consts are now in a unique file test/e2e/testconsts/consts.go.
- improved tests stability.
  • Loading branch information
Andreagit97 committed Jul 13, 2021
1 parent 55d8022 commit 43c02e7
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 288 deletions.
81 changes: 43 additions & 38 deletions test/e2e/cluster_labels_e2e/cluster_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
liqoconst "github.com/liqotech/liqo/pkg/consts"
liqoutils "github.com/liqotech/liqo/pkg/utils/foreignCluster"
"github.com/liqotech/liqo/test/e2e/testconsts"
"github.com/liqotech/liqo/test/e2e/testutils/tester"
testutils "github.com/liqotech/liqo/test/e2e/testutils/util"
)
Expand All @@ -32,16 +31,18 @@ func TestE2E(t *testing.T) {
}

const (
// Name of the ClusterConfig in every cluster with Liqo.
// numberOfTestClusters number of clusters used in this E2E test.
numberOfTestClusters = 4
// clusterConfigName is the name of the ClusterConfig in every cluster with Liqo.
clusterConfigName = "liqo-configuration"
// Name of the test namespace for this test with cluster labels.
// testNamespaceName is the name of the test namespace for this test.
testNamespaceName = "test-namespace-labels"
)

var _ = Describe("Liqo E2E", func() {
var (
ctx = context.Background()
testContext = tester.GetTester(ctx)
testContext = tester.GetTester(ctx, numberOfTestClusters)
interval = 1 * time.Second
// shortTimeout is used for Consistently statement
shortTimeout = 5 * time.Second
Expand All @@ -51,7 +52,7 @@ var _ = Describe("Liqo E2E", func() {
localIndex = 0
)

Context("Assert that labels inserted at installation time are in the right resources: clutserConfig,"+
Context("Assert that labels inserted at installation time are in the right resources: clusterConfig,"+
" resourceOffer and virtualNodes", func() {

DescribeTable(" 1 - Check labels presence in the ClusterConfig resources for every cluster",
Expand All @@ -60,7 +61,7 @@ var _ = Describe("Liqo E2E", func() {
clusterConfig := &configv1alpha1.ClusterConfig{}
Eventually(func() error {
return cluster.ControllerClient.Get(ctx, types.NamespacedName{Name: clusterConfigName}, clusterConfig)
}, timeout, interval).Should(Succeed())
}, timeout, interval).Should(BeNil())
Expect(clusterConfig.Spec.DiscoveryConfig.ClusterLabels).To(Equal(clusterLabels))
},
Entry("Check the ClusterConfig resource of the cluster 1", testContext.Clusters[0], testutils.GetClusterLabels(0)),
Expand Down Expand Up @@ -93,7 +94,7 @@ var _ = Describe("Liqo E2E", func() {
Namespace: tenantNamespaceName,
Name: fmt.Sprintf("%s-%s", resourceOfferNamePrefix, cluster.ClusterID),
}, resourceOffer)
}, timeout, interval).Should(Succeed())
}, timeout, interval).Should(BeNil())
Expect(resourceOffer.Spec.Labels).To(Equal(clusterLabels))
}
},
Expand All @@ -117,7 +118,7 @@ var _ = Describe("Liqo E2E", func() {
Eventually(func() error {
return testContext.Clusters[i].ControllerClient.Get(ctx,
types.NamespacedName{Name: virtualNodeName}, virtualNode)
}, timeout, interval).Should(Succeed())
}, timeout, interval).Should(BeNil())
for key, value := range clusterLabels {
Expect(virtualNode.Labels).To(HaveKeyWithValue(key, value))
}
Expand All @@ -132,57 +133,51 @@ var _ = Describe("Liqo E2E", func() {

})

// In this test cases is created a namespace only inside one cluster
// In these test cases it is created a namespace only inside one cluster
Context(fmt.Sprintf("Create a namespace in the cluster '%d' with its NamespaceOffloading and check if the remote namespaces"+
"are created on the right remote cluster according to the ClusterSelector specified in the NamespaceOffloading Spec ", localIndex), func() {

It("Creating the namespace and checks the presence of the remote namespaces", func() {
It("Creating the namespace and checking the presence of the remote namespaces", func() {
By(" 1 - Creating the local namespace without the NamespaceOffloading resource")
Eventually(func() error {
return testutils.CreateNamespaceWithoutNamespaceOffloading(ctx, testContext.Clusters[localIndex].ControllerClient,
testNamespaceName)
}, timeout, interval).Should(Succeed())
_, err := testutils.EnforceNamespace(ctx, testContext.Clusters[localIndex].NativeClient,
testContext.Clusters[localIndex].ClusterID,
testNamespaceName, testutils.GetNamespaceLabel(false))
return err
}, timeout, interval).Should(BeNil())

By(" 2 - Create the NamespaceOffloading resource associated with the previously created namespace")
Eventually(func() error {
return testutils.CreateNamespaceOffloading(ctx, testContext.Clusters[localIndex].ControllerClient, testNamespaceName,
offloadingv1alpha1.EnforceSameNameMappingStrategyType,
offloadingv1alpha1.LocalAndRemotePodOffloadingStrategyType,
testutils.GetClusterSelector())
}, timeout, interval).Should(Succeed())
}, timeout, interval).Should(BeNil())

By(fmt.Sprintf(" 3 - Getting the virtual nodes in the cluster '%d'", localIndex))
virtualNodesList := &corev1.NodeList{}
Eventually(func() error {
return testContext.Clusters[localIndex].ControllerClient.List(ctx, virtualNodesList,
client.MatchingLabels{liqoconst.TypeLabel: liqoconst.TypeNode})
}, timeout, interval).Should(Succeed())
Expect(len(virtualNodesList.Items)).To(Equal(testconsts.NumberOfTestClusters - 1))
}, timeout, interval).Should(BeNil())
Expect(len(virtualNodesList.Items)).To(Equal(numberOfTestClusters - 1))

By(" 4 - Checking the remote clusters on which the remote namespaces are created")
for i := range virtualNodesList.Items {
match, err := k8shelper.MatchNodeSelectorTerms(&virtualNodesList.Items[i], testutils.GetClusterSelector())
Expect(err).To(Succeed())
Expect(err).To(BeNil())
remoteClusterID := virtualNodesList.Items[i].Annotations[liqoconst.RemoteClusterID]
if match {
// Check if the remote namespace is correctly created.
By(fmt.Sprintf(" 5 - Checking if a remote namespace is correctly created inside cluster '%s'", remoteClusterID))
namespace := &corev1.Namespace{}
Eventually(func() error {
namespace := &corev1.Namespace{}
if err = testContext.ClustersClients[remoteClusterID].Get(ctx,
types.NamespacedName{Name: testNamespaceName}, namespace); err != nil {
return err
}
value, ok := namespace.Annotations[liqoconst.RemoteNamespaceAnnotationKey]
if !ok {
return fmt.Errorf("the annotation '%s' is not present", liqoconst.RemoteNamespaceAnnotationKey)
}
if value != testContext.Clusters[localIndex].ClusterID {
return fmt.Errorf("the value of the annotation is not correct: '%s'", value)
}
return nil
}, longTimeout, interval).Should(Succeed())

return testContext.ClustersClients[remoteClusterID].Get(ctx,
types.NamespacedName{Name: testNamespaceName}, namespace)
}, timeout, interval).Should(BeNil())
value, ok := namespace.Annotations[liqoconst.RemoteNamespaceAnnotationKey]
Expect(ok).To(BeTrue())
Expect(value).To(Equal(testContext.Clusters[localIndex].ClusterID))
} else {
// Check if the remote namespace does not exists.
By(fmt.Sprintf(" 5 - Checking that no remote namespace is created inside cluster '%s'", remoteClusterID))
Expand All @@ -197,17 +192,21 @@ var _ = Describe("Liqo E2E", func() {

})

It("Delete the local namespace and check if the remote namespaces are deleted", func() {
By(" 1 - Getting the local namespace and delete it")
namespace := &corev1.Namespace{}
It("Delete the NamespaceOffloading resource in the local namespace "+
"and check if the remote namespaces are deleted", func() {
By(" 1 - Getting the NamespaceOffloading in the local namespace and delete it")
namespaceOffloading := &offloadingv1alpha1.NamespaceOffloading{}
Eventually(func() metav1.StatusReason {
err := testContext.Clusters[localIndex].ControllerClient.Get(ctx, types.NamespacedName{Name: testNamespaceName}, namespace)
_ = testContext.Clusters[localIndex].ControllerClient.Delete(ctx, namespace)
err := testContext.Clusters[localIndex].ControllerClient.Get(ctx,
types.NamespacedName{Name: liqoconst.DefaultNamespaceOffloadingName, Namespace: testNamespaceName},
namespaceOffloading)
_ = testContext.Clusters[localIndex].ControllerClient.Delete(ctx, namespaceOffloading)
return apierrors.ReasonForError(err)
}, longTimeout, interval).Should(Equal(metav1.StatusReasonNotFound))

// When the local namespace is really deleted the remote namespace must be already deleted.
// When the NamespaceOffloading resource is really deleted the remote namespaces must be already deleted.
By(" 2 - Checking that all remote namespaces are deleted")
namespace := &corev1.Namespace{}
for i := range testContext.Clusters {
if i == localIndex {
continue
Expand All @@ -217,6 +216,12 @@ var _ = Describe("Liqo E2E", func() {
types.NamespacedName{Name: testNamespaceName}, namespace))
}, timeout, interval).Should(Equal(metav1.StatusReasonNotFound))
}

// Cleaning the environment after the test.
By(" 3 - Getting the local namespace and delete it")
Eventually(func() error {
return testutils.EnsureNamespaceDeletion(ctx, testContext.Clusters[localIndex].NativeClient, testutils.GetNamespaceLabel(false))
}, timeout, interval).Should(BeNil())
})
})
})
67 changes: 44 additions & 23 deletions test/e2e/conflict_remote_namespace_e2e/conflict_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ func TestE2E(t *testing.T) {
}

const (
// local name of the test namespace.
// numberOfTestClusters number of clusters used in this E2E test.
numberOfTestClusters = 4
// testNamespaceName is the name of the test namespace for this test.
testNamespaceName = "test-namespace-conflict"
)

var _ = Describe("Liqo E2E", func() {
var (
ctx = context.Background()
testContext = tester.GetTester(ctx)
testContext = tester.GetTester(ctx, numberOfTestClusters)
interval = 1 * time.Second
timeout = 10 * time.Second
// longTimeout is used in situations that may take longer to be performed
Expand All @@ -54,13 +56,19 @@ var _ = Describe("Liqo E2E", func() {

By(fmt.Sprintf(" 1 - Creating the remote namespace inside the cluster '%d'", remoteIndex))
Eventually(func() error {
return testutils.CreateNamespaceWithoutNamespaceOffloading(ctx, testContext.Clusters[remoteIndex].ControllerClient, remoteTestNamespaceName)
}, timeout, interval).Should(Succeed())
_, err := testutils.EnforceNamespace(ctx, testContext.Clusters[remoteIndex].NativeClient,
testContext.Clusters[remoteIndex].ClusterID, remoteTestNamespaceName,
testutils.GetNamespaceLabel(false))
return err
}, timeout, interval).Should(BeNil())

By(fmt.Sprintf(" 2 - Creating the local namespace inside the cluster '%d'", localIndex))
Eventually(func() error {
return testutils.CreateNamespaceWithNamespaceOffloading(ctx, testContext.Clusters[localIndex].ControllerClient, testNamespaceName)
}, timeout, interval).Should(Succeed())
_, err := testutils.EnforceNamespace(ctx, testContext.Clusters[localIndex].NativeClient,
testContext.Clusters[localIndex].ClusterID, testNamespaceName,
testutils.GetNamespaceLabel(true))
return err
}, timeout, interval).Should(BeNil())

By(" 3 - Getting the NamespaceOffloading resource")
Eventually(func() error {
Expand All @@ -73,17 +81,21 @@ var _ = Describe("Liqo E2E", func() {
namespaceOffloading.Status.OffloadingPhase)
}
return nil
}, longTimeout, interval).Should(Succeed())
}, longTimeout, interval).Should(BeNil())

// This remote namespace has not the annotation inserted by the NamespaceMap controller,
// it has been created in the STEP 1 without that annotation.
By(fmt.Sprintf(" 4 - Deleting the remote namespace inside the cluster '%d'", remoteIndex))
Eventually(func() metav1.StatusReason {
err := testContext.Clusters[remoteIndex].ControllerClient.Get(ctx,
types.NamespacedName{Name: remoteTestNamespaceName}, namespace)
_ = testContext.Clusters[remoteIndex].ControllerClient.Delete(ctx, namespace)
return apierrors.ReasonForError(err)
}, timeout, interval).Should(Equal(metav1.StatusReasonNotFound))
Eventually(func() error {
if err := testContext.Clusters[remoteIndex].ControllerClient.Get(ctx,
types.NamespacedName{Name: remoteTestNamespaceName}, namespace); err != nil {
return err
}
return testContext.Clusters[remoteIndex].ControllerClient.Delete(ctx, namespace)
}, timeout, interval).Should(BeNil())

By(fmt.Sprintf(" 5 - Checking that the remote namespace inside the cluster '%d' has been recreated", remoteIndex))
By(fmt.Sprintf(" 5 - Checking that the remote namespace with the right "+
"annotation has been created inside the cluster '%d' by the NamespaceMap controller", remoteIndex))
Eventually(func() error {
if err := testContext.Clusters[remoteIndex].ControllerClient.Get(ctx,
types.NamespacedName{Name: remoteTestNamespaceName}, namespace); err != nil {
Expand All @@ -93,30 +105,39 @@ var _ = Describe("Liqo E2E", func() {
return fmt.Errorf("the remote namespace has not the right Liqo annotation")
}
return nil
}, longTimeout, interval).Should(Succeed())

}, longTimeout, interval).Should(BeNil())
})

It("Delete the local namespace and check if the remote namespaces are deleted", func() {
By(" 1 - Getting the local namespace and delete it")
namespace := &corev1.Namespace{}
It("Delete the NamespaceOffloading resource in the local namespace "+
"and check if the remote namespaces are deleted", func() {
By(" 1 - Getting the NamespaceOffloading in the local namespace and delete it")
namespaceOffloading := &offloadingv1alpha1.NamespaceOffloading{}
Eventually(func() metav1.StatusReason {
err := testContext.Clusters[localIndex].ControllerClient.Get(ctx, types.NamespacedName{Name: testNamespaceName}, namespace)
_ = testContext.Clusters[localIndex].ControllerClient.Delete(ctx, namespace)
err := testContext.Clusters[localIndex].ControllerClient.Get(ctx,
types.NamespacedName{Name: liqoconst.DefaultNamespaceOffloadingName, Namespace: testNamespaceName},
namespaceOffloading)
_ = testContext.Clusters[localIndex].ControllerClient.Delete(ctx, namespaceOffloading)
return apierrors.ReasonForError(err)
}, longTimeout, interval).Should(Equal(metav1.StatusReasonNotFound))

// When the local namespace is really deleted the remote namespace must be already deleted.
// When the NamespaceOffloading resource is really deleted the remote namespace must be already deleted.
By(" 2 - Checking that all remote namespaces are deleted")
namespace := &corev1.Namespace{}
for i := range testContext.Clusters {
if i == localIndex {
continue
}
Eventually(func() metav1.StatusReason {
return apierrors.ReasonForError(testContext.Clusters[i].ControllerClient.Get(ctx,
types.NamespacedName{Name: testNamespaceName}, namespace))
types.NamespacedName{Name: remoteTestNamespaceName}, namespace))
}, timeout, interval).Should(Equal(metav1.StatusReasonNotFound))
}

// Cleaning the environment after the test.
By(" 3 - Getting the local namespace and delete it")
Eventually(func() error {
return testutils.EnsureNamespaceDeletion(ctx, testContext.Clusters[localIndex].NativeClient, testutils.GetNamespaceLabel(true))
}, longTimeout, interval).Should(BeNil())
})
})
})
Loading

0 comments on commit 43c02e7

Please sign in to comment.