Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion hack/run-ci-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down
22 changes: 18 additions & 4 deletions test/e2e/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/wmco_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down