Skip to content

🌱 add checker to validate conditions for v1beta2 #12111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/e2e/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput)
})
}

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/cluster_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func ClusterDeletionSpec(ctx context.Context, inputGetter func() ClusterDeletion
},
}, clusterResources)

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

// Get all objects per deletion phase and the list of blocking objects.
var objectsPerPhase [][]client.Object
objectsPerPhase, blockingObjects = getDeletionPhaseObjects(ctx, input.BootstrapClusterProxy, clusterResources.Cluster, input.ClusterDeletionPhases)
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/cluster_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/test/framework/kubetest"
Expand Down Expand Up @@ -259,6 +260,12 @@ func ClusterUpgradeConformanceSpec(ctx context.Context, inputGetter func() Clust
WaitForNodesReady: input.E2EConfig.GetIntervals(specName, "wait-nodes-ready"),
})

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

if !input.SkipConformanceTests {
By("Running conformance tests")
// Start running the conformance test suite.
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/cluster_upgrade_runtimesdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() Cl
"AfterClusterUpgrade": "Success",
})).To(Succeed(), "Lifecycle hook calls were not as expected")

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/clusterclass_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ func ClusterClassChangesSpec(ctx context.Context, inputGetter func() ClusterClas
WaitForMachinePools: input.E2EConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
})

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("Deleting a MachineDeploymentTopology in the Cluster Topology and wait for associated MachineDeployment to be deleted")
deleteMachineDeploymentTopologyAndWait(ctx, deleteMachineDeploymentTopologyAndWaitInput{
ClusterProxy: input.BootstrapClusterProxy,
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/clusterclass_rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
}, input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade")...).Should(Succeed())
assertClusterObjects(ctx, input.BootstrapClusterProxy, clusterResources.Cluster, clusterResources.ClusterClass, input.FilterMetadataBeforeValidation)

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
55 changes: 4 additions & 51 deletions test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,10 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
}

Byf("[%d] Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines", i)
verifyV1Beta2ConditionsTrueV1Beta1(ctx, managementClusterProxy.GetClient(), workloadCluster.Name, workloadCluster.Namespace,
[]string{clusterv1.AvailableCondition, clusterv1.ReadyCondition})
verifyV1Beta2Conditions(ctx, managementClusterProxy.GetClient(), workloadCluster.Name, workloadCluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

// Note: It is a known issue on Kubernetes < v1.29 that SSA sometimes fail:
// https://github.com/kubernetes/kubernetes/issues/117356
Expand Down Expand Up @@ -801,55 +803,6 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
})
}

// verifyV1Beta2ConditionsTrueV1Beta1 checks the Cluster and Machines of a Cluster that
// the given v1beta2 condition types are set to true without a message, if they exist.
func verifyV1Beta2ConditionsTrueV1Beta1(ctx context.Context, c client.Client, clusterName, clusterNamespace string, v1beta2conditionTypes []string) {
cluster := &clusterv1beta1.Cluster{}
key := client.ObjectKey{
Namespace: clusterNamespace,
Name: clusterName,
}
Eventually(func() error {
return c.Get(ctx, key, cluster)
}, 3*time.Minute, 3*time.Second).Should(Succeed(), "Failed to get Cluster object %s", klog.KRef(clusterNamespace, clusterName))

if cluster.Status.V1Beta2 != nil && len(cluster.Status.V1Beta2.Conditions) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we need a rebase (cluster.Status.v1beta2 doesn't exist anymore)

for _, conditionType := range v1beta2conditionTypes {
for _, condition := range cluster.Status.V1Beta2.Conditions {
if condition.Type != conditionType {
continue
}
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Cluster should be set to true", conditionType)
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Cluster should have an empty message", conditionType)
}
}
}

machineList := &clusterv1beta1.MachineList{}
Eventually(func() error {
return c.List(ctx, machineList, client.InNamespace(clusterNamespace),
client.MatchingLabels{
clusterv1.ClusterNameLabel: clusterName,
})
}, 3*time.Minute, 3*time.Second).Should(Succeed(), "Failed to list Machines for Cluster %s", klog.KObj(cluster))
if cluster.Status.V1Beta2 != nil && len(cluster.Status.V1Beta2.Conditions) > 0 {
for _, machine := range machineList.Items {
if machine.Status.V1Beta2 == nil || len(machine.Status.V1Beta2.Conditions) == 0 {
continue
}
for _, conditionType := range v1beta2conditionTypes {
for _, condition := range machine.Status.V1Beta2.Conditions {
if condition.Type != conditionType {
continue
}
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Machine %q should be set to true", conditionType, machine.Name)
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Machine %q should have an empty message", conditionType, machine.Name)
}
}
}
}
}

func setupClusterctl(ctx context.Context, clusterctlBinaryURL, clusterctlConfigPath string) (string, string) {
clusterctlBinaryPath := downloadToTmpFile(ctx, clusterctlBinaryURL)

Expand Down
51 changes: 51 additions & 0 deletions test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ package e2e
import (
"context"
"fmt"
"time"

"github.com/blang/semver/v4"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
)

Expand Down Expand Up @@ -82,3 +88,48 @@ func GetLatestReleaseOfMinor(ctx context.Context, minorRelease string) (string,
releaseMarker := fmt.Sprintf(latestReleaseMarkerPrefix, minorRelease)
return clusterctl.ResolveRelease(ctx, releaseMarker)
}

// verifyV1Beta2Conditions checks the Cluster and Machines of a Cluster that
// the given v1beta2 condition types are set to true without a message, if they exist.
func verifyV1Beta2Conditions(ctx context.Context, c client.Client, clusterName, clusterNamespace string, v1beta2conditionTypes map[string]struct{}) {
cluster := &clusterv1.Cluster{}
key := client.ObjectKey{
Namespace: clusterNamespace,
Name: clusterName,
}
Eventually(func() error {
return c.Get(ctx, key, cluster)
}, 3*time.Minute, 10*time.Second).Should(Succeed(), "Failed to get Cluster object %s", klog.KRef(clusterNamespace, clusterName))

if len(cluster.Status.Conditions) > 0 {
for _, condition := range cluster.Status.Conditions {
if _, ok := v1beta2conditionTypes[condition.Type]; !ok {
continue
}
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Cluster should be set to true", condition.Type)
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Cluster should have an empty message", condition.Type)
}
}

machineList := &clusterv1.MachineList{}
Eventually(func() error {
return c.List(ctx, machineList, client.InNamespace(clusterNamespace),
client.MatchingLabels{
clusterv1.ClusterNameLabel: clusterName,
})
}, 3*time.Minute, 10*time.Second).Should(Succeed(), "Failed to list Machines for Cluster %s", klog.KObj(cluster))
if len(cluster.Status.Conditions) > 0 {
for _, machine := range machineList.Items {
if len(machine.Status.Conditions) == 0 {
continue
}
for _, condition := range machine.Status.Conditions {
if _, ok := v1beta2conditionTypes[condition.Type]; !ok {
continue
}
Expect(condition.Status).To(Equal(metav1.ConditionTrue), "The v1beta2 condition %q on the Machine %q should be set to true", condition.Type, machine.Name)
Expect(condition.Message).To(BeEmpty(), "The v1beta2 condition %q on the Machine %q should have an empty message", condition.Type, machine.Name)
}
}
}
}
7 changes: 7 additions & 0 deletions test/e2e/k8s_conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/test/framework/kubetest"
Expand Down Expand Up @@ -153,6 +154,12 @@ func K8SConformanceSpec(ctx context.Context, inputGetter func() K8SConformanceSp
)
Expect(err).ToNot(HaveOccurred(), "Failed to run Kubernetes conformance")

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/kcp_adoption.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ func KCPAdoptionSpec(ctx context.Context, inputGetter func() KCPAdoptionSpecInpu
}
Expect(secrets.Items).To(HaveLen(4 /* pki */ + 1 /* kubeconfig */ + int(*replicas)))

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), cluster.Name, cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/kcp_remediations.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ func KCPRemediationSpec(ctx context.Context, inputGetter func() KCPRemediationSp

By("CP BACK TO FULL OPERATIONAL STATE!")

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/machine_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -139,6 +140,12 @@ func MachinePoolSpec(ctx context.Context, inputGetter func() MachinePoolInput) {
WaitForMachinePoolToScale: input.E2EConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
})

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/md_remediations.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -120,6 +121,12 @@ func MachineDeploymentRemediationSpec(ctx context.Context, inputGetter func() Ma
WaitForMachineRemediation: input.E2EConfig.GetIntervals(specName, "wait-machine-remediation"),
})

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
8 changes: 8 additions & 0 deletions test/e2e/md_rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -120,6 +121,13 @@ func MachineDeploymentRolloutSpec(ctx context.Context, inputGetter func() Machin
WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
MachineDeployments: clusterResources.MachineDeployments,
})

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/md_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -125,6 +126,12 @@ func MachineDeploymentScaleSpec(ctx context.Context, inputGetter func() MachineD
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
})

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("Deleting the MachineDeployment with foreground deletion")
foreground := metav1.DeletePropagationForeground
framework.DeleteAndWaitMachineDeployment(ctx, framework.DeleteAndWaitMachineDeploymentInput{
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/node_drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,12 @@ func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeo
}
}, nodeDrainTimeoutKCPInterval...).Should(Succeed())

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/quick_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
"sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -180,6 +181,12 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
},
}, clusterResources)

Byf("Verify v1beta2 Available and Ready conditions (if exist) to be true for Cluster and Machines")
verifyV1Beta2Conditions(ctx, input.BootstrapClusterProxy.GetClient(), clusterResources.Cluster.Name, clusterResources.Cluster.Namespace,
map[string]struct{}{
clusterv1.AvailableCondition: {}, clusterv1.ReadyCondition: {},
})

By("PASSED!")
})

Expand Down
Loading
Loading