Skip to content

Commit

Permalink
Add reconcile state test
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Sep 6, 2023
1 parent ec92242 commit c4154d1
Showing 1 changed file with 152 additions and 2 deletions.
154 changes: 152 additions & 2 deletions internal/controllers/topology/cluster/reconcile_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,44 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) {
wantHookToBeCalled: false,
wantError: false,
},
{
name: "hook should not be called if the control plane is stable at desired version but MPs are upgrading - hook is marked",
s: &scope.Scope{
Blueprint: &scope.ClusterBlueprint{
Topology: &clusterv1.Topology{
ControlPlane: clusterv1.ControlPlaneTopology{
Replicas: pointer.Int32(2),
},
},
},
Current: &scope.ClusterState{
Cluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: "test-ns",
Annotations: map[string]string{
runtimev1.PendingHooksAnnotation: "AfterClusterUpgrade",
},
},
Spec: clusterv1.ClusterSpec{},
},
ControlPlane: &scope.ControlPlaneState{
Object: controlPlaneObj,
},
},
HookResponseTracker: scope.NewHookResponseTracker(),
UpgradeTracker: func() *scope.UpgradeTracker {
ut := scope.NewUpgradeTracker()
ut.ControlPlane.IsPendingUpgrade = false
ut.MachinePools.MarkUpgrading("mp1")
return ut
}(),
},
wantMarked: true,
hookResponse: successResponse,
wantHookToBeCalled: false,
wantError: false,
},
{
name: "hook should not be called if the control plane is stable at desired version but MDs are pending create - hook is marked",
s: &scope.Scope{
Expand Down Expand Up @@ -759,6 +797,43 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) {
wantHookToBeCalled: false,
wantError: false,
},
{
name: "hook should not be called if the control plane is stable at desired version but MPs are pending create - hook is marked",
s: &scope.Scope{
Blueprint: &scope.ClusterBlueprint{
Topology: &clusterv1.Topology{
ControlPlane: clusterv1.ControlPlaneTopology{
Replicas: pointer.Int32(2),
},
},
},
Current: &scope.ClusterState{
Cluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: "test-ns",
Annotations: map[string]string{
runtimev1.PendingHooksAnnotation: "AfterClusterUpgrade",
},
},
Spec: clusterv1.ClusterSpec{},
},
ControlPlane: &scope.ControlPlaneState{
Object: controlPlaneObj,
}},
HookResponseTracker: scope.NewHookResponseTracker(),
UpgradeTracker: func() *scope.UpgradeTracker {
ut := scope.NewUpgradeTracker()
ut.ControlPlane.IsPendingUpgrade = false
ut.MachinePools.MarkPendingCreate("mp-topology-1")
return ut
}(),
},
wantMarked: true,
hookResponse: successResponse,
wantHookToBeCalled: false,
wantError: false,
},
{
name: "hook should not be called if the control plane is stable at desired version but MDs are pending upgrade - hook is marked",
s: &scope.Scope{
Expand Down Expand Up @@ -796,6 +871,43 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) {
wantHookToBeCalled: false,
wantError: false,
},
{
name: "hook should not be called if the control plane is stable at desired version but MPs are pending upgrade - hook is marked",
s: &scope.Scope{
Blueprint: &scope.ClusterBlueprint{
Topology: &clusterv1.Topology{
ControlPlane: clusterv1.ControlPlaneTopology{
Replicas: pointer.Int32(2),
},
},
},
Current: &scope.ClusterState{
Cluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: "test-ns",
Annotations: map[string]string{
runtimev1.PendingHooksAnnotation: "AfterClusterUpgrade",
},
},
Spec: clusterv1.ClusterSpec{},
},
ControlPlane: &scope.ControlPlaneState{
Object: controlPlaneObj,
}},
HookResponseTracker: scope.NewHookResponseTracker(),
UpgradeTracker: func() *scope.UpgradeTracker {
ut := scope.NewUpgradeTracker()
ut.ControlPlane.IsPendingUpgrade = false
ut.MachinePools.MarkPendingUpgrade("mp1")
return ut
}(),
},
wantMarked: true,
hookResponse: successResponse,
wantHookToBeCalled: false,
wantError: false,
},
{
name: "hook should not be called if the control plane is stable at desired version but MDs upgrade is deferred - hook is marked",
s: &scope.Scope{
Expand Down Expand Up @@ -835,7 +947,45 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) {
wantError: false,
},
{
name: "hook should be called if the control plane and MDs are stable at the topology version - success response should unmark the hook",
name: "hook should not be called if the control plane is stable at desired version but MPs upgrade is deferred - hook is marked",
s: &scope.Scope{
Blueprint: &scope.ClusterBlueprint{
Topology: &clusterv1.Topology{
ControlPlane: clusterv1.ControlPlaneTopology{
Replicas: pointer.Int32(2),
},
},
},
Current: &scope.ClusterState{
Cluster: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
Namespace: "test-ns",
Annotations: map[string]string{
runtimev1.PendingHooksAnnotation: "AfterClusterUpgrade",
},
},
Spec: clusterv1.ClusterSpec{},
},
ControlPlane: &scope.ControlPlaneState{
Object: controlPlaneObj,
},
},
HookResponseTracker: scope.NewHookResponseTracker(),
UpgradeTracker: func() *scope.UpgradeTracker {
ut := scope.NewUpgradeTracker()
ut.ControlPlane.IsPendingUpgrade = false
ut.MachinePools.MarkDeferredUpgrade("mp1")
return ut
}(),
},
wantMarked: true,
hookResponse: successResponse,
wantHookToBeCalled: false,
wantError: false,
},
{
name: "hook should be called if the control plane, MDs, and MPs are stable at the topology version - success response should unmark the hook",
s: &scope.Scope{
Blueprint: &scope.ClusterBlueprint{
Topology: &clusterv1.Topology{
Expand Down Expand Up @@ -872,7 +1022,7 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) {
wantError: false,
},
{
name: "hook should be called if the control plane and MDs are stable at the topology version - failure response should leave the hook marked",
name: "hook should be called if the control plane, MDs, and MPs are stable at the topology version - failure response should leave the hook marked",
s: &scope.Scope{
Blueprint: &scope.ClusterBlueprint{
Topology: &clusterv1.Topology{
Expand Down

0 comments on commit c4154d1

Please sign in to comment.