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 548c371 commit 5680e40
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/e2e/reconfigure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,51 @@ package e2e
import (
"context"
"encoding/json"
"fmt"
"log"
"testing"

"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()
require.NoError(t, tc.loadExistingNodes(), "error getting the current Windows nodes in the cluster")
// machines instances
for _, node := range gc.machineNodes {
err := removeVersionAnnotation(tc, ctx, node.Name)
require.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)
require.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 +101,16 @@ 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 {
log.Printf("removing version annotation from node: %s", nodeName)
patchData, err := metadata.GenerateRemovePatch([]string{}, []string{metadata.VersionAnnotation})
if err != nil {
return fmt.Errorf("error creating version annotation remove request: %w", err)
}
_, err = tc.client.K8s.CoreV1().Nodes().Patch(ctx, nodeName, types.JSONPatchType, patchData, metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("error removing version annotation from node %s: %w", nodeName, err)
}
return nil
}

0 comments on commit 5680e40

Please sign in to comment.