Skip to content

Commit 3e41252

Browse files
committed
add checker to validate conditions for v1beta2 to scale.go
Signed-off-by: sivchari <[email protected]>
1 parent c8d8f4e commit 3e41252

File tree

3 files changed

+71
-54
lines changed

3 files changed

+71
-54
lines changed

test/e2e/clusterctl_upgrade.go

+4-49
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,10 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
753753
Byf("[%d] THE UPGRADED MANAGEMENT CLUSTER WORKS!", i)
754754
}
755755

756+
Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
757+
verifyV1Beta2ConditionsTrueV1Beta1(ctx, input.BootstrapClusterProxy.GetClient(), workloadClusterName, workloadClusterNamespace,
758+
[]string{clusterv1.AvailableCondition, clusterv1.ReadyCondition})
759+
756760
By("PASSED!")
757761
})
758762

@@ -801,55 +805,6 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
801805
})
802806
}
803807

804-
// verifyV1Beta2ConditionsTrueV1Beta1 checks the Cluster and Machines of a Cluster that
805-
// the given v1beta2 condition types are set to true without a message, if they exist.
806-
func verifyV1Beta2ConditionsTrueV1Beta1(ctx context.Context, c client.Client, clusterName, clusterNamespace string, v1beta2conditionTypes []string) {
807-
cluster := &clusterv1beta1.Cluster{}
808-
key := client.ObjectKey{
809-
Namespace: clusterNamespace,
810-
Name: clusterName,
811-
}
812-
Eventually(func() error {
813-
return c.Get(ctx, key, cluster)
814-
}, 3*time.Minute, 3*time.Second).Should(Succeed(), "Failed to get Cluster object %s", klog.KRef(clusterNamespace, clusterName))
815-
816-
if cluster.Status.V1Beta2 != nil && len(cluster.Status.V1Beta2.Conditions) > 0 {
817-
for _, conditionType := range v1beta2conditionTypes {
818-
for _, condition := range cluster.Status.V1Beta2.Conditions {
819-
if condition.Type != conditionType {
820-
continue
821-
}
822-
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Cluster should be set to true", conditionType)
823-
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Cluster should have an empty message", conditionType)
824-
}
825-
}
826-
}
827-
828-
machineList := &clusterv1beta1.MachineList{}
829-
Eventually(func() error {
830-
return c.List(ctx, machineList, client.InNamespace(clusterNamespace),
831-
client.MatchingLabels{
832-
clusterv1.ClusterNameLabel: clusterName,
833-
})
834-
}, 3*time.Minute, 3*time.Second).Should(Succeed(), "Failed to list Machines for Cluster %s", klog.KObj(cluster))
835-
if cluster.Status.V1Beta2 != nil && len(cluster.Status.V1Beta2.Conditions) > 0 {
836-
for _, machine := range machineList.Items {
837-
if machine.Status.V1Beta2 == nil || len(machine.Status.V1Beta2.Conditions) == 0 {
838-
continue
839-
}
840-
for _, conditionType := range v1beta2conditionTypes {
841-
for _, condition := range machine.Status.V1Beta2.Conditions {
842-
if condition.Type != conditionType {
843-
continue
844-
}
845-
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Machine %q should be set to true", conditionType, machine.Name)
846-
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Machine %q should have an empty message", conditionType, machine.Name)
847-
}
848-
}
849-
}
850-
}
851-
}
852-
853808
func setupClusterctl(ctx context.Context, clusterctlBinaryURL, clusterctlConfigPath string) (string, string) {
854809
clusterctlBinaryPath := downloadToTmpFile(ctx, clusterctlBinaryURL)
855810

test/e2e/common.go

+56
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ package e2e
1919
import (
2020
"context"
2121
"fmt"
22+
"time"
2223

2324
"github.com/blang/semver/v4"
2425
. "github.com/onsi/ginkgo/v2"
26+
. "github.com/onsi/gomega"
2527
"github.com/onsi/gomega/types"
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/klog/v2"
30+
"sigs.k8s.io/controller-runtime/pkg/client"
2631

32+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
33+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
2734
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
2835
)
2936

@@ -82,3 +89,52 @@ func GetLatestReleaseOfMinor(ctx context.Context, minorRelease string) (string,
8289
releaseMarker := fmt.Sprintf(latestReleaseMarkerPrefix, minorRelease)
8390
return clusterctl.ResolveRelease(ctx, releaseMarker)
8491
}
92+
93+
// verifyV1Beta2ConditionsTrueV1Beta1 checks the Cluster and Machines of a Cluster that
94+
// the given v1beta2 condition types are set to true without a message, if they exist.
95+
func verifyV1Beta2ConditionsTrueV1Beta1(ctx context.Context, c client.Client, clusterName, clusterNamespace string, v1beta2conditionTypes []string) {
96+
cluster := &clusterv1beta1.Cluster{}
97+
key := client.ObjectKey{
98+
Namespace: clusterNamespace,
99+
Name: clusterName,
100+
}
101+
Eventually(func() error {
102+
return c.Get(ctx, key, cluster)
103+
}, 3*time.Minute, 3*time.Second).Should(Succeed(), "Failed to get Cluster object %s", klog.KRef(clusterNamespace, clusterName))
104+
105+
if cluster.Status.V1Beta2 != nil && len(cluster.Status.V1Beta2.Conditions) > 0 {
106+
for _, conditionType := range v1beta2conditionTypes {
107+
for _, condition := range cluster.Status.V1Beta2.Conditions {
108+
if condition.Type != conditionType {
109+
continue
110+
}
111+
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Cluster should be set to true", conditionType)
112+
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Cluster should have an empty message", conditionType)
113+
}
114+
}
115+
}
116+
117+
machineList := &clusterv1beta1.MachineList{}
118+
Eventually(func() error {
119+
return c.List(ctx, machineList, client.InNamespace(clusterNamespace),
120+
client.MatchingLabels{
121+
clusterv1.ClusterNameLabel: clusterName,
122+
})
123+
}, 3*time.Minute, 3*time.Second).Should(Succeed(), "Failed to list Machines for Cluster %s", klog.KObj(cluster))
124+
if cluster.Status.V1Beta2 != nil && len(cluster.Status.V1Beta2.Conditions) > 0 {
125+
for _, machine := range machineList.Items {
126+
if machine.Status.V1Beta2 == nil || len(machine.Status.V1Beta2.Conditions) == 0 {
127+
continue
128+
}
129+
for _, conditionType := range v1beta2conditionTypes {
130+
for _, condition := range machine.Status.V1Beta2.Conditions {
131+
if condition.Type != conditionType {
132+
continue
133+
}
134+
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Machine %q should be set to true", conditionType, machine.Name)
135+
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Machine %q should have an empty message", conditionType, machine.Name)
136+
}
137+
}
138+
}
139+
}
140+
}

test/e2e/scale.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -462,18 +462,24 @@ func ScaleSpec(ctx context.Context, inputGetter func() ScaleSpecInput) {
462462
}
463463
}
464464

465-
// TODO(ykakarap): Follow-up: Dump resources for the failed clusters (creation).
466-
467-
clusterNamesToDelete := []string{}
468-
for _, result := range clusterCreateResults {
469-
clusterNamesToDelete = append(clusterNamesToDelete, result.clusterName)
465+
for _, cluster := range clusterCreateResults {
466+
Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
467+
verifyV1Beta2ConditionsTrueV1Beta1(ctx, input.BootstrapClusterProxy.GetClient(), cluster.clusterName, namespace.Name,
468+
[]string{clusterv1.AvailableCondition, clusterv1.ReadyCondition})
470469
}
471470

471+
// TODO(ykakarap): Follow-up: Dump resources for the failed clusters (creation).
472+
472473
if input.SkipCleanup {
473474
By("PASSED!")
474475
return
475476
}
476477

478+
clusterNamesToDelete := []string{}
479+
for _, result := range clusterCreateResults {
480+
clusterNamesToDelete = append(clusterNamesToDelete, result.clusterName)
481+
}
482+
477483
By("Delete the workload clusters concurrently")
478484
// Now delete all the workload clusters.
479485
_, err = workConcurrentlyAndWait(ctx, workConcurrentlyAndWaitInput{

0 commit comments

Comments
 (0)