Skip to content

Commit 3bf9016

Browse files
committed
feat: initial tests
1 parent 6477166 commit 3bf9016

File tree

10 files changed

+489
-105
lines changed

10 files changed

+489
-105
lines changed

Makefile

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,33 +107,38 @@ test-e2e-controller: manifests generate update-test-crds fmt vet ## Run the e2e
107107
}
108108
go test ./test/e2e/ -v -ginkgo.v
109109

110-
E2E_METAL_API_URL := "$(METALCTL_API_URL)"
111-
E2E_METAL_API_HMAC := "$(METALCTL_HMAC)"
112-
E2E_METAL_API_HMAC_AUTH_TYPE := "$(or $(METALCTL_HMAC_AUTH_TYPE),Metal-Admin)"
113-
E2E_METAL_PROJECT_ID := "00000000-0000-0000-0000-000000000001"
114-
E2E_METAL_PARTITION := "mini-lab"
115-
E2E_METAL_PUBLIC_NETWORK := "internet-mini-lab"
116-
E2E_CONTROL_PLANE_MACHINE_IMAGE := "capms-ubuntu-1.33.5"
117-
E2E_CONTROL_PLANE_MACHINE_SIZE := "v1-small-x86"
118-
E2E_WORKER_MACHINE_IMAGE := "capms-ubuntu-1.33.5"
119-
E2E_WORKER_MACHINE_SIZE := "v1-small-x86"
120-
E2E_FIREWALL_IMAGE := "firewall-ubuntu-3.0"
121-
E2E_FIREWALL_SIZE := "v1-small-x86"
122-
E2E_FIREWALL_NETWORKS := "internet-mini-lab"
110+
E2E_METAL_API_URL ?= "$(METALCTL_API_URL)"
111+
E2E_METAL_API_HMAC ?= "$(METALCTL_HMAC)"
112+
E2E_METAL_API_HMAC_AUTH_TYPE ?= "$(or $(METALCTL_HMAC_AUTH_TYPE),Metal-Admin)"
113+
E2E_METAL_PROJECT_ID ?= "00000000-0000-0000-0000-000000000001"
114+
E2E_METAL_PARTITION ?= "mini-lab"
115+
E2E_METAL_PUBLIC_NETWORK ?= "internet-mini-lab"
116+
E2E_KUBERNETES_VERSIONS ?= "v1.32.9,v1.33.5,v1.34.1"
117+
E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX ?= "capms-ubuntu-"
118+
E2E_CONTROL_PLANE_MACHINE_SIZE ?= "v1-small-x86"
119+
E2E_WORKER_MACHINE_IMAGE_PREFIX ?= "capms-ubuntu-"
120+
E2E_WORKER_MACHINE_SIZE ?= "v1-small-x86"
121+
E2E_FIREWALL_IMAGE ?= "firewall-ubuntu-3.0"
122+
E2E_FIREWALL_SIZE ?= "v1-small-x86"
123+
E2E_FIREWALL_NETWORKS ?= "internet-mini-lab"
123124

124125
.PHONY: test-e2e
125126
test-e2e: manifests generate fmt vet
126127
rm -rf test/e2e/frmwrk/artifacts
127128

128-
METAL_API_URL=$(E2E_METAL_API_URL) \
129+
mkdir -p test/e2e/frmwrk/artifacts/config/target
130+
kubectl kustomize test/e2e/frmwrk/config/target/base -o test/e2e/frmwrk/artifacts/config/target/base.yaml
131+
132+
@METAL_API_URL=$(E2E_METAL_API_URL) \
129133
METAL_API_HMAC=$(E2E_METAL_API_HMAC) \
130134
METAL_API_HMAC_AUTH_TYPE=$(E2E_METAL_API_HMAC_AUTH_TYPE) \
131135
METAL_PROJECT_ID=$(E2E_METAL_PROJECT_ID) \
132136
METAL_PARTITION=$(E2E_METAL_PARTITION) \
133137
METAL_PUBLIC_NETWORK=$(E2E_METAL_PUBLIC_NETWORK) \
134-
CONTROL_PLANE_MACHINE_IMAGE=$(E2E_CONTROL_PLANE_MACHINE_IMAGE) \
138+
E2E_KUBERNETES_VERSIONS=$(E2E_KUBERNETES_VERSIONS) \
139+
E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX=$(E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX) \
135140
CONTROL_PLANE_MACHINE_SIZE=$(E2E_CONTROL_PLANE_MACHINE_SIZE) \
136-
WORKER_MACHINE_IMAGE=$(E2E_WORKER_MACHINE_IMAGE) \
141+
E2E_WORKER_MACHINE_IMAGE_PREFIX=$(E2E_WORKER_MACHINE_IMAGE_PREFIX) \
137142
WORKER_MACHINE_SIZE=$(E2E_WORKER_MACHINE_SIZE) \
138143
FIREWALL_IMAGE=$(E2E_FIREWALL_IMAGE) \
139144
FIREWALL_SIZE=$(E2E_FIREWALL_SIZE) \
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resources:
2+
- ./metal-ccm.yaml

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
k8s.io/api v0.32.3
1414
k8s.io/apimachinery v0.32.3
1515
k8s.io/client-go v0.32.3
16+
k8s.io/klog/v2 v2.130.1
1617
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
1718
sigs.k8s.io/cluster-api v1.10.6
1819
sigs.k8s.io/cluster-api/test v1.10.6
@@ -167,7 +168,6 @@ require (
167168
k8s.io/apiserver v0.32.3 // indirect
168169
k8s.io/cluster-bootstrap v0.32.3 // indirect
169170
k8s.io/component-base v0.32.3 // indirect
170-
k8s.io/klog/v2 v2.130.1 // indirect
171171
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
172172
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
173173
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect

test/e2e/frmwrk/bootstrap_test.go

Lines changed: 91 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,89 +2,114 @@ package frmwrk
22

33
import (
44
"context"
5+
"fmt"
6+
"os"
7+
"path"
8+
"strings"
59

610
. "github.com/onsi/ginkgo/v2"
711
. "github.com/onsi/gomega"
812

9-
// v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10-
// controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
13+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
1115
"sigs.k8s.io/cluster-api/test/framework"
1216
)
1317

1418
var _ = Describe("Basic Cluster Creation", Ordered, func() {
19+
var (
20+
ec *E2ECluster
21+
)
22+
1523
BeforeAll(func() {
1624
e2eCtx = NewE2EContext()
1725
e2eCtx.ProvideBootstrapCluster()
1826
e2eCtx.CreateClusterctlConfig(context.TODO())
1927
e2eCtx.InitManagementCluster(context.TODO())
28+
29+
DeferCleanup(e2eCtx.Teardown, context.TODO())
2030
})
2131

22-
It("create", func() {
23-
// TODO:
24-
// - access kind cluster
25-
// - install capms
26-
// - create a namespace
27-
// - create node network
28-
// - create firewall
29-
// - create control plane IP
30-
// - create cluster
31-
32-
ctx := context.Background()
33-
34-
ec := e2eCtx.NewE2ECluster(ClusterConfig{
35-
SpecName: "basic-cluster-creation",
36-
NamespaceName: "simple",
37-
ClusterName: "simple",
38-
KubernetesVersion: "v1.34.1",
39-
ControlPlaneIP: "203.0.113.130",
40-
ControlPlaneMachineCount: 1,
41-
WorkerMachineCount: 1,
42-
})
43-
defer ec.Teardown(ctx)
44-
45-
ec.SetupMetalStackPreconditions(ctx)
46-
ec.SetupNamespace(ctx)
47-
ec.GenerateAndApplyClusterTemplate(ctx)
48-
49-
By("Wait for cluster")
50-
cluster := framework.DiscoveryAndWaitForCluster(ctx, framework.DiscoveryAndWaitForClusterInput{
51-
Namespace: ec.NamespaceName,
52-
Name: ec.ClusterName,
53-
Getter: e2eCtx.Environment.Bootstrap.GetClient(),
54-
}, e2eCtx.E2EConfig.GetIntervals("default", "wait-cluster")...)
55-
56-
controlPlane := framework.GetKubeadmControlPlaneByCluster(ctx, framework.GetKubeadmControlPlaneByClusterInput{
57-
Lister: e2eCtx.Environment.Bootstrap.GetClient(),
58-
ClusterName: cluster.Name,
59-
Namespace: cluster.Namespace,
32+
BeforeEach(func() {
33+
ec = nil
34+
})
35+
36+
kubernetesVersions := strings.Split(os.Getenv("E2E_KUBERNETES_VERSIONS"), ",")
37+
Expect(kubernetesVersions).ToNot(BeEmpty(), "E2E_KUBERNETES_VERSIONS must be set")
38+
39+
for _, v := range kubernetesVersions {
40+
It(fmt.Sprintf("create new cluster with kubernetes %s", v), func() {
41+
ctx := context.Background()
42+
43+
ec = createE2ECluster(ctx, e2eCtx, ClusterConfig{
44+
SpecName: "basic-cluster-creation-" + v,
45+
NamespaceName: "simple-" + v,
46+
ClusterName: "simple",
47+
KubernetesVersion: v,
48+
ControlPlaneMachineImage: os.Getenv("E2E_CONTROL_PLANE_MACHINE_IMAGE_PREFIX") + strings.TrimPrefix(v, "v"),
49+
ControlPlaneMachineCount: 1,
50+
WorkerMachineImage: os.Getenv("E2E_WORKER_MACHINE_IMAGE_PREFIX") + strings.TrimPrefix(v, "v"),
51+
WorkerMachineCount: 1,
52+
})
53+
Expect(ec).ToNot(BeNil())
6054
})
55+
}
56+
})
6157

62-
Expect(controlPlane).To(Not(BeNil()))
63-
64-
// framework.WaitForKubeadmControlPlaneMachinesToExist(ctx, framework.WaitForKubeadmControlPlaneMachinesToExistInput{
65-
// Lister: e2eCtx.Environment.Bootstrap.GetClient(),
66-
// Cluster: cluster,
67-
// ControlPlane: controlPlane,
68-
// }, e2eCtx.E2EConfig.GetIntervals("default", "wait-control-plane")...)
69-
// framework.DiscoveryAndWaitForControlPlaneInitialized(ctx, framework.DiscoveryAndWaitForControlPlaneInitializedInput{
70-
// Lister: e2eCtx.Environment.Bootstrap.GetClient(),
71-
// Cluster: cluster,
72-
// }, e2eCtx.E2EConfig.GetIntervals("default", "wait-control-plane")...)
73-
74-
// By("Wait for control plane")
75-
// framework.WaitForControlPlaneToBeReady(ctx, framework.WaitForControlPlaneToBeReadyInput{
76-
// Getter: e2eCtx.Environment.Bootstrap.GetClient(),
77-
// ControlPlane: &controlplanev1.KubeadmControlPlane{
78-
// ObjectMeta: v1.ObjectMeta{
79-
// Name: ec.ClusterName,
80-
// Namespace: ec.NamespaceName,
81-
// },
82-
// },
83-
// }, e2eCtx.E2EConfig.GetIntervals("default", "wait-control-plane")...)
58+
func createE2ECluster(ctx context.Context, e2eCtx *E2EContext, cfg ClusterConfig) *E2ECluster {
59+
ec := e2eCtx.NewE2ECluster(cfg)
60+
DeferCleanup(ec.Teardown, ctx)
8461

85-
})
62+
ec.SetupMetalStackPreconditions(ctx)
63+
ec.SetupNamespace(ctx)
64+
ec.GenerateAndApplyClusterTemplate(ctx)
8665

87-
AfterAll(func() {
88-
e2eCtx.Teardown(context.TODO())
66+
By("Wait for cluster")
67+
cluster := framework.DiscoveryAndWaitForCluster(ctx, framework.DiscoveryAndWaitForClusterInput{
68+
Namespace: ec.NamespaceName,
69+
Name: ec.ClusterName,
70+
Getter: e2eCtx.Environment.Bootstrap.GetClient(),
71+
}, e2eCtx.E2EConfig.GetIntervals("default", "wait-cluster")...)
72+
73+
controlPlane := framework.GetKubeadmControlPlaneByCluster(ctx, framework.GetKubeadmControlPlaneByClusterInput{
74+
Lister: e2eCtx.Environment.Bootstrap.GetClient(),
75+
ClusterName: cluster.Name,
76+
Namespace: cluster.Namespace,
8977
})
90-
})
78+
79+
Expect(controlPlane).To(Not(BeNil()))
80+
81+
targetResources, err := os.ReadFile(path.Join(e2eCtx.Environment.artifactsPath, "config", "target", "base.yaml"))
82+
Expect(err).ToNot(HaveOccurred())
83+
84+
err = ec.Refs.Workload.CreateOrUpdate(ctx, targetResources)
85+
Expect(err).ToNot(HaveOccurred())
86+
87+
framework.WaitForKubeadmControlPlaneMachinesToExist(ctx, framework.WaitForKubeadmControlPlaneMachinesToExistInput{
88+
Lister: e2eCtx.Environment.Bootstrap.GetClient(),
89+
Cluster: cluster,
90+
ControlPlane: controlPlane,
91+
}, e2eCtx.E2EConfig.GetIntervals("default", "wait-control-plane")...)
92+
framework.DiscoveryAndWaitForControlPlaneInitialized(ctx, framework.DiscoveryAndWaitForControlPlaneInitializedInput{
93+
Lister: e2eCtx.Environment.Bootstrap.GetClient(),
94+
Cluster: cluster,
95+
}, e2eCtx.E2EConfig.GetIntervals("default", "wait-control-plane")...)
96+
97+
By("Wait for control plane")
98+
framework.WaitForControlPlaneToBeReady(ctx, framework.WaitForControlPlaneToBeReadyInput{
99+
Getter: e2eCtx.Environment.Bootstrap.GetClient(),
100+
ControlPlane: &controlplanev1.KubeadmControlPlane{
101+
ObjectMeta: metav1.ObjectMeta{
102+
Name: ec.ClusterName,
103+
Namespace: ec.NamespaceName,
104+
},
105+
},
106+
}, e2eCtx.E2EConfig.GetIntervals("default", "wait-control-plane")...)
107+
108+
framework.WaitForClusterMachinesReady(ctx, framework.WaitForClusterMachinesReadyInput{
109+
Cluster: cluster,
110+
GetLister: e2eCtx.Environment.Bootstrap.GetClient(),
111+
NodeGetter: e2eCtx.Environment.Bootstrap.GetClient(),
112+
}, e2eCtx.E2EConfig.GetIntervals("default", "wait-workers")...)
113+
114+
return ec
115+
}

test/e2e/frmwrk/config/capi-e2e-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ providers:
109109
files:
110110
- sourcePath: "../../../../metadata.yaml"
111111
- sourcePath: "../../../../config/clusterctl-templates/cluster-template.yaml"
112+
- sourcePath: "../../../../config/cluster-resource-sets/calico-resource-set.yaml"
113+
- sourcePath: "../../../../config/cluster-resource-sets/metal-ccm-resource-set.yaml"
114+
- sourcePath: "../../../../config/cluster-resource-sets/metallb-resource-set.yaml"
112115
replacements:
113116
- old: --metrics-addr=127.0.0.1:8080
114117
new: --metrics-addr=:8080
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: operator.tigera.io/v1
2+
kind: Installation
3+
metadata:
4+
name: default
5+
spec:
6+
# Configures Calico networking.
7+
calicoNetwork:
8+
bgp: Disabled
9+
ipPools:
10+
- name: default-ipv4-ippool
11+
blockSize: 26
12+
cidr: 10.240.0.0/12
13+
encapsulation: None
14+
mtu: 1440
15+
cni:
16+
ipam:
17+
type: HostLocal
18+
type: Calico
19+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- ./metal-ccm.yaml
6+
- https://raw.githubusercontent.com/projectcalico/calico/v3.28.2/manifests/tigera-operator.yaml
7+
- ./cni-calico-installation.yaml
8+
- github.com/metallb/metallb/config/native?ref=v0.14.9
9+
10+
patches:
11+
- path: ./metallb-speaker.yaml

0 commit comments

Comments
 (0)