Skip to content

Commit

Permalink
[e2e] Add version anno remove test
Browse files Browse the repository at this point in the history
This commit introduces a test to check WMCO is able to reconfigure
instances when the version annotation gets removed.
  • Loading branch information
jrvaldes committed Sep 27, 2024
1 parent 067496a commit bacee21
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/e2e/reconfigure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,50 @@ package e2e
import (
"context"
"encoding/json"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/openshift/windows-machine-config-operator/pkg/metadata"
"github.com/openshift/windows-machine-config-operator/pkg/patch"
"github.com/openshift/windows-machine-config-operator/pkg/wiparser"
)

func reconfigurationTestSuite(t *testing.T) {
tc, err := NewTestContext()
require.NoError(t, err)
t.Run("Remove version annotation", tc.testRemoveVersionAnnotation)
t.Run("Re-add removed instance", tc.testReAddInstance)
t.Run("Change private key", testPrivateKeyChange)
}

// testRemoveVersionAnnotation tests the case where the version annotation is removed from the node.
func (tc *testContext) testRemoveVersionAnnotation(t *testing.T) {
ctx := context.TODO()
// machines instances
for _, node := range gc.machineNodes {
err := removeVersionAnnotation(tc, ctx, node.Name)
assert.NoError(t, err, "error removing version annotation")

err = tc.waitForConfiguredWindowsNodes(gc.numberOfMachineNodes, true, false)
require.NoError(t, err, "error waiting for the machine instance to become Windows node")
}
// BYOH instances
for _, node := range gc.byohNodes {
err := removeVersionAnnotation(tc, ctx, node.Name)
assert.NoError(t, err, "error removing version annotation")

err = tc.waitForConfiguredWindowsNodes(gc.numberOfBYOHNodes, true, true)
require.NoError(t, err, "error waiting for the BYOH instance to become Windows node")
}
// check nodes are ready and schedulable
tc.testNodesBecomeReadyAndSchedulable(t)
}

// testReAddInstance tests the case where a Windows BYOH instance was removed from the cluster, and then re-added.
func (tc *testContext) testReAddInstance(t *testing.T) {
if gc.numberOfBYOHNodes == 0 {
Expand Down Expand Up @@ -73,3 +100,21 @@ func (tc *testContext) testReAddInstance(t *testing.T) {
require.NoError(t, err, "error waiting for the Windows node to be re-added")
tc.testNodesBecomeReadyAndSchedulable(t)
}

func removeVersionAnnotation(tc *testContext, ctx context.Context, nodeName string) error {
node, err := tc.client.K8s.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
if err != nil {
return err
}
_, found := node.Annotations[metadata.VersionAnnotation]
if !found {
return fmt.Errorf("missing version annotation in node %s", node.Name)
}
delete(node.Annotations, metadata.VersionAnnotation)

_, err = tc.client.K8s.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
if err != nil {
return err
}
return nil
}

0 comments on commit bacee21

Please sign in to comment.