diff --git a/test/e2e/reconfigure_test.go b/test/e2e/reconfigure_test.go index 5efe319362..d5f2547f21 100644 --- a/test/e2e/reconfigure_test.go +++ b/test/e2e/reconfigure_test.go @@ -3,12 +3,15 @@ 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" ) @@ -16,10 +19,35 @@ import ( 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 { @@ -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 +}