Skip to content

Commit

Permalink
[e2e] Add support for platform=none
Browse files Browse the repository at this point in the history
- Add platform=none as new cloud provider in WMCO e2e test suite
- Add a check in ConfigMap controller test to avoid the creation of
  Windows instances via machineSet for platform-agnostic infrastructure
- Introduce a function to validate windows-instances ConfigMap
- Add a new step in run-ci-e2e-test.sh script to create the windows-instances
  configMap once the operator deployment process is complete.
- Add a new Makefile target to test BYOH in platform=none, where the number of
  Windows instances created by MachineSet is fixed to 0.
  • Loading branch information
jrvaldes committed Jan 27, 2022
1 parent ec22cc4 commit c1fb113
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ unit:
run-ci-e2e-test:
hack/run-ci-e2e-test.sh -t basic

.PHONY: run-ci-e2e-byoh-test
run-ci-e2e-byoh-test:
hack/run-ci-e2e-test.sh -t basic -m 0

.PHONY: run-ci-e2e-upgrade-test
run-ci-e2e-upgrade-test:
hack/run-ci-e2e-test.sh -t upgrade
Expand Down
26 changes: 26 additions & 0 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,29 @@ transform_csv() {
fi
sed -i "s|"$1"|"$2"|g" $MANIFEST_LOC/manifests/windows-machine-config-operator.clusterserviceversion.yaml
}

# creates the `windows-instances` ConfigMap
# Parameters:
# 1: the ConfigMap data section
createWindowsInstancesConfigMap() {
DATA=$1
if [[ -z "$DATA" ]]; then
error-exit "ConfigMap data cannot be empty"
fi
cat <<EOF | oc apply -f -
kind: ConfigMap
apiVersion: v1
metadata:
name: windows-instances
namespace: ${WMCO_DEPLOY_NAMESPACE}
${DATA}
EOF
}

# returns the number of instances from `windows-instances` ConfigMap
getWindowsInstanceCountFromConfigMap() {
oc get configmaps \
windows-instances \
-n "${WMCO_DEPLOY_NAMESPACE}" \
-o json | jq '.data | length'
}
19 changes: 19 additions & 0 deletions hack/run-ci-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ if ! [[ "$OPENSHIFT_CI" = "true" && "$TEST" = "upgrade" ]]; then
done
fi

# WINDOWS_INSTANCES_DATA holds the windows-instances ConfigMap data section
WINDOWS_INSTANCES_DATA=${WINDOWS_INSTANCES_DATA:-}
# Check WINDOWS_INSTANCES_DATA and create the windows-instances ConfigMap, if
# any. The ConfigMap creation must takes place after the operator's deployment
# process is complete, because the namespace is removed as part of the cleanup
# step (cleanup_WMCO) while retrying the deployment.
if [[ -n "$WINDOWS_INSTANCES_DATA" ]]; then
createWindowsInstancesConfigMap "${WINDOWS_INSTANCES_DATA}" || {
error-exit "error creating windows-instances ConfigMap with ${WINDOWS_INSTANCES_DATA}"
}
# read BYOH from ConfigMap
BYOH_NODE_COUNT=$(getWindowsInstanceCountFromConfigMap) || {
error-exit "error getting windows-instances ConfigMap"
}
# update BYOH node count option or default to 0
BYOH_NODE_COUNT_OPTION="--byoh-node-count=${BYOH_NODE_COUNT:-0}"
echo "updated ${BYOH_NODE_COUNT_OPTION}"
fi

# The bool flags in golang does not respect key value pattern. They follow -flag=x pattern.
# -flag x is allowed for non-boolean flags only(https://golang.org/pkg/flag/)

Expand Down
39 changes: 32 additions & 7 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ func (tc *testContext) createWindowsInstanceConfigMap(machines *mapi.MachineList
return nil
}

// validateWindowsInstanceConfigMap validates the windows-instance ConfigMap
func (tc *testContext) validateWindowsInstanceConfigMap(expectedCount int) error {
windowsInstances, err := tc.client.K8s.CoreV1().ConfigMaps(tc.namespace).Get(context.TODO(),
wiparser.InstanceConfigMap, metav1.GetOptions{})
if err != nil {
return errors.Wrapf(err, "error retrieving ConfigMap: %s", wiparser.InstanceConfigMap)
}
// check instance count
actualCount := len(windowsInstances.Data)
if actualCount != expectedCount {
return errors.Wrapf(err, "invalid BYOH instance count: %v, expected: %v", actualCount, expectedCount)
}
// TODO: Validate windowsInstances.Data (See https://issues.redhat.com/browse/WINC-671)
// ConfigMap is valid, return no error
return nil
}

// testMachineConfiguration tests that the Windows Machine controller can properly configure Machines
func (tc *testContext) testMachineConfiguration(t *testing.T) {
if gc.numberOfMachineNodes == 0 {
Expand Down Expand Up @@ -139,14 +156,22 @@ func (tc *testContext) testBYOHConfiguration(t *testing.T) {
t.Skip("BYOH testing disabled")
}

err := tc.disableClusterMachineApprover()
require.NoError(t, err, "failed to scale down Machine Approver pods")

err = tc.provisionBYOHConfigMapWithMachineSet()
require.NoError(t, err, "error provisioning BYOH ConfigMap with MachineSets")

// For platform-agnostic infrastructure just validate the BYOH ConfigMap
// TODO: See https://github.com/openshift/windows-machine-config-operator/pull/858#discussion_r780316359
if tc.CloudProvider.GetType() == config.NonePlatformType {
err := tc.validateWindowsInstanceConfigMap(int(gc.numberOfBYOHNodes))
require.NoError(t, err, "error validating windows-instances ConfigMap")
log.Printf("using %v BYOH instance(s) already provisioned", gc.numberOfBYOHNodes)
} else {
// Otherwise, provision BYOH instances with MachineSet
err := tc.disableClusterMachineApprover()
require.NoError(t, err, "failed to scale down Machine Approver pods")
err = tc.provisionBYOHConfigMapWithMachineSet()
require.NoError(t, err, "error provisioning BYOH ConfigMap with MachineSets")
}
// Wait for Windows worker node to become available
t.Run("VM is configured by ConfigMap controller", func(t *testing.T) {
err = tc.waitForWindowsNodes(gc.numberOfBYOHNodes, false, false, true)
err := tc.waitForWindowsNodes(gc.numberOfBYOHNodes, false, false, true)
assert.NoError(t, err, "Windows node creation failed")
})
}
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/providers/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
oc "github.com/openshift/windows-machine-config-operator/test/e2e/clusterinfo"
awsProvider "github.com/openshift/windows-machine-config-operator/test/e2e/providers/aws"
azureProvider "github.com/openshift/windows-machine-config-operator/test/e2e/providers/azure"
noneProvider "github.com/openshift/windows-machine-config-operator/test/e2e/providers/none"
vSphereProvider "github.com/openshift/windows-machine-config-operator/test/e2e/providers/vsphere"
)

Expand Down Expand Up @@ -37,6 +38,8 @@ func NewCloudProvider(hasCustomVXLANPort bool) (CloudProvider, error) {
return azureProvider.New(openshift, hasCustomVXLANPort)
case config.VSpherePlatformType:
return vSphereProvider.New(openshift)
case config.NonePlatformType:
return noneProvider.New(openshift)
default:
return nil, fmt.Errorf("the '%v' cloud provider is not supported", provider)
}
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/providers/none/none.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package none

import (
"github.com/pkg/errors"

config "github.com/openshift/api/config/v1"
mapi "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/windows-machine-config-operator/test/e2e/clusterinfo"
)

// Provider is a provider struct for testing platform=none
type Provider struct {
oc *clusterinfo.OpenShift
}

// New returns a Provider implementation for platform=none
func New(clientset *clusterinfo.OpenShift) (*Provider, error) {
return &Provider{
oc: clientset,
}, nil
}

// GenerateMachineSet is not supported for platform=none and throws an exception
func (p *Provider) GenerateMachineSet(withWindowsLabel bool, replicas int32) (*mapi.MachineSet, error) {
return nil, errors.New("MachineSet generation not supported for platform=none")
}

// GetType returns the platform type for platform=none
func (p *Provider) GetType() config.PlatformType {
return config.NonePlatformType
}

0 comments on commit c1fb113

Please sign in to comment.