Skip to content

Commit 0067888

Browse files
committed
Enhance destroy machine test to use machine health check
Remove remediation tests because destroy machine is superset
1 parent 2b85d81 commit 0067888

File tree

14 files changed

+81
-286
lines changed

14 files changed

+81
-286
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ e2e-essentials: bin/ginkgo e2e-cluster-templates kind-cluster ## Fulfill essenti
214214
JOB ?= .*
215215
run-e2e: e2e-essentials ## Run e2e testing. JOB is an optional REGEXP to select certainn test cases to run. e.g. JOB=PR-Blocking, JOB=Conformance
216216
cd test/e2e && \
217-
ginkgo -v -trace -tags=e2e -focus=$(JOB) -nodes=1 --noColor=false ./... -- \
217+
ginkgo -v -trace -tags=e2e -focus=$(JOB) -skip=Conformance -nodes=1 --noColor=false ./... -- \
218218
-e2e.artifacts-folder=${PROJECT_DIR}/_artifacts \
219219
-e2e.config=${PROJECT_DIR}/test/e2e/config/cloudstack.yaml \
220220
-e2e.skip-resource-cleanup=false -e2e.use-existing-cluster=true

test/e2e/common.go

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ import (
2727
"github.com/apache/cloudstack-go/v2/cloudstack"
2828
"github.com/blang/semver"
2929
. "github.com/onsi/ginkgo"
30-
"github.com/onsi/gomega/types"
3130
"gopkg.in/ini.v1"
3231
corev1 "k8s.io/api/core/v1"
3332

3433
. "github.com/onsi/gomega"
34+
"github.com/onsi/gomega/types"
35+
k8stypes "k8s.io/apimachinery/pkg/types"
3536
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3637
"sigs.k8s.io/cluster-api/test/framework"
3738
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
3839
"sigs.k8s.io/cluster-api/test/framework/exec"
3940
"sigs.k8s.io/cluster-api/util"
41+
"sigs.k8s.io/controller-runtime/pkg/client"
4042
)
4143

4244
// Test suite constants for e2e config variables.
@@ -188,7 +190,7 @@ type cloudConfig struct {
188190
VerifySSL bool `ini:"verify-ssl"`
189191
}
190192

191-
func DestroyOneMachineAndWaitForReplacement(clusterName string, machineType string, intervals []interface{}) {
193+
func DestroyOneMachine(clusterName string, machineType string) {
192194
encodedSecret := os.Getenv("CLOUDSTACK_B64ENCODED_SECRET")
193195
secret, err := base64.StdEncoding.DecodeString(encodedSecret)
194196
if err != nil {
@@ -223,7 +225,6 @@ func DestroyOneMachineAndWaitForReplacement(clusterName string, machineType stri
223225
}
224226
}
225227
}
226-
Byf("Original number of machines: %d ", originalCount)
227228

228229
Byf("Destroying machine %s", vmToDestroy.Name)
229230
stopParams := client.VirtualMachine.NewStopVirtualMachineParams(vmToDestroy.Id)
@@ -238,22 +239,72 @@ func DestroyOneMachineAndWaitForReplacement(clusterName string, machineType stri
238239
if err != nil {
239240
Fail("Failed to destroy machine")
240241
}
241-
Byf("Destroyed machine %s", vmToDestroy.Name)
242-
243-
By("Waiting for a replacement machine")
244-
Eventually(func() (int, error) {
245-
By("Counting machines")
246-
listResp, err = client.VirtualMachine.ListVirtualMachines(client.VirtualMachine.NewListVirtualMachinesParams())
247-
if err != nil {
248-
return -1, err
242+
}
243+
244+
func WaitForMachineRemediationAfterDestroy(ctx context.Context, proxy framework.ClusterProxy, cluster *clusterv1.Cluster, machineMatcher string, healthyMachineCount int, intervals []interface{}) {
245+
mgmtClusterClient := proxy.GetClient()
246+
workloadClusterClient := proxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name).GetClient()
247+
248+
WaitForHealthyMachineCount(ctx, mgmtClusterClient, workloadClusterClient, cluster, machineMatcher, healthyMachineCount, intervals)
249+
Byf("Current number of healthy %s is %d", machineMatcher, healthyMachineCount)
250+
251+
Byf("Destroying one %s", machineMatcher)
252+
DestroyOneMachine(cluster.Name, machineMatcher)
253+
254+
Byf("Waiting for the destroyed %s to be unhealthy", machineMatcher)
255+
WaitForHealthyMachineCount(ctx, mgmtClusterClient, workloadClusterClient, cluster, machineMatcher, healthyMachineCount-1, intervals)
256+
257+
Byf("Waiting for remediation of %s", machineMatcher)
258+
WaitForHealthyMachineCount(ctx, mgmtClusterClient, workloadClusterClient, cluster, machineMatcher, healthyMachineCount, intervals)
259+
Byf("%s machine remediated successfully", machineMatcher)
260+
}
261+
262+
func WaitForHealthyMachineCount(ctx context.Context, mgmtClient client.Client, workloadClient client.Client, cluster *clusterv1.Cluster, mhcMatcher string, healthyMachineCount int, intervals []interface{}) {
263+
machineHealthChecks := framework.GetMachineHealthChecksForCluster(ctx, framework.GetMachineHealthChecksForClusterInput{
264+
Lister: mgmtClient,
265+
ClusterName: cluster.Name,
266+
Namespace: cluster.Namespace,
267+
})
268+
269+
for _, mhc := range machineHealthChecks {
270+
Expect(mhc.Spec.UnhealthyConditions).NotTo(BeEmpty())
271+
if !strings.Contains(mhc.Name, mhcMatcher) {
272+
continue
249273
}
250-
count := 0
251-
for _, vm := range listResp.VirtualMachines {
252-
if strings.Contains(vm.Name, matcher) {
253-
count++
274+
275+
Eventually(func() (bool, error) {
276+
machines := framework.GetMachinesByMachineHealthCheck(ctx, framework.GetMachinesByMachineHealthCheckInput{
277+
Lister: mgmtClient,
278+
ClusterName: cluster.Name,
279+
MachineHealthCheck: mhc,
280+
})
281+
282+
count := 0
283+
for _, machine := range machines {
284+
if machine.Status.NodeRef == nil {
285+
continue
286+
}
287+
node := &corev1.Node{}
288+
err := workloadClient.Get(ctx, k8stypes.NamespacedName{Name: machine.Status.NodeRef.Name, Namespace: machine.Status.NodeRef.Namespace}, node)
289+
if err != nil {
290+
continue
291+
}
292+
if !HasMatchingUnhealthyConditions(mhc, node.Status.Conditions) {
293+
count++
294+
}
295+
}
296+
return count == healthyMachineCount, nil
297+
}, intervals...).Should(BeTrue())
298+
}
299+
}
300+
301+
func HasMatchingUnhealthyConditions(machineHealthCheck *clusterv1.MachineHealthCheck, nodeConditions []corev1.NodeCondition) bool {
302+
for _, unhealthyCondition := range machineHealthCheck.Spec.UnhealthyConditions {
303+
for _, nodeCondition := range nodeConditions {
304+
if nodeCondition.Type == unhealthyCondition.Type && nodeCondition.Status == unhealthyCondition.Status {
305+
return true
254306
}
255307
}
256-
Byf("Current number of machines: %d", count)
257-
return count, nil
258-
}, intervals...).Should(Equal(originalCount))
308+
}
309+
return false
259310
}

test/e2e/config/cloudstack.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ providers:
7474
type: InfrastructureProvider
7575
files:
7676
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template.yaml"
77-
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-kcp-remediation.yaml"
78-
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-md-remediation.yaml"
7977
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-invalid-zone.yaml"
8078
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-invalid-account.yaml"
8179
- sourcePath: "../data/infrastructure-cloudstack/v1beta1/cluster-template-invalid-domain.yaml"

test/e2e/data/infrastructure-cloudstack/v1beta1/cluster-template-destroy-kcp-machine/kustomization.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/e2e/data/infrastructure-cloudstack/v1beta1/cluster-template-destroy-kcp-machine/mhc.yaml

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/e2e/data/infrastructure-cloudstack/v1beta1/cluster-template-destroy-machine/mhc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
apiVersion: cluster.x-k8s.io/v1beta1
2121
kind: MachineHealthCheck
2222
metadata:
23-
name: "${CLUSTER_NAME}-mhc-kcp-0"
23+
name: "${CLUSTER_NAME}-mhc-control-plane-0"
2424
spec:
2525
clusterName: "${CLUSTER_NAME}"
2626
maxUnhealthy: 100%

test/e2e/data/infrastructure-cloudstack/v1beta1/cluster-template-kcp-remediation/kustomization.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/e2e/data/infrastructure-cloudstack/v1beta1/cluster-template-kcp-remediation/mhc.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/e2e/data/infrastructure-cloudstack/v1beta1/cluster-template-md-remediation/kustomization.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/e2e/data/infrastructure-cloudstack/v1beta1/cluster-template-md-remediation/md.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)