Skip to content

Commit 54d6fd0

Browse files
authored
Merge pull request #1848 from Nordix/lentzi90/dev-test-class-update
🌱 Update the dev-test ClusterClass
2 parents cf4ccc5 + d410f82 commit 54d6fd0

File tree

2 files changed

+134
-46
lines changed

2 files changed

+134
-46
lines changed

docs/book/src/development/development.md

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
- [Using your own capi-openstack controller image for testing cluster creation or deletion](#using-your-own-capi-openstack-controller-image-for-testing-cluster-creation-or-deletion)
77
- [Building and upload your own capi-openstack controller image](#building-and-upload-your-own-capi-openstack-controller-image)
88
- [Using your own capi-openstack controller image](#using-your-own-capi-openstack-controller-image)
9-
- [Developing with Tilt](#developing-with-tilt)
9+
- [Testing Cluster Creation using the 'dev-test' ClusterClass with Tilt](#testing-cluster-creation-using-the-dev-test-clusterclass-with-tilt)
10+
- [Developing with Tilt](#developing-with-tilt)
11+
- [Apply ClusterClass and create Cluster](#apply-clusterclass-and-create-cluster)
12+
- [Automatically applying kustomizations with Tilt](#automatically-applying-kustomizations-with-tilt)
13+
- [Using the 'dev-test' ClusterClass without Tilt](#using-the-dev-test-clusterclass-without-tilt)
14+
- [Creating a Kind Cluster](#creating-a-kind-cluster)
15+
- [Secret Configuration](#secret-configuration)
16+
- [Apply the ClusterClass and create Clusters](#apply-the-clusterclass-and-create-clusters)
1017
- [Running E2E tests locally](#running-e2e-tests-locally)
1118
- [Support for clouds using SSL](#support-for-clouds-using-ssl)
1219
- [Support for clouds with multiple external networks](#support-for-clouds-with-multiple-external-networks)
@@ -15,9 +22,13 @@
1522
- [Create E2E test environment](#create-e2e-test-environment)
1623
- [OpenStack](#openstack)
1724
- [DevStack](#devstack)
25+
- [Server side](#server-side)
26+
- [CAPO side](#capo-side)
1827
- [Running E2E tests using rootless podman](#running-e2e-tests-using-rootless-podman)
1928
- [Host configuration](#host-configuration)
2029
- [Running podman system service to emulate docker daemon](#running-podman-system-service-to-emulate-docker-daemon)
30+
- [API concepts](#api-concepts)
31+
- [`referencedResources`](#referencedresources)
2132

2233
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2334

@@ -52,42 +63,28 @@ After generating `infrastructure-components.yaml`, replace the `us.gcr.io/k8s-ar
5263

5364
## Testing Cluster Creation using the 'dev-test' ClusterClass with Tilt
5465

55-
This guide demonstrates how to create a Kubernetes cluster using ClusterClass, specifically designed for a development environment. It includes initializing a Kind cluster, configuring secrets, and applying ClusterClass to deploy your cluster with Tilt.
66+
This guide demonstrates how to create a Kubernetes cluster using a ClusterClass, specifically designed for a development environment. It includes configuring secrets, applying the ClusterClass, and creating a cluster with Tilt.
5667

57-
### Creating a Kind Cluster
58-
59-
Create a Kind cluster. This process involves the initialization of Cluster API providers for OpenStack.
68+
The `dev-test` ClusterClass is designed for development.
69+
This means that it is using the latest (potentially unstable) API version.
70+
The defaults are also aligned with the devstack setup (documented below) to make it as easy as possible to use in a development flow.
71+
However, this also means that it may *not* be well suited for general usage.
6072

61-
```bash
62-
kind create cluster
63-
export CLUSTER_TOPOLOGY=true
64-
clusterctl init --infrastructure openstack
65-
```
66-
67-
### Secret Configuration
68-
69-
CAPO needs a clouds.yaml file in order to manage the OpenStack resources needed for the Cluster. This should be supplied as a secret named `${CLUSTER_NAME}-cloud-config`. You can create this secret for example with:
70-
71-
```bash
72-
kubectl create secret generic ${CLUSTER_NAME}-cloud-config --from-file=clouds.yaml
73-
```
74-
75-
You can also make Tilt create it for you when you run `tilt up`, more on that in the next section.
76-
77-
## Developing with Tilt
73+
### Developing with Tilt
7874

7975
We have support for using [Tilt](https://tilt.dev/) for rapid iterative development. Please visit the [Cluster API documentation on Tilt](https://cluster-api.sigs.k8s.io/developer/tilt.html) for information on how to set up your development environment.
8076

81-
Default values align with the devstack setup, as documented below. When specifying the `KUBERNETES_VERSION`, ensure an image named `ubuntu-2204-kube-{{ KUBERNETES_VERSION }}` is available in your environment, corresponding to that Kubernetes version.
82-
For using Tilt with ClusterClass, update your `tilt-settings.yaml` file as described:
77+
The `Tiltfile` in the Cluster API repository can be used as is with CAPO, but we need to add some configuration.
78+
For using Tilt with ClusterClass, update your `tilt-settings.yaml` file (located in the root of the CAPI repository) as described:
8379

8480
```yaml
81+
template_dirs:
82+
openstack:
83+
# Make Tilt aware of the CAPO templates
84+
- ../cluster-api-provider-openstack/templates
85+
8586
kustomize_substitutions:
8687
CLUSTER_TOPOLOGY: "true"
87-
# Define the name of your cluster (e.g., "dev-test")
88-
CLUSTER_NAME: "<cluster_name>"
89-
# Desired Kubernetes Version for Your Cluster (e.g., "v1.28.5")
90-
KUBERNETES_VERSION: "<kubernetes_version>"
9188
# [Optional] SSH Keypair Name for Instances in OpenStack (Default: "")
9289
OPENSTACK_SSH_KEY_NAME: "<openstack_keypair_name>"
9390
# [Optional] Control Plane Machine Flavor (Default: m1.medium)
@@ -97,10 +94,30 @@ kustomize_substitutions:
9794
# [Optional] OpenStack Cloud Environment (Default: capo-e2e)
9895
OPENSTACK_CLOUD: "<openstack_cloud>"
9996

97+
# [Optional] Automatically apply a kustomization, e.g. for adding the clouds.yaml secret
10098
additional_kustomizations:
10199
secret_kustomization: /path/to/kustomize/secret/configuration
102100
```
103101
102+
### Apply ClusterClass and create Cluster
103+
104+
When you are happy with the configuration, start the environment as explained in the CAPI documentation.
105+
Open the Tilt dashboard in your browser.
106+
After a while, you should be able to find resources called `CAPO.clusterclasses` and `CAPO.templates`.
107+
These shoud correspond to what exists in the `templates` folder and you should see widgets for applying and deleting them.
108+
109+
**Note:** When you apply a cluster template, there will be a `KUBERNETES_VERSION` variable.
110+
This variable is used to pick the image used!
111+
Ensure that an image named `ubuntu-2204-kube-{{ KUBERNETES_VERSION }}` is available in your environment, corresponding to that Kubernetes version.
112+
113+
**Note:** All clusters created from the dev-test ClusterClass will require a secret named `dev-test-cloud-config` with the `clouds.yaml` to be used by CAPO for interacting with OpenStack.
114+
You can create it manually or see below how to make Tilt automate it.
115+
116+
### Automatically applying kustomizations with Tilt
117+
118+
This explains how to automatically create the secret containing `clouds.yaml`.
119+
The same procedure can be used for any other things you want to create in the cluster.
120+
104121
Ensure the specified path (`/path/to/kustomize/secret/configuration`) contains both the `clouds.yaml` file and a `kustomization.yaml` file. The `kustomization.yaml` should define the necessary resources, such as a Kubernetes secret, using the `clouds.yaml` file.
105122

106123
For example, if you want to automatically create a secret named `dev-test-cloud-config` with the content of your `clouds.yaml` every time you do `tilt up`, you could do the following.
@@ -144,11 +161,51 @@ secretGenerator:
144161
type: Opaque
145162
```
146163

147-
If you now add `/tmp/capo-dev` to the `additional_kustomizations`, tilt will automatically apply
148-
the secret when you do `tilt up`.
164+
If you now add `/tmp/capo-dev` to the `additional_kustomizations`, tilt will automatically apply
165+
the secret.
149166

150167
To check that the kustomization produces the desired output, do `kustomize build /tmp/capo-dev`.
151168

169+
## Using the 'dev-test' ClusterClass without Tilt
170+
171+
If you want to use the ClusterClass without Tilt, you will need to follow these steps instead of the above.
172+
173+
### Creating a Kind Cluster
174+
175+
Create a Kind cluster and deploy CAPO.
176+
177+
**Note:** As the dev-test ClusterClass is made for development, it may be using a newer API version than what is in the latest release.
178+
You *will need* to [use local artifacts](https://cluster-api.sigs.k8s.io/clusterctl/developers#use-local-artifacts) for this to work in most cases!
179+
180+
```bash
181+
kind create cluster
182+
export CLUSTER_TOPOLOGY=true
183+
clusterctl init --infrastructure openstack
184+
```
185+
186+
### Secret Configuration
187+
188+
CAPO needs a clouds.yaml file in order to manage the OpenStack resources needed for the Cluster. This should be supplied as a secret named `dev-test-cloud-config`. You can create this secret for example with:
189+
190+
```bash
191+
kubectl create secret generic dev-test-cloud-config --from-file=clouds.yaml
192+
```
193+
194+
### Apply the ClusterClass and create Clusters
195+
196+
You can use `clusterctl` to render the ClusterClass:
197+
198+
```bash
199+
clusterctl generate yaml --from templates/clusterclass-dev-test.yaml
200+
```
201+
202+
Create a cluster using the development template, that makes use of the ClusterClass:
203+
204+
```bash
205+
clusterctl generate cluster my-cluster --kubernetes-version=v1.29.0 --from templates/cluster-template-development.yaml > my-cluster.yaml
206+
kubectl apply -f my-cluster.yaml
207+
```
208+
152209
## Running E2E tests locally
153210

154211
You can run the E2E tests locally with:
@@ -445,4 +502,4 @@ This sections goal is to gather various insights into the API design that can se
445502

446503
Starting from v1alpha8 both `OpenStackMachineStatus` and `BastionsStatus` feature a field named `referencedResources` which aims to include fields that list individual IDs of the resources associated with the machine or bastion. These IDs are calculated on machine or bastion creation and are not intended to be changed during the object lifecycle.
447504

448-
Having all the IDs of related resources saved in the statuses allows CAPO to make easy decisions about deleting the related resources when deleting the VM corresponding to the machine or bastion.
505+
Having all the IDs of related resources saved in the statuses allows CAPO to make easy decisions about deleting the related resources when deleting the VM corresponding to the machine or bastion.

templates/clusterclass-dev-test.yaml

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ spec:
77
ref:
88
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
99
kind: KubeadmControlPlaneTemplate
10-
name: ${CLUSTER_NAME}-control-plane-template
10+
name: dev-test-control-plane
1111
machineInfrastructure:
1212
ref:
1313
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
1414
kind: OpenStackMachineTemplate
15-
name: ${CLUSTER_NAME}-control-plane-machine-template
15+
name: dev-test-control-plane-machine
1616
infrastructure:
1717
ref:
1818
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
1919
kind: OpenStackClusterTemplate
20-
name: ${CLUSTER_NAME}-openstackcluster-template
20+
name: dev-test-openstackcluster
2121
workers:
2222
machineDeployments:
2323
- class: default-worker
@@ -26,17 +26,48 @@ spec:
2626
ref:
2727
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
2828
kind: KubeadmConfigTemplate
29-
name: ${CLUSTER_NAME}-default-worker-bootstraptemplate
29+
name: dev-test-default-worker-bootstraptemplate
3030
infrastructure:
3131
ref:
3232
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
3333
kind: OpenStackMachineTemplate
34-
name: ${CLUSTER_NAME}-default-worker-machine-template
34+
name: dev-test-default-worker-machine
35+
patches:
36+
- name: controlPlaneImage
37+
description: "Sets the OpenStack image that is used for creating the servers."
38+
definitions:
39+
- selector:
40+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
41+
kind: OpenStackMachineTemplate
42+
matchResources:
43+
controlPlane: true
44+
jsonPatches:
45+
- op: add
46+
path: /spec/template/spec/image/name
47+
valueFrom:
48+
template: |
49+
ubuntu-2204-kube-{{ .builtin.controlPlane.version }}
50+
- name: workerImage
51+
description: "Sets the OpenStack image that is used for creating the servers."
52+
definitions:
53+
- selector:
54+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
55+
kind: OpenStackMachineTemplate
56+
matchResources:
57+
machineDeploymentClass:
58+
names:
59+
- default-worker
60+
jsonPatches:
61+
- op: add
62+
path: /spec/template/spec/image/name
63+
valueFrom:
64+
template: |
65+
ubuntu-2204-kube-{{ .builtin.machineDeployment.version }}
3566
---
3667
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
3768
kind: KubeadmConfigTemplate
3869
metadata:
39-
name: ${CLUSTER_NAME}-default-worker-bootstraptemplate
70+
name: dev-test-default-worker-bootstraptemplate
4071
spec:
4172
template:
4273
spec:
@@ -51,7 +82,7 @@ spec:
5182
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
5283
kind: KubeadmControlPlaneTemplate
5384
metadata:
54-
name: ${CLUSTER_NAME}-control-plane-template
85+
name: dev-test-control-plane
5586
spec:
5687
template:
5788
spec:
@@ -80,7 +111,7 @@ spec:
80111
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
81112
kind: OpenStackClusterTemplate
82113
metadata:
83-
name: ${CLUSTER_NAME}-openstackcluster-template
114+
name: dev-test-openstackcluster
84115
spec:
85116
template:
86117
spec:
@@ -91,38 +122,38 @@ spec:
91122
- 8.8.8.8
92123
identityRef:
93124
kind: Secret
94-
name: ${CLUSTER_NAME}-cloud-config
125+
name: dev-test-cloud-config
95126
managedSecurityGroups: true
96127
nodeCidr: 10.6.0.0/24
97128
---
98129
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
99130
kind: OpenStackMachineTemplate
100131
metadata:
101-
name: ${CLUSTER_NAME}-control-plane-machine-template
132+
name: dev-test-control-plane-machine
102133
spec:
103134
template:
104135
spec:
105136
cloudName: ${OPENSTACK_CLOUD:=capo-e2e}
106137
flavor: ${OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR:=m1.medium}
107138
identityRef:
108139
kind: Secret
109-
name: ${CLUSTER_NAME}-cloud-config
140+
name: dev-test-cloud-config
110141
image:
111-
name: ubuntu-2204-kube-${KUBERNETES_VERSION}
142+
name: overridden-by-patch
112143
sshKeyName: ${OPENSTACK_SSH_KEY_NAME:=""}
113144
---
114145
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8
115146
kind: OpenStackMachineTemplate
116147
metadata:
117-
name: ${CLUSTER_NAME}-default-worker-machine-template
148+
name: dev-test-default-worker-machine
118149
spec:
119150
template:
120151
spec:
121152
cloudName: ${OPENSTACK_CLOUD:=capo-e2e}
122153
flavor: ${OPENSTACK_NODE_MACHINE_FLAVOR:=m1.small}
123154
identityRef:
124155
kind: Secret
125-
name: ${CLUSTER_NAME}-cloud-config
156+
name: dev-test-cloud-config
126157
image:
127-
name: ubuntu-2204-kube-${KUBERNETES_VERSION}
158+
name: overridden-by-patch
128159
sshKeyName: ${OPENSTACK_SSH_KEY_NAME:=""}

0 commit comments

Comments
 (0)