Skip to content

Commit

Permalink
Make workload cluster unique per test in reconciler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g-gaston committed Oct 24, 2023
1 parent 5051411 commit fc817e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
13 changes: 7 additions & 6 deletions pkg/providers/cloudstack/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -74,7 +75,7 @@ func TestReconcilerReconcileSuccess(t *testing.T) {
spec := tt.buildSpec()
tt.ipValidator.EXPECT().ValidateControlPlaneIP(tt.ctx, logger, tt.buildSpec()).Return(controller.Result{}, nil)
tt.remoteClientRegistry.EXPECT().GetClient(
tt.ctx, client.ObjectKey{Name: "workload-cluster", Namespace: constants.EksaSystemNamespace},
tt.ctx, client.ObjectKey{Name: tt.cluster.Name, Namespace: constants.EksaSystemNamespace},
).Return(remoteClient, nil).Times(1)

tt.cniReconciler.EXPECT().Reconcile(tt.ctx, logger, remoteClient, spec)
Expand Down Expand Up @@ -358,7 +359,7 @@ func TestReconcileCNISuccess(t *testing.T) {
spec := tt.buildSpec()

tt.remoteClientRegistry.EXPECT().GetClient(
tt.ctx, client.ObjectKey{Name: "workload-cluster", Namespace: "eksa-system"},
tt.ctx, client.ObjectKey{Name: tt.cluster.Name, Namespace: "eksa-system"},
).Return(remoteClient, nil)
tt.cniReconciler.EXPECT().Reconcile(tt.ctx, logger, remoteClient, spec)

Expand All @@ -379,7 +380,7 @@ func TestReconcileCNIErrorClientRegistry(t *testing.T) {
spec := tt.buildSpec()

tt.remoteClientRegistry.EXPECT().GetClient(
tt.ctx, client.ObjectKey{Name: "workload-cluster", Namespace: "eksa-system"},
tt.ctx, client.ObjectKey{Name: tt.cluster.Name, Namespace: "eksa-system"},
).Return(nil, errors.New("building client"))

result, err := tt.reconciler().ReconcileCNI(tt.ctx, logger, spec)
Expand Down Expand Up @@ -631,7 +632,7 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {
})

cluster := cloudstackCluster(func(c *anywherev1.Cluster) {
c.Name = "workload-cluster"
c.Name = strings.ToLower(t.Name())
c.Spec.ManagementCluster = anywherev1.ManagementCluster{
Name: managementCluster.Name,
}
Expand Down Expand Up @@ -725,13 +726,13 @@ func (tt *reconcilerTest) cleanup() {
tt.DeleteAllOfAndWait(tt.ctx, &controlplanev1.KubeadmControlPlane{})
tt.DeleteAndWait(tt.ctx, &cloudstackv1.CloudStackMachineTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: "workload-cluster-etcd-1",
Name: tt.cluster.Name + "-etcd-1",
Namespace: "eksa-system",
},
})
tt.DeleteAndWait(tt.ctx, &etcdv1.EtcdadmCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "workload-cluster-etcd",
Name: tt.cluster.Name + "-etcd",
Namespace: "eksa-system",
},
})
Expand Down
27 changes: 15 additions & 12 deletions pkg/providers/vsphere/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -83,7 +84,7 @@ func TestReconcilerReconcileSuccess(t *testing.T) {
tt.govcClient.EXPECT().ListTags(tt.ctx).Return([]executables.Tag{}, nil)

tt.remoteClientRegistry.EXPECT().GetClient(
tt.ctx, client.ObjectKey{Name: "workload-cluster", Namespace: "eksa-system"},
tt.ctx, client.ObjectKey{Name: tt.cluster.Name, Namespace: "eksa-system"},
).Return(remoteClient, nil).Times(1)
tt.cniReconciler.EXPECT().Reconcile(tt.ctx, logger, remoteClient, tt.buildSpec())

Expand Down Expand Up @@ -227,7 +228,9 @@ func TestReconcilerControlPlaneIsNotReady(t *testing.T) {

func TestReconcilerReconcileWorkersSuccess(t *testing.T) {
tt := newReconcilerTest(t)
tt.eksaSupportObjs = append(tt.eksaSupportObjs)
tt.eksaSupportObjs = append(tt.eksaSupportObjs, test.CAPICluster(func(c *clusterv1.Cluster) {
c.Name = tt.cluster.Name
}))
tt.createAllObjs()

result, err := tt.reconciler().ReconcileWorkers(tt.ctx, test.NewNullLogger(), tt.buildSpec())
Expand Down Expand Up @@ -277,7 +280,7 @@ func TestReconcileCNISuccess(t *testing.T) {
spec := tt.buildSpec()

tt.remoteClientRegistry.EXPECT().GetClient(
tt.ctx, client.ObjectKey{Name: "workload-cluster", Namespace: "eksa-system"},
tt.ctx, client.ObjectKey{Name: tt.cluster.Name, Namespace: "eksa-system"},
).Return(remoteClient, nil)
tt.cniReconciler.EXPECT().Reconcile(tt.ctx, logger, remoteClient, spec)

Expand All @@ -297,7 +300,7 @@ func TestReconcileCNIErrorClientRegistry(t *testing.T) {
spec := tt.buildSpec()

tt.remoteClientRegistry.EXPECT().GetClient(
tt.ctx, client.ObjectKey{Name: "workload-cluster", Namespace: "eksa-system"},
tt.ctx, client.ObjectKey{Name: tt.cluster.Name, Namespace: "eksa-system"},
).Return(nil, errors.New("building client"))

result, err := tt.reconciler().ReconcileCNI(tt.ctx, logger, spec)
Expand All @@ -322,7 +325,7 @@ func TestReconcilerReconcileControlPlaneSuccess(t *testing.T) {
tt.ShouldEventuallyExist(tt.ctx,
&addonsv1.ClusterResourceSet{
ObjectMeta: metav1.ObjectMeta{
Name: "workload-cluster-cpi",
Name: tt.cluster.Name + "-cpi",
Namespace: "eksa-system",
},
},
Expand All @@ -331,7 +334,7 @@ func TestReconcilerReconcileControlPlaneSuccess(t *testing.T) {
tt.ShouldEventuallyExist(tt.ctx,
&controlplanev1.KubeadmControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "workload-cluster",
Name: tt.cluster.Name,
Namespace: "eksa-system",
},
},
Expand All @@ -340,20 +343,20 @@ func TestReconcilerReconcileControlPlaneSuccess(t *testing.T) {
tt.ShouldEventuallyExist(tt.ctx,
&vspherev1.VSphereMachineTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: "workload-cluster-control-plane-1",
Name: tt.cluster.Name + "-control-plane-1",
Namespace: "eksa-system",
},
},
)

capiCluster := test.CAPICluster(func(c *clusterv1.Cluster) {
c.Name = "workload-cluster"
c.Name = tt.cluster.Name
})
tt.ShouldEventuallyExist(tt.ctx, capiCluster)

tt.ShouldEventuallyExist(tt.ctx, &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "workload-cluster-cloud-controller-manager", Namespace: "eksa-system"}})
tt.ShouldEventuallyExist(tt.ctx, &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "workload-cluster-cloud-provider-vsphere-credentials", Namespace: "eksa-system"}})
tt.ShouldEventuallyExist(tt.ctx, &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "workload-cluster-cpi-manifests", Namespace: "eksa-system"}})
tt.ShouldEventuallyExist(tt.ctx, &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: tt.cluster.Name + "-cloud-controller-manager", Namespace: "eksa-system"}})
tt.ShouldEventuallyExist(tt.ctx, &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: tt.cluster.Name + "-cloud-provider-vsphere-credentials", Namespace: "eksa-system"}})
tt.ShouldEventuallyExist(tt.ctx, &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: tt.cluster.Name + "-cpi-manifests", Namespace: "eksa-system"}})
}

type reconcilerTest struct {
Expand Down Expand Up @@ -422,7 +425,7 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {
})

cluster := test.Cluster(func(c *anywherev1.Cluster) {
c.Name = "workload-cluster"
c.Name = strings.ToLower(t.Name())
c.Namespace = clusterNamespace
c.Spec.ManagementCluster = anywherev1.ManagementCluster{
Name: managementCluster.Name,
Expand Down

0 comments on commit fc817e0

Please sign in to comment.