diff --git a/hack/run-ci-e2e-test.sh b/hack/run-ci-e2e-test.sh index 933fdfff5d..8b6560c8ca 100755 --- a/hack/run-ci-e2e-test.sh +++ b/hack/run-ci-e2e-test.sh @@ -120,11 +120,15 @@ go test ./test/e2e/... -run=TestWMCO/operator_deployed_without_private_key_secre # Run the creation tests of the Windows VMs printf "\n####### Testing creation #######\n" >> "$ARTIFACT_DIR"/wmco.log -go test ./test/e2e/... -run=TestWMCO/create -v -timeout=120m -args --node-count=$NODE_COUNT --private-key-path=$KUBE_SSH_KEY_PATH $WMCO_PATH_OPTION +go test ./test/e2e/... -run=TestWMCO/create -v -timeout=90m -args --node-count=$NODE_COUNT --private-key-path=$KUBE_SSH_KEY_PATH $WMCO_PATH_OPTION # Get logs for the creation tests printf "\n####### WMCO logs for creation tests #######\n" >> "$ARTIFACT_DIR"/wmco.log get_WMCO_logs +# Run the network tests +printf "\n####### Testing network #######\n" >> "$ARTIFACT_DIR"/wmco.log +go test ./test/e2e/... -run=TestWMCO/network -v -timeout=20m -args --node-count=$NODE_COUNT --private-key-path=$KUBE_SSH_KEY_PATH $WMCO_PATH_OPTION + # Run the upgrade tests and skip deletion of the Windows VMs printf "\n####### Testing upgrade #######\n" >> "$ARTIFACT_DIR"/wmco.log go test ./test/e2e/... -run=TestWMCO/upgrade -v -timeout=90m -args --node-count=$NODE_COUNT --private-key-path=$KUBE_SSH_KEY_PATH $WMCO_PATH_OPTION diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index e45af275cf..ca8f30d719 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -23,17 +23,12 @@ import ( ) func creationTestSuite(t *testing.T) { - // The order of tests here are important. testValidateSecrets is what populates the windowsVMs slice in the gc. - // testNetwork needs that to check if the HNS networks have been installed. Ideally we would like to run testNetwork - // before testValidateSecrets and testConfigMapValidation but we cannot as the source of truth for the credentials - // are the secrets but they are created only after the VMs have been fully configured. - // Any node object related tests should be run only after testNodeCreation as that initializes the node objects in - // the global context. + // The order of tests here are important. Any node object related tests should be run only after + // testWindowsNodeCreation as that initializes the node objects in the global context. if !t.Run("Creation", func(t *testing.T) { testWindowsNodeCreation(t) }) { // No point in running the other tests if creation failed return } - t.Run("Network validation", testNetwork) t.Run("Node Metadata", func(t *testing.T) { testNodeMetadata(t) }) t.Run("NodeTaint validation", func(t *testing.T) { testNodeTaint(t) }) t.Run("UserData validation", func(t *testing.T) { testUserData(t) }) diff --git a/test/e2e/network_test.go b/test/e2e/network_test.go index 1c899b78c8..c36065d825 100644 --- a/test/e2e/network_test.go +++ b/test/e2e/network_test.go @@ -15,6 +15,7 @@ import ( appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" v1 "k8s.io/api/core/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -23,9 +24,12 @@ import ( // testNetwork runs all the cluster and node network tests func testNetwork(t *testing.T) { + // Populate the global test context testCtx, err := NewTestContext() require.NoError(t, err) - require.NoError(t, testCtx.createNamespace(testCtx.workloadNamespace), "error creating test namespace") + err = testCtx.waitForWindowsNodes(gc.numberOfNodes, true, false, false) + assert.NoError(t, err, "timed out waiting for Windows node") + t.Run("East West Networking", testEastWestNetworking) t.Run("North south networking", testNorthSouthNetworking) } @@ -282,14 +286,24 @@ func getAffinityForNode(node *v1.Node) (*v1.Affinity, error) { }, nil } -// createNamespace creates a namespace with the provided name -func (tc *testContext) createNamespace(name string) error { +// ensureNamespace checks if a namespace with the provided name exists and creates one if it does not +func (tc *testContext) ensureNamespace(name string) error { + // Check if the namespace exists + _, err := tc.client.K8s.CoreV1().Namespaces().Get(context.TODO(), name, metav1.GetOptions{}) + if err != nil && !apierrors.IsNotFound(err) { + return err + } + if err == nil { + return nil + } + + // The namespace does not exists, so lets create it ns := &v1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, } - _, err := tc.client.K8s.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) + _, err = tc.client.K8s.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) return err } diff --git a/test/e2e/wmco_test.go b/test/e2e/wmco_test.go index 9f23a8bdcd..b3c4694a50 100644 --- a/test/e2e/wmco_test.go +++ b/test/e2e/wmco_test.go @@ -31,10 +31,15 @@ func TestWMCO(t *testing.T) { wmcoPath = "/usr/local/bin/windows-machine-config-operator" } + testCtx, err := NewTestContext() + require.NoError(t, err) + require.NoError(t, testCtx.ensureNamespace(testCtx.workloadNamespace), "error creating test namespace") + // test that the operator can deploy without the secret already created, we can later use a secret created by the // individual test suites after the operator is running t.Run("operator deployed without private key secret", testOperatorDeployed) t.Run("create", creationTestSuite) + t.Run("network", testNetwork) t.Run("upgrade", upgradeTestSuite) t.Run("reconfigure", reconfigurationTest) t.Run("destroy", deletionTestSuite)