Skip to content
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

🌱 Add MachinePools to topology upgrade test #9502

Merged
merged 1 commit into from
Sep 28, 2023
Merged
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
1 change: 1 addition & 0 deletions test/e2e/cluster_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func ClusterUpgradeConformanceSpec(ctx context.Context, inputGetter func() Clust
EtcdImageTag: input.E2EConfig.GetVariable(EtcdVersionUpgradeTo),
DNSImageTag: input.E2EConfig.GetVariable(CoreDNSVersionUpgradeTo),
MachineDeployments: clusterResources.MachineDeployments,
MachinePools: clusterResources.MachinePools,
KubernetesUpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo),
WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
WaitForKubeProxyUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/cluster_upgrade_runtimesdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func clusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() cl
Cluster: clusterResources.Cluster,
ControlPlane: clusterResources.ControlPlane,
MachineDeployments: clusterResources.MachineDeployments,
MachinePools: clusterResources.MachinePools,
KubernetesUpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo),
WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
WaitForKubeProxyUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
Expand All @@ -233,7 +234,7 @@ func clusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() cl
input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo),
input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"))
},
PreWaitForMachineDeploymentToBeUpgraded: func() {
PreWaitForWorkersToBeUpgraded: func() {
machineSetPreflightChecksTestHandler(ctx,
input.BootstrapClusterProxy.GetClient(),
clusterRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ spec:
nodeDeletionTimeout: "30s"
replicas: ${WORKER_MACHINE_COUNT}
failureDomain: fd4
machinePools:
- class: "default-worker"
name: "mp-0"
nodeDeletionTimeout: "30s"
nodeVolumeDetachTimeout: "5m"
minReadySeconds: 5
replicas: ${WORKER_MACHINE_COUNT}
failureDomains:
- fd4
variables:
- name: kubeadmControlPlaneMaxSurge
value: "1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
resources:
- ../bases/crs.yaml
- ../bases/mp.yaml
- cluster-runtimesdk.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
resources:
- ../bases/cluster-with-topology.yaml
- ../bases/crs.yaml
- ../bases/mp.yaml
1 change: 1 addition & 0 deletions test/e2e/self_hosted.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
EtcdImageTag: input.E2EConfig.GetVariable(EtcdVersionUpgradeTo),
DNSImageTag: input.E2EConfig.GetVariable(CoreDNSVersionUpgradeTo),
MachineDeployments: clusterResources.MachineDeployments,
MachinePools: clusterResources.MachinePools,
KubernetesUpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo),
WaitForMachinesToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
WaitForKubeProxyUpgrade: input.E2EConfig.GetIntervals(specName, "wait-machine-upgrade"),
Expand Down
53 changes: 36 additions & 17 deletions test/framework/cluster_topology_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
"sigs.k8s.io/cluster-api/test/framework/internal/log"
"sigs.k8s.io/cluster-api/util/patch"
)
Expand Down Expand Up @@ -59,19 +60,21 @@ func GetClusterClassByName(ctx context.Context, input GetClusterClassByNameInput

// UpgradeClusterTopologyAndWaitForUpgradeInput is the input type for UpgradeClusterTopologyAndWaitForUpgrade.
type UpgradeClusterTopologyAndWaitForUpgradeInput struct {
ClusterProxy ClusterProxy
Cluster *clusterv1.Cluster
ControlPlane *controlplanev1.KubeadmControlPlane
EtcdImageTag string
DNSImageTag string
MachineDeployments []*clusterv1.MachineDeployment
KubernetesUpgradeVersion string
WaitForMachinesToBeUpgraded []interface{}
WaitForKubeProxyUpgrade []interface{}
WaitForDNSUpgrade []interface{}
WaitForEtcdUpgrade []interface{}
PreWaitForControlPlaneToBeUpgraded func()
PreWaitForMachineDeploymentToBeUpgraded func()
ClusterProxy ClusterProxy
Cluster *clusterv1.Cluster
ControlPlane *controlplanev1.KubeadmControlPlane
EtcdImageTag string
DNSImageTag string
MachineDeployments []*clusterv1.MachineDeployment
MachinePools []*expv1.MachinePool
KubernetesUpgradeVersion string
WaitForMachinesToBeUpgraded []interface{}
WaitForMachinePoolToBeUpgraded []interface{}
WaitForKubeProxyUpgrade []interface{}
WaitForDNSUpgrade []interface{}
WaitForEtcdUpgrade []interface{}
PreWaitForControlPlaneToBeUpgraded func()
PreWaitForWorkersToBeUpgraded func()
}

// UpgradeClusterTopologyAndWaitForUpgrade upgrades a Cluster topology and waits for it to be upgraded.
Expand All @@ -82,6 +85,7 @@ func UpgradeClusterTopologyAndWaitForUpgrade(ctx context.Context, input UpgradeC
Expect(input.Cluster).ToNot(BeNil(), "Invalid argument. input.Cluster can't be nil when calling UpgradeClusterTopologyAndWaitForUpgrade")
Expect(input.ControlPlane).ToNot(BeNil(), "Invalid argument. input.ControlPlane can't be nil when calling UpgradeClusterTopologyAndWaitForUpgrade")
Expect(input.MachineDeployments).ToNot(BeEmpty(), "Invalid argument. input.MachineDeployments can't be empty when calling UpgradeClusterTopologyAndWaitForUpgrade")
Expect(input.MachinePools).ToNot(BeEmpty(), "Invalid argument. input.MachinePools can't be empty when calling UpgradeClusterTopologyAndWaitForUpgrade")
Expect(input.KubernetesUpgradeVersion).ToNot(BeNil(), "Invalid argument. input.KubernetesUpgradeVersion can't be empty when calling UpgradeClusterTopologyAndWaitForUpgrade")

mgmtClient := input.ClusterProxy.GetClient()
Expand Down Expand Up @@ -150,12 +154,12 @@ func UpgradeClusterTopologyAndWaitForUpgrade(ctx context.Context, input UpgradeC
}, input.WaitForEtcdUpgrade...)
}

// Once the ControlPlane is upgraded we can run PreWaitForMachineDeploymentToBeUpgraded.
// Once the ControlPlane is upgraded we can run PreWaitForWorkersToBeUpgraded.
// Note: This can e.g. be used to verify the AfterControlPlaneUpgrade lifecycle hook is executed
// and blocking correctly.
if input.PreWaitForMachineDeploymentToBeUpgraded != nil {
log.Logf("Calling PreWaitForMachineDeploymentToBeUpgraded")
input.PreWaitForMachineDeploymentToBeUpgraded()
if input.PreWaitForWorkersToBeUpgraded != nil {
log.Logf("Calling PreWaitForWorkersToBeUpgraded")
input.PreWaitForWorkersToBeUpgraded()
}

for _, deployment := range input.MachineDeployments {
Expand All @@ -171,4 +175,19 @@ func UpgradeClusterTopologyAndWaitForUpgrade(ctx context.Context, input UpgradeC
}, input.WaitForMachinesToBeUpgraded...)
}
}

for _, pool := range input.MachinePools {
if *pool.Spec.Replicas > 0 {
log.Logf("Waiting for Kubernetes versions of machines in MachinePool %s to be upgraded to %s",
klog.KObj(pool), input.KubernetesUpgradeVersion)
WaitForMachinePoolInstancesToBeUpgraded(ctx, WaitForMachinePoolInstancesToBeUpgradedInput{
Getter: mgmtClient,
WorkloadClusterGetter: input.ClusterProxy.GetWorkloadCluster(ctx, input.Cluster.Namespace, input.Cluster.Name).GetClient(),
Cluster: input.Cluster,
MachineCount: int(*pool.Spec.Replicas),
KubernetesUpgradeVersion: input.KubernetesUpgradeVersion,
MachinePool: pool,
}, input.WaitForMachinePoolToBeUpgraded...)
}
}
}