|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "strings" |
| 8 | + |
| 9 | + . "github.com/onsi/ginkgo/v2" |
| 10 | + . "github.com/onsi/gomega" |
| 11 | + "sigs.k8s.io/cluster-api/test/framework" |
| 12 | + "sigs.k8s.io/cluster-api/test/framework/clusterctl" |
| 13 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 14 | +) |
| 15 | + |
| 16 | +var _ = Describe("Kubernetes version upgrade in target nodes", Label("k8s-upgrade-n3"), func() { |
| 17 | + |
| 18 | + var ( |
| 19 | + ctx = context.TODO() |
| 20 | + clusterctlLogFolder string |
| 21 | + ) |
| 22 | + |
| 23 | + BeforeEach(func() { |
| 24 | + osType = strings.ToLower(os.Getenv("OS")) |
| 25 | + Expect(osType).ToNot(Equal("")) |
| 26 | + validateGlobals(specName) |
| 27 | + |
| 28 | + // We need to override clusterctl apply log folder to avoid getting our credentials exposed. |
| 29 | + clusterctlLogFolder = filepath.Join(os.TempDir(), "target_cluster_logs", bootstrapClusterProxy.GetName()) |
| 30 | + }) |
| 31 | + |
| 32 | + It("Should create a cluster and run kubernetes N+3 tests", func() { |
| 33 | + By("Apply BMH for workload cluster") |
| 34 | + ApplyBmh(ctx, e2eConfig, bootstrapClusterProxy, namespace, specName) |
| 35 | + By("Creating target cluster") |
| 36 | + targetCluster, _ = CreateTargetCluster(ctx, func() CreateTargetClusterInput { |
| 37 | + return CreateTargetClusterInput{ |
| 38 | + E2EConfig: e2eConfig, |
| 39 | + BootstrapClusterProxy: bootstrapClusterProxy, |
| 40 | + SpecName: specName, |
| 41 | + ClusterName: clusterName, |
| 42 | + K8sVersion: e2eConfig.MustGetVariable("KUBERNETES_N0_VERSION"), |
| 43 | + KCPMachineCount: int64(numberOfControlplane), |
| 44 | + WorkerMachineCount: int64(numberOfWorkers), |
| 45 | + ClusterctlLogFolder: clusterctlLogFolder, |
| 46 | + ClusterctlConfigPath: clusterctlConfigPath, |
| 47 | + OSType: osType, |
| 48 | + Namespace: namespace, |
| 49 | + } |
| 50 | + }) |
| 51 | + |
| 52 | + By("Running Kubernetes Upgrade tests") |
| 53 | + upgradeKubernetesN3(ctx, func() upgradeKubernetesN3Input { |
| 54 | + return upgradeKubernetesN3Input{ |
| 55 | + E2EConfig: e2eConfig, |
| 56 | + BootstrapClusterProxy: bootstrapClusterProxy, |
| 57 | + TargetCluster: targetCluster, |
| 58 | + SpecName: specName, |
| 59 | + ClusterName: clusterName, |
| 60 | + Namespace: namespace, |
| 61 | + } |
| 62 | + }) |
| 63 | + }) |
| 64 | + |
| 65 | + AfterEach(func() { |
| 66 | + ListBareMetalHosts(ctx, bootstrapClusterProxy.GetClient(), client.InNamespace(namespace)) |
| 67 | + ListMetal3Machines(ctx, bootstrapClusterProxy.GetClient(), client.InNamespace(namespace)) |
| 68 | + ListMachines(ctx, bootstrapClusterProxy.GetClient(), client.InNamespace(namespace)) |
| 69 | + ListNodes(ctx, targetCluster.GetClient()) |
| 70 | + DumpSpecResourcesAndCleanup(ctx, specName, bootstrapClusterProxy, targetCluster, artifactFolder, namespace, e2eConfig.GetIntervals, clusterName, clusterctlLogFolder, skipCleanup, clusterctlConfigPath) |
| 71 | + }) |
| 72 | + |
| 73 | +}) |
| 74 | + |
| 75 | +type upgradeKubernetesN3Input struct { |
| 76 | + E2EConfig *clusterctl.E2EConfig |
| 77 | + BootstrapClusterProxy framework.ClusterProxy |
| 78 | + TargetCluster framework.ClusterProxy |
| 79 | + SpecName string |
| 80 | + ClusterName string |
| 81 | + Namespace string |
| 82 | +} |
| 83 | + |
| 84 | +// upgradeKubernetesN3 implements a test upgrading the cluster nodes from an old k8s version to a newer version. |
| 85 | +func upgradeKubernetesN3(ctx context.Context, inputGetter func() upgradeKubernetesN3Input) { |
| 86 | + Logf("Starting Kubernetes upgrade tests") |
| 87 | + input := inputGetter() |
| 88 | + clusterClient := input.BootstrapClusterProxy.GetClient() |
| 89 | + targetClusterClient := input.TargetCluster.GetClient() |
| 90 | + kubernetesVersion := input.E2EConfig.MustGetVariable("KUBERNETES_N0_VERSION") |
| 91 | + upgradedK8sVersion1 := input.E2EConfig.MustGetVariable("KUBERNETES_N1_VERSION") |
| 92 | + upgradedK8sVersion2 := input.E2EConfig.MustGetVariable("KUBERNETES_N2_VERSION") |
| 93 | + upgradedK8sVersion3 := input.E2EConfig.MustGetVariable("KUBERNETES_N3_VERSION") |
| 94 | + |
| 95 | + Logf("KUBERNETES VERSION: %v", kubernetesVersion) |
| 96 | + Logf("UPGRADED K8S VERSION: %v", upgradedK8sVersion1) |
| 97 | + |
| 98 | + ListBareMetalHosts(ctx, clusterClient, client.InNamespace(input.Namespace)) |
| 99 | + ListMetal3Machines(ctx, clusterClient, client.InNamespace(namespace)) |
| 100 | + ListMachines(ctx, clusterClient, client.InNamespace(namespace)) |
| 101 | + ListNodes(ctx, targetClusterClient) |
| 102 | + |
| 103 | + By("Running Kubernetes n+1 Upgrade tests") |
| 104 | + UpgradeControlPlane(ctx, func() UpgradeControlPlaneInput { |
| 105 | + return UpgradeControlPlaneInput{ |
| 106 | + E2EConfig: e2eConfig, |
| 107 | + BootstrapClusterProxy: bootstrapClusterProxy, |
| 108 | + TargetCluster: targetCluster, |
| 109 | + SpecName: specName, |
| 110 | + ClusterName: clusterName, |
| 111 | + Namespace: namespace, |
| 112 | + K8sFromVersion: kubernetesVersion, |
| 113 | + K8sToVersion: upgradedK8sVersion1, |
| 114 | + } |
| 115 | + }) |
| 116 | + By("KUBERNETES UPGRADE N+1 TESTS PASSED!") |
| 117 | + Logf("KUBERNETES VERSION: %v", upgradedK8sVersion1) |
| 118 | + Logf("UPGRADED K8S VERSION: %v", upgradedK8sVersion2) |
| 119 | + Logf("NUMBER OF CONTROLPLANE BMH: %v", numberOfControlplane) |
| 120 | + |
| 121 | + By("Running Kubernetes N+2 Upgrade tests") |
| 122 | + UpgradeControlPlane(ctx, func() UpgradeControlPlaneInput { |
| 123 | + return UpgradeControlPlaneInput{ |
| 124 | + E2EConfig: e2eConfig, |
| 125 | + BootstrapClusterProxy: bootstrapClusterProxy, |
| 126 | + TargetCluster: targetCluster, |
| 127 | + SpecName: specName, |
| 128 | + ClusterName: clusterName, |
| 129 | + Namespace: namespace, |
| 130 | + K8sFromVersion: upgradedK8sVersion1, |
| 131 | + K8sToVersion: upgradedK8sVersion2, |
| 132 | + } |
| 133 | + }) |
| 134 | + By("KUBERNETES UPGRADE N+2 TESTS PASSED!") |
| 135 | + Logf("KUBERNETES VERSION: %v", upgradedK8sVersion2) |
| 136 | + Logf("UPGRADED K8S VERSION: %v", upgradedK8sVersion3) |
| 137 | + Logf("NUMBER OF CONTROLPLANE BMH: %v", numberOfControlplane) |
| 138 | + |
| 139 | + By("Running Kubernetes n+3 Upgrade tests") |
| 140 | + UpgradeControlPlane(ctx, func() UpgradeControlPlaneInput { |
| 141 | + return UpgradeControlPlaneInput{ |
| 142 | + E2EConfig: e2eConfig, |
| 143 | + BootstrapClusterProxy: bootstrapClusterProxy, |
| 144 | + TargetCluster: targetCluster, |
| 145 | + SpecName: specName, |
| 146 | + ClusterName: clusterName, |
| 147 | + Namespace: namespace, |
| 148 | + K8sFromVersion: upgradedK8sVersion2, |
| 149 | + K8sToVersion: upgradedK8sVersion3, |
| 150 | + } |
| 151 | + }) |
| 152 | + By("KUBERNETES UPGRADE N+3 TESTS PASSED!") |
| 153 | +} |
0 commit comments