Skip to content

Commit 1089d88

Browse files
Simple test for machinepool (#96)
1 parent 861fc62 commit 1089d88

File tree

6 files changed

+102
-1
lines changed

6 files changed

+102
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ generate-e2e-templates: kustomize
263263
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-local-vcn-peering --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-local-vcn-peering.yaml
264264
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-remote-vcn-peering --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-remote-vcn-peering.yaml
265265
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-externally-managed-vcn --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-externally-managed-vcn.yaml
266+
$(KUSTOMIZE) build $(OCI_TEMPLATES)/v1beta1/cluster-template-machine-pool --load_restrictor LoadRestrictionsNone > $(OCI_TEMPLATES)/v1beta1/cluster-template-machine-pool.yaml
266267

267268
.PHONY: test-e2e-run
268269
test-e2e-run: generate-e2e-templates ginkgo $(ENVSUBST) ## Run e2e tests

cloud/scope/machine_pool.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ func (m *MachinePoolScope) SetListandSetMachinePoolInstances(ctx context.Context
182182
providerIDList := make([]string, len(poolInstanceSummaries))
183183

184184
for i, instance := range poolInstanceSummaries {
185-
providerIDList[i] = fmt.Sprintf("oci://%s", *instance.Id)
185+
if *instance.State == "Running" {
186+
providerIDList[i] = fmt.Sprintf("oci://%s", *instance.Id)
187+
}
186188
}
187189

188190
m.OCIMachinePool.Spec.ProviderIDList = providerIDList

test/e2e/cluster_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"k8s.io/utils/pointer"
4242
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4343
capi_e2e "sigs.k8s.io/cluster-api/test/e2e"
44+
"sigs.k8s.io/cluster-api/test/framework"
4445
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
4546
"sigs.k8s.io/cluster-api/util"
4647
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -512,6 +513,48 @@ var _ = Describe("Workload cluster creation", func() {
512513
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
513514
}, result)
514515
})
516+
517+
It("Machine Pool - Simple", func() {
518+
clusterName = getClusterName(clusterNamePrefix, "machine-pool")
519+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
520+
ClusterProxy: bootstrapClusterProxy,
521+
ConfigCluster: clusterctl.ConfigClusterInput{
522+
LogFolder: filepath.Join(artifactFolder, "clusters", bootstrapClusterProxy.GetName()),
523+
ClusterctlConfigPath: clusterctlConfigPath,
524+
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
525+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
526+
Flavor: "machine-pool",
527+
Namespace: namespace.Name,
528+
ClusterName: clusterName,
529+
KubernetesVersion: e2eConfig.GetVariable(capi_e2e.KubernetesVersion),
530+
ControlPlaneMachineCount: pointer.Int64Ptr(1),
531+
WorkerMachineCount: pointer.Int64Ptr(1),
532+
},
533+
CNIManifestPath: e2eConfig.GetVariable(capi_e2e.CNIPath),
534+
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
535+
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
536+
WaitForMachinePools: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
537+
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
538+
}, result)
539+
540+
By("Scaling the machine pool up")
541+
framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
542+
ClusterProxy: bootstrapClusterProxy,
543+
Cluster: result.Cluster,
544+
Replicas: 2,
545+
MachinePools: result.MachinePools,
546+
WaitForMachinePoolToScale: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
547+
})
548+
549+
By("Scaling the machine pool down")
550+
framework.ScaleMachinePoolAndWait(ctx, framework.ScaleMachinePoolAndWaitInput{
551+
ClusterProxy: bootstrapClusterProxy,
552+
Cluster: result.Cluster,
553+
Replicas: 1,
554+
MachinePools: result.MachinePools,
555+
WaitForMachinePoolToScale: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
556+
})
557+
})
515558
})
516559

517560
func verifyMultipleNsgSubnet(ctx context.Context, namespace string, clusterName string, mcDeployments []*clusterv1.MachineDeployment) {

test/e2e/config/e2e_conf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ providers:
6969
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-local-vcn-peering.yaml"
7070
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-remote-vcn-peering.yaml"
7171
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-externally-managed-vcn.yaml"
72+
- sourcePath: "../data/infrastructure-oci/v1beta1/cluster-template-machine-pool.yaml"
7273
- sourcePath: "../data/shared/v1beta1/metadata.yaml"
7374

7475

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bases:
2+
- ../bases/cluster.yaml
3+
- ./machine-pool.yaml
4+
- ../bases/ccm.yaml
5+
6+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
apiVersion: cluster.x-k8s.io/v1beta1
3+
kind: MachinePool
4+
metadata:
5+
name: "${CLUSTER_NAME}-mp-0"
6+
namespace: default
7+
spec:
8+
clusterName: "${CLUSTER_NAME}"
9+
replicas: "${WORKER_MACHINE_COUNT}"
10+
template:
11+
spec:
12+
bootstrap:
13+
configRef:
14+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
15+
kind: KubeadmConfig
16+
name: "${CLUSTER_NAME}-mp-0"
17+
clusterName: "${CLUSTER_NAME}"
18+
infrastructureRef:
19+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
20+
kind: OCIMachinePool
21+
name: "${CLUSTER_NAME}-mp-0"
22+
version: "${KUBERNETES_VERSION}"
23+
---
24+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
25+
kind: OCIMachinePool
26+
metadata:
27+
name: "${CLUSTER_NAME}-mp-0"
28+
namespace: default
29+
spec:
30+
imageId: "${OCI_IMAGE_ID}"
31+
metadata:
32+
ssh_authorized_keys: "${OCI_SSH_KEY}"
33+
shapeConfig:
34+
ocpus: "1"
35+
instanceConfiguration:
36+
instanceDetails:
37+
shape: "${OCI_NODE_MACHINE_TYPE=VM.Standard.E4.Flex}"
38+
---
39+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha4
40+
kind: KubeadmConfig
41+
metadata:
42+
name: "${CLUSTER_NAME}-mp-0"
43+
spec:
44+
joinConfiguration:
45+
nodeRegistration:
46+
kubeletExtraArgs:
47+
cloud-provider: external
48+
provider-id: oci://{{ ds["id"] }}

0 commit comments

Comments
 (0)