Skip to content

Commit

Permalink
Add md_remediation test
Browse files Browse the repository at this point in the history
  • Loading branch information
mboukhalfa committed Apr 9, 2024
1 parent 6b4eb53 commit fa8553c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ cluster-templates: $(KUSTOMIZE) ## Generate cluster templates
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-ubuntu > $(E2E_OUT_DIR)/cluster-template-ubuntu.yaml
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-centos > $(E2E_OUT_DIR)/cluster-template-centos.yaml
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-upgrade-workload > $(E2E_OUT_DIR)/cluster-template-upgrade-workload.yaml
$(KUSTOMIZE) build $(E2E_TEMPLATES_DIR)/cluster-template-md-remediation > $(E2E_OUT_DIR)/cluster-template-md-remediation.yaml

## --------------------------------------
## E2E Testing
Expand All @@ -194,7 +195,7 @@ e2e-tests: $(GINKGO) e2e-substitutions cluster-templates # This target should be
--show-node-events --no-color=$(GINKGO_NOCOLOR) \
--fail-fast="$(KEEP_TEST_ENV)" \
--junit-report="junit.e2e_suite.1.xml" \
--focus="$(GINKGO_FOCUS)" $(_SKIP_ARGS) "$(ROOT_DIR)/$(TEST_DIR)/e2e/" -- \
--focus="healthcheck" $(_SKIP_ARGS) "$(ROOT_DIR)/$(TEST_DIR)/e2e/" -- \
-e2e.artifacts-folder="$(ARTIFACTS)" \
-e2e.config="$(E2E_CONF_FILE_ENVSUBST)" \
-e2e.skip-resource-cleanup=$(SKIP_CLEANUP) \
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/config/e2e_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ providers:
targetName: "cluster-template-ubuntu.yaml"
- sourcePath: "../_out/cluster-template-centos.yaml"
targetName: "cluster-template-centos.yaml"
- sourcePath: "../_out/cluster-template-md-remediation.yaml"
targetName: "cluster-template-md-remediation.yaml"

variables:
CNI: "/tmp/calico.yaml"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resources:
- ../bases/ippool
- ../bases/centos-kubeadm-config

- mhc.yaml
patchesStrategicMerge:
- md.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: cluster.x-k8s.io/${CAPI_VERSION}
kind: MachineDeployment
metadata:
labels:
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
nodepool: nodepool-0
name: ${CLUSTER_NAME}
namespace: ${NAMESPACE}
spec:
template:
metadata:
labels:
"e2e.remediation.label": ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# MachineHealthCheck object with
# - a selector that targets all the machines with label e2e.remediation.label=""
# - unhealthyConditions triggering remediation after 10s the condition is set
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineHealthCheck
metadata:
name: "${CLUSTER_NAME}-mhc-0"
namespace: ${NAMESPACE}
spec:
clusterName: "${CLUSTER_NAME}"
maxUnhealthy: 100%
selector:
matchLabels:
e2e.remediation.label: ""
unhealthyConditions:
- type: e2e.remediation.condition
status: "False"
timeout: 10s
30 changes: 30 additions & 0 deletions test/e2e/md_remediations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package e2e

import (
"os"
"path/filepath"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
capi_e2e "sigs.k8s.io/cluster-api/test/e2e"
)

var _ = Describe("When testing MachineDeployment remediation [healthcheck] [remediation] [features]", func() {
BeforeEach(func() {
osType := strings.ToLower(os.Getenv("OS"))
Expect(osType).ToNot(Equal(""))
validateGlobals(specName)
// We need to override clusterctl apply log folder to avoid getting our credentials exposed.
clusterctlLogFolder = filepath.Join(os.TempDir(), "clusters", bootstrapClusterProxy.GetName())
})
capi_e2e.MachineDeploymentRemediationSpec(ctx, func() capi_e2e.MachineDeploymentRemediationSpecInput {
return capi_e2e.MachineDeploymentRemediationSpecInput{
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
}
})
})

0 comments on commit fa8553c

Please sign in to comment.