Skip to content

Commit

Permalink
Add another test to simulate node state fixed within timeout period o…
Browse files Browse the repository at this point in the history
…f Pending phase
  • Loading branch information
vincentportella committed Aug 19, 2024
1 parent ac3fff0 commit ccc6ae5
Showing 1 changed file with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestPendingNoKubeNodes(t *testing.T) {

// Test to ensure that Cyclops will not proceed if there is node detached from
// the nodegroup on the cloud provider. It should try to wait for the issue to
// resolve transition to the Healing phase if it doesn't.
// resolve to transition to the Healing phase if it doesn't.
func TestPendingDetachedCloudProviderNode(t *testing.T) {
nodegroup, err := mock.NewNodegroup("ng-1", 2)
if err != nil {
Expand Down Expand Up @@ -348,11 +348,79 @@ func TestPendingDetachedCloudProviderNode(t *testing.T) {
assert.Equal(t, v1.CycleNodeRequestHealing, cnr.Status.Phase)
}

// Test to ensure that Cyclops will not proceed if there is node detached from
// the nodegroup on the cloud provider. It should try to wait for the issue to
// resolve and transition to Initialised when it does before reaching the
// timeout period.
func TestPendingReattachedCloudProviderNode(t *testing.T) {
nodegroup, err := mock.NewNodegroup("ng-1", 2)
if err != nil {
assert.NoError(t, err)
}

// "detach" one instance from the asg
nodegroup[0].Nodegroup = ""

cnr := &v1.CycleNodeRequest{
ObjectMeta: metav1.ObjectMeta{
Name: "cnr-1",
Namespace: "kube-system",
},
Spec: v1.CycleNodeRequestSpec{
NodeGroupsList: []string{"ng-1"},
CycleSettings: v1.CycleSettings{
Concurrency: 1,
Method: v1.CycleNodeRequestMethodDrain,
},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"customer": "kitt",
},
},
},
Status: v1.CycleNodeRequestStatus{
Phase: v1.CycleNodeRequestPending,
},
}

fakeTransitioner := NewFakeTransitioner(cnr,
WithKubeNodes(nodegroup),
WithCloudProviderInstances(nodegroup),
)

// Should requeue while it tries to wait
_, err = fakeTransitioner.Run()
assert.NoError(t, err)
assert.Equal(t, v1.CycleNodeRequestPending, cnr.Status.Phase)

// Simulate waiting for 1s less than the wait limit
cnr.Status.EquilibriumWaitStarted = &metav1.Time{
Time: time.Now().Add(-nodeEquilibriumWaitLimit + time.Second),
}

_, err = fakeTransitioner.Autoscaling.AttachInstances(&autoscaling.AttachInstancesInput{
AutoScalingGroupName: aws.String("ng-1"),
InstanceIds: aws.StringSlice([]string{nodegroup[0].InstanceID}),
})

assert.NoError(t, err)

// "re-attach" the instance to the asg
fakeTransitioner.cloudProviderInstances[0].Nodegroup = "ng-1"

// The CNR should transition to the Initialised phase because the state of
// the nodes is now correct and this happened within the timeout period.
_, err = fakeTransitioner.Run()
assert.NoError(t, err)
assert.Equal(t, v1.CycleNodeRequestInitialised, cnr.Status.Phase)
assert.Len(t, cnr.Status.NodesToTerminate, 2)
}

// Test to ensure that Cyclops will not proceed if there is node detached from
// the nodegroup on the cloud provider. It should wait and especially should not
// succeed if the instance is re-attached by the final requeuing of the Pending
// phase which would occur after the timeout period.
func TestPendingReattachedCloudProviderNode(t *testing.T) {
func TestPendingReattachedCloudProviderNodeTooLate(t *testing.T) {
nodegroup, err := mock.NewNodegroup("ng-1", 2)
if err != nil {
assert.NoError(t, err)
Expand Down

0 comments on commit ccc6ae5

Please sign in to comment.