Skip to content

Commit e107322

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

File tree

3 files changed

+62
-49
lines changed

3 files changed

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

+58
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ 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"
2628

29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/klog/v2"
31+
2732
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
33+
"sigs.k8s.io/controller-runtime/pkg/client"
34+
35+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
36+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
2837
)
2938

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

0 commit comments

Comments
 (0)