-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3506 from devigned/e2e-mp
⚠️ add docker machine pool and e2e tests for machine pool
- Loading branch information
Showing
43 changed files
with
2,113 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
# MachinePool which references the DockerMachinePool and KubeadmConfigTemplate below | ||
apiVersion: exp.cluster.x-k8s.io/v1alpha3 | ||
kind: MachinePool | ||
metadata: | ||
name: "${CLUSTER_NAME}-mp-0" | ||
spec: | ||
clusterName: '${CLUSTER_NAME}' | ||
replicas: ${WORKER_MACHINE_COUNT} | ||
template: | ||
spec: | ||
bootstrap: | ||
configRef: | ||
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3 | ||
kind: KubeadmConfig | ||
name: "${CLUSTER_NAME}-mp-0-config" | ||
clusterName: '${CLUSTER_NAME}' | ||
infrastructureRef: | ||
apiVersion: exp.infrastructure.cluster.x-k8s.io/v1alpha3 | ||
kind: DockerMachinePool | ||
name: "${CLUSTER_NAME}-dmp-0" | ||
version: "${KUBERNETES_VERSION}" | ||
--- | ||
# DockerMachinePool using default values referenced by the MachinePool | ||
apiVersion: exp.infrastructure.cluster.x-k8s.io/v1alpha3 | ||
kind: DockerMachinePool | ||
metadata: | ||
name: "${CLUSTER_NAME}-dmp-0" | ||
--- | ||
# KubeadmConfigTemplate referenced by the MachinePool | ||
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha3 | ||
kind: KubeadmConfig | ||
metadata: | ||
name: "${CLUSTER_NAME}-mp-0-config" | ||
spec: | ||
joinConfiguration: | ||
nodeRegistration: | ||
kubeletExtraArgs: | ||
eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0% |
4 changes: 4 additions & 0 deletions
4
test/e2e/data/infrastructure-docker/cluster-template-machine-pool/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
resources: | ||
- ../bases/cluster-with-kcp.yaml | ||
- ../bases/mp.yaml | ||
- ../bases/crs.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/utils/pointer" | ||
|
||
"sigs.k8s.io/cluster-api/test/framework" | ||
"sigs.k8s.io/cluster-api/test/framework/clusterctl" | ||
"sigs.k8s.io/cluster-api/util" | ||
) | ||
|
||
// MachinePoolInput is the input for MachinePoolSpec | ||
type MachinePoolInput struct { | ||
E2EConfig *clusterctl.E2EConfig | ||
ClusterctlConfigPath string | ||
BootstrapClusterProxy framework.ClusterProxy | ||
ArtifactFolder string | ||
SkipCleanup bool | ||
} | ||
|
||
// MachinePoolSpec implements a test that verifies MachinePool scale up, down and version update | ||
func MachinePoolSpec(ctx context.Context, inputGetter func() MachinePoolInput) { | ||
var ( | ||
specName = "machine-pool" | ||
input MachinePoolInput | ||
namespace *corev1.Namespace | ||
cancelWatches context.CancelFunc | ||
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult | ||
) | ||
|
||
BeforeEach(func() { | ||
Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName) | ||
input = inputGetter() | ||
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName) | ||
Expect(input.ClusterctlConfigPath).To(BeAnExistingFile(), "Invalid argument. input.ClusterctlConfigPath must be an existing file when calling %s spec", specName) | ||
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName) | ||
Expect(os.MkdirAll(input.ArtifactFolder, 0755)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName) | ||
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersionUpgradeTo)) | ||
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersionUpgradeFrom)) | ||
|
||
// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. | ||
namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) | ||
}) | ||
|
||
It("Should successfully create a cluster with machine pool machines", func() { | ||
By("Creating a workload cluster") | ||
workerMachineCount := int32(2) | ||
clusterResources = clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{ | ||
ClusterProxy: input.BootstrapClusterProxy, | ||
ConfigCluster: clusterctl.ConfigClusterInput{ | ||
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", input.BootstrapClusterProxy.GetName()), | ||
ClusterctlConfigPath: input.ClusterctlConfigPath, | ||
KubeconfigPath: input.BootstrapClusterProxy.GetKubeconfigPath(), | ||
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider, | ||
Flavor: "machine-pool", | ||
Namespace: namespace.Name, | ||
ClusterName: fmt.Sprintf("%s-%s", specName, util.RandomString(6)), | ||
KubernetesVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeFrom), | ||
ControlPlaneMachineCount: pointer.Int64Ptr(1), | ||
WorkerMachineCount: pointer.Int64Ptr(int64(workerMachineCount)), | ||
}, | ||
WaitForClusterIntervals: input.E2EConfig.GetIntervals(specName, "wait-cluster"), | ||
WaitForControlPlaneIntervals: input.E2EConfig.GetIntervals(specName, "wait-control-plane"), | ||
WaitForMachinePools: input.E2EConfig.GetIntervals(specName, "wait-machine-pool-nodes"), | ||
}) | ||
|
||
By("Scaling the machine pool up") | ||
framework.ScaleMachinePoolAndWait(context.TODO(), framework.ScaleMachinePoolAndWaitInput{ | ||
ClusterProxy: input.BootstrapClusterProxy, | ||
Cluster: clusterResources.Cluster, | ||
Replicas: workerMachineCount + 1, | ||
MachinePools: clusterResources.MachinePools, | ||
WaitForMachinePoolToScale: input.E2EConfig.GetIntervals(specName, "wait-machine-pool-nodes"), | ||
}) | ||
|
||
By("Scaling the machine pool down") | ||
framework.ScaleMachinePoolAndWait(context.TODO(), framework.ScaleMachinePoolAndWaitInput{ | ||
ClusterProxy: input.BootstrapClusterProxy, | ||
Cluster: clusterResources.Cluster, | ||
Replicas: workerMachineCount - 1, | ||
MachinePools: clusterResources.MachinePools, | ||
WaitForMachinePoolToScale: input.E2EConfig.GetIntervals(specName, "wait-machine-pool-nodes"), | ||
}) | ||
|
||
By("Upgrading the instances") | ||
framework.UpgradeMachinePoolAndWait(context.TODO(), framework.UpgradeMachinePoolAndWaitInput{ | ||
ClusterProxy: input.BootstrapClusterProxy, | ||
Cluster: clusterResources.Cluster, | ||
UpgradeVersion: input.E2EConfig.GetVariable(KubernetesVersionUpgradeTo), | ||
WaitForMachinePoolToBeUpgraded: input.E2EConfig.GetIntervals(specName, "wait-machine-pool-upgrade"), | ||
MachinePools: clusterResources.MachinePools, | ||
}) | ||
|
||
By("PASSED!") | ||
}) | ||
|
||
AfterEach(func() { | ||
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself. | ||
dumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo" | ||
) | ||
|
||
var _ = Describe("When testing MachinePools", func() { | ||
MachinePoolSpec(context.TODO(), func() MachinePoolInput { | ||
return MachinePoolInput{ | ||
E2EConfig: e2eConfig, | ||
ClusterctlConfigPath: clusterctlConfigPath, | ||
BootstrapClusterProxy: bootstrapClusterProxy, | ||
ArtifactFolder: artifactFolder, | ||
SkipCleanup: skipCleanup, | ||
} | ||
}) | ||
}) |
Oops, something went wrong.