Skip to content

Commit

Permalink
Add e2e test for upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Demicev <alexandr.demicev@suse.com>
  • Loading branch information
alexander-demicev committed Nov 15, 2023
1 parent f146681 commit c6f08cc
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ import (
const (
KubernetesVersionManagement = "KUBERNETES_VERSION_MANAGEMENT"
KubernetesVersion = "KUBERNETES_VERSION"
KubernetesVersionUpgradeFrom = "KUBERNETES_VERSION_UPGRADE_FROM"
KubernetesVersionUpgradeTo = "KUBERNETES_VERSION_UPGRADE_TO"
CPMachineTemplateUpgradeTo = "CONTROL_PLANE_MACHINE_TEMPLATE_UPGRADE_TO"
WorkersMachineTemplateUpgradeTo = "WORKERS_MACHINE_TEMPLATE_UPGRADE_TO"
IPFamily = "IP_FAMILY"
KindImageVersion = "KIND_IMAGE_VERSION"
)

func Byf(format string, a ...interface{}) {
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/config/e2e_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ providers:
new: "--leader-elect=false"

variables:
KUBERNETES_VERSION_MANAGEMENT: "v1.24.4"
KUBERNETES_VERSION: "v1.24.4"
KUBERNETES_VERSION_MANAGEMENT: "v1.28.0"
KUBERNETES_VERSION: "v1.28.1"
KIND_IMAGE_VERSION: "v1.28.0"
NODE_DRAIN_TIMEOUT: "60s"
CONFORMANCE_WORKER_MACHINE_COUNT: "2"
CONFORMANCE_CONTROL_PLANE_MACHINE_COUNT: "1"
KUBERNETES_VERSION_UPGRADE_TO: "v1.24.2"
KUBERNETES_VERSION_UPGRADE_FROM: "v1.23.8"
KUBERNETES_VERSION_UPGRADE_TO: "v1.28.2"
KUBERNETES_UPGRADE_OCI_IMAGE_ID: "${KUBERNETES_UPGRADE_OCI_IMAGE_ID}"
IP_FAMILY: "IPv4"
EXP_CLUSTER_RESOURCE_SET: "true"
Expand Down
8 changes: 5 additions & 3 deletions test/e2e/data/infrastructure/cluster-template-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ metadata:
name: "${CLUSTER_NAME}-control-plane"
spec:
template:
spec: {}
spec:
customImage: kindest/node:${KIND_IMAGE_VERSION}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
Expand Down Expand Up @@ -80,7 +81,8 @@ metadata:
name: ${CLUSTER_NAME}-md-0
spec:
template:
spec: {}
spec:
customImage: kindest/node:${KIND_IMAGE_VERSION}
---
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha1
kind: RKE2ConfigTemplate
Expand All @@ -92,4 +94,4 @@ spec:
agentConfig:
version: ${KUBERNETES_VERSION}+rke2r1
nodeAnnotations:
test: "true"
test: "true"
3 changes: 3 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"

bootstrapv1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1alpha1"
controlplanev1 "github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1alpha1"
Expand Down Expand Up @@ -104,6 +105,8 @@ func init() {
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)

ctrl.SetLogger(klog.Background())

RunSpecs(t, "caprke2-e2e")
}

Expand Down
32 changes: 32 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,38 @@ var _ = Describe("Workload cluster creation", func() {
ControlPlane: result.ControlPlane,
}, e2eConfig.GetIntervals(specName, "wait-control-plane")...)

By("Upgrading control plane and worker machines")
ApplyClusterTemplateAndWait(ctx, ApplyClusterTemplateAndWaitInput{
ClusterProxy: bootstrapClusterProxy,
ConfigCluster: clusterctl.ConfigClusterInput{
LogFolder: clusterctlLogFolder,
ClusterctlConfigPath: clusterctlConfigPath,
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
InfrastructureProvider: "docker",
Flavor: "docker",
Namespace: namespace.Name,
ClusterName: clusterName,
KubernetesVersion: e2eConfig.GetVariable(KubernetesVersionUpgradeTo),
ControlPlaneMachineCount: pointer.Int64Ptr(3),
WorkerMachineCount: pointer.Int64Ptr(3),
},
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
}, result)

WaitForClusterToUpgrade(ctx, WaitForClusterToUpgradeInput{
Lister: bootstrapClusterProxy.GetClient(),
ControlPlane: result.ControlPlane,
MachineDeployments: result.MachineDeployments,
VersionAfterUpgrade: e2eConfig.GetVariable(KubernetesVersionUpgradeTo),
}, e2eConfig.GetIntervals(specName, "wait-control-plane")...)

WaitForControlPlaneToBeReady(ctx, WaitForControlPlaneToBeReadyInput{
Getter: bootstrapClusterProxy.GetClient(),
ControlPlane: result.ControlPlane,
}, e2eConfig.GetIntervals(specName, "wait-control-plane")...)

// TODO: this can be uncommented when control plane scaling down is working

// By("Scaling control plane nodes to 1")
Expand Down
38 changes: 38 additions & 0 deletions test/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package e2e

import (
"context"
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -251,6 +252,43 @@ func WaitForMachineConditions(ctx context.Context, input WaitForMachineCondition
}, intervals...).Should(BeTrue(), framework.PrettyPrint(input.Machine)+"\n")
}

// WaitForClusterToUpgradeInput is the input for WaitForClusterToUpgrade.
type WaitForClusterToUpgradeInput struct {
Lister framework.Lister
ControlPlane *controlplanev1.RKE2ControlPlane
MachineDeployments []*clusterv1.MachineDeployment
VersionAfterUpgrade string
}

// WaitForClusterToUpgrade will wait for a cluster to be upgraded.
func WaitForClusterToUpgrade(ctx context.Context, input WaitForClusterToUpgradeInput, intervals ...interface{}) {
By("Waiting for machines to update")

totallMachineCount := *input.ControlPlane.Spec.Replicas
for _, md := range input.MachineDeployments {
totallMachineCount += *md.Spec.Replicas
}

Eventually(func() (bool, error) {
machineList := &clusterv1.MachineList{}
if err := input.Lister.List(ctx, machineList); err != nil {
return false, fmt.Errorf("failed to list machines: %w", err)
}

if len(machineList.Items) != int(totallMachineCount) { // not all replicas are created
return false, nil
}

for _, machine := range machineList.Items {
if machine.Spec.Version != nil && *machine.Spec.Version != input.VersionAfterUpgrade {
return false, nil
}
}

return true, nil
}, intervals...).Should(BeTrue(), framework.PrettyPrint(input.ControlPlane)+"\n")
}

func setDefaults(input *ApplyClusterTemplateAndWaitInput) {
if input.WaitForControlPlaneInitialized == nil {
input.WaitForControlPlaneInitialized = func(ctx context.Context, input ApplyClusterTemplateAndWaitInput, result *ApplyClusterTemplateAndWaitResult) {
Expand Down

0 comments on commit c6f08cc

Please sign in to comment.