Skip to content

Commit

Permalink
Make kcp and object of reconcoiler struct for different provider unit…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
panktishah26 committed Nov 27, 2023
1 parent 6837010 commit df2b28a
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 122 deletions.
76 changes: 35 additions & 41 deletions pkg/providers/cloudstack/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,7 @@ func TestReconcilerReconcileSuccess(t *testing.T) {
// We want to check that the cluster status is cleaned up if validations are passed
tt.cluster.SetFailure(anywherev1.FailureReasonType("InvalidCluster"), "invalid cluster")

kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = tt.cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", tt.cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
},
ObservedGeneration: 2,
}
})
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.secret, kcp)
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.secret, tt.kcp)
tt.createAllObjs()

logger := test.NewNullLogger()
Expand Down Expand Up @@ -198,27 +178,17 @@ func TestReconcilerControlPlaneIsNotReady(t *testing.T) {

tt := newReconcilerTest(t)

kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = tt.cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", tt.cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.NewTime(time.Now()),
},
tt.kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.NewTime(time.Now()),
},
ObservedGeneration: 2,
}
})
tt.eksaSupportObjs = append(tt.eksaSupportObjs, kcp, tt.secret)
},
ObservedGeneration: 2,
}
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.kcp, tt.secret)
tt.createAllObjs()

logger := test.NewNullLogger()
Expand Down Expand Up @@ -572,6 +542,7 @@ type reconcilerTest struct {
validatorRegistry *cloudstack.MockValidatorRegistry
execConfig *decoder.CloudStackExecConfig
secret *corev1.Secret
kcp *controlplanev1.KubeadmControlPlane
}

func newReconcilerTest(t testing.TB) *reconcilerTest {
Expand Down Expand Up @@ -676,6 +647,28 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {

c.Spec.EksaVersion = &version
})

kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
},
ObservedGeneration: 2,
}
})

secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down Expand Up @@ -717,6 +710,7 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {
validatorRegistry: validatorRegistry,
execConfig: execConfig,
secret: secret,
kcp: kcp,
}

t.Cleanup(tt.cleanup)
Expand Down
74 changes: 34 additions & 40 deletions pkg/providers/snow/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,8 @@ func TestReconcilerReconcileSuccess(t *testing.T) {
tt := newReconcilerTest(t)
// We want to check that the cluster status is cleaned up if validations are passed
tt.cluster.SetFailure(anywherev1.FailureReasonType("InvalidCluster"), "invalid cluster")
kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = tt.cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", tt.cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
},
ObservedGeneration: 2,
}
})
tt.eksaSupportObjs = append(tt.eksaSupportObjs, kcp)

tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.kcp)
tt.createAllObjs()

logger := test.NewNullLogger()
Expand Down Expand Up @@ -249,26 +230,16 @@ func TestReconcilerReconcileControlPlane(t *testing.T) {

func TestReconcilerCheckControlPlaneReadyItIsReady(t *testing.T) {
tt := newReconcilerTest(t)
kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = tt.cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", tt.cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
tt.kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
}
})
tt.eksaSupportObjs = append(tt.eksaSupportObjs, kcp)
},
}
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.kcp)
tt.withFakeClient()

result, err := tt.reconciler().CheckControlPlaneReady(tt.ctx, test.NewNullLogger(), tt.buildSpec())
Expand Down Expand Up @@ -333,6 +304,7 @@ type reconcilerTest struct {
eksaSupportObjs []client.Object
machineConfigControlPlane *anywherev1.SnowMachineConfig
machineConfigWorker *anywherev1.SnowMachineConfig
kcp *controlplanev1.KubeadmControlPlane
}

func newReconcilerTest(t testing.TB) *reconcilerTest {
Expand Down Expand Up @@ -422,6 +394,27 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {
c.Spec.EksaVersion = &version
})

kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
},
ObservedGeneration: 2,
}
})

tt := &reconcilerTest{
t: t,
WithT: NewWithT(t),
Expand All @@ -446,6 +439,7 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {
cluster: cluster,
machineConfigControlPlane: machineConfigCP,
machineConfigWorker: machineConfigWN,
kcp: kcp,
}

t.Cleanup(tt.cleanup)
Expand Down
75 changes: 34 additions & 41 deletions pkg/providers/vsphere/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,7 @@ func TestReconcilerReconcileSuccess(t *testing.T) {
// We want to check that the cluster status is cleaned up if validations are passed
tt.cluster.SetFailure(anywherev1.FailureReasonType("InvalidCluster"), "invalid cluster")

kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = tt.cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", tt.cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
},
ObservedGeneration: 2,
}
})
tt.eksaSupportObjs = append(tt.eksaSupportObjs, kcp)
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.kcp)
tt.createAllObjs()

logger := test.NewNullLogger()
Expand Down Expand Up @@ -189,28 +169,18 @@ func TestReconcilerControlPlaneIsNotReady(t *testing.T) {
t.Skip("Flaky (https://github.com/aws/eks-anywhere/issues/7000)")

tt := newReconcilerTest(t)
kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = tt.cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", tt.cluster.Name),
},
tt.kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.NewTime(time.Now()),
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionFalse,
LastTransitionTime: metav1.NewTime(time.Now()),
},
},
ObservedGeneration: 2,
}
})
},
ObservedGeneration: 2,
}

tt.eksaSupportObjs = append(tt.eksaSupportObjs, kcp)
tt.eksaSupportObjs = append(tt.eksaSupportObjs, tt.kcp)
tt.createAllObjs()

logger := test.NewNullLogger()
Expand Down Expand Up @@ -382,6 +352,7 @@ type reconcilerTest struct {
machineConfigControlPlane *anywherev1.VSphereMachineConfig
machineConfigWorker *anywherev1.VSphereMachineConfig
ipValidator *vspherereconcilermocks.MockIPValidator
kcp *controlplanev1.KubeadmControlPlane
}

func newReconcilerTest(t testing.TB) *reconcilerTest {
Expand Down Expand Up @@ -469,6 +440,27 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {
c.Spec.EksaVersion = &version
})

kcp := test.KubeadmControlPlane(func(kcp *controlplanev1.KubeadmControlPlane) {
kcp.Name = cluster.Name
kcp.Spec = controlplanev1.KubeadmControlPlaneSpec{
MachineTemplate: controlplanev1.KubeadmControlPlaneMachineTemplate{
InfrastructureRef: corev1.ObjectReference{
Name: fmt.Sprintf("%s-control-plane-1", cluster.Name),
},
},
}
kcp.Status = controlplanev1.KubeadmControlPlaneStatus{
Conditions: clusterv1.Conditions{
{
Type: clusterapi.ReadyCondition,
Status: corev1.ConditionTrue,
LastTransitionTime: metav1.NewTime(time.Now()),
},
},
ObservedGeneration: 2,
}
})

tt := &reconcilerTest{
t: t,
WithT: NewWithT(t),
Expand Down Expand Up @@ -497,6 +489,7 @@ func newReconcilerTest(t testing.TB) *reconcilerTest {
datacenterConfig: workloadClusterDatacenter,
machineConfigControlPlane: machineConfigCP,
machineConfigWorker: machineConfigWN,
kcp: kcp,
}

t.Cleanup(tt.cleanup)
Expand Down

0 comments on commit df2b28a

Please sign in to comment.