Skip to content

Commit 6dc0ee3

Browse files
committed
add checker to validate conditions for v1beta2
Signed-off-by: sivchari <[email protected]>
1 parent d753f40 commit 6dc0ee3

File tree

3 files changed

+60
-49
lines changed

3 files changed

+60
-49
lines changed

test/e2e/autoscaler.go

+4
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput)
367367
})
368368
}
369369

370+
Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
371+
verifyV1Beta2ConditionsTrueV1Beta1(ctx, input.BootstrapClusterProxy.GetClient(), workloadClusterProxy.GetName(), namespace.Name,
372+
[]string{clusterv1.AvailableCondition, clusterv1.ReadyCondition})
373+
370374
By("PASSED!")
371375
})
372376

test/e2e/clusterctl_upgrade.go

-49
Original file line numberDiff line numberDiff line change
@@ -801,55 +801,6 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
801801
})
802802
}
803803

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-
853804
func setupClusterctl(ctx context.Context, clusterctlBinaryURL, clusterctlConfigPath string) (string, string) {
854805
clusterctlBinaryPath := downloadToTmpFile(ctx, clusterctlBinaryURL)
855806

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+
}

0 commit comments

Comments
 (0)