Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 3b1b439

Browse files
michal-gubrickymatofeder
authored andcommitted
Make development with Tilt easier
Signed-off-by: michal.gubricky <[email protected]>
1 parent 542bd3e commit 3b1b439

File tree

8 files changed

+108
-32
lines changed

8 files changed

+108
-32
lines changed

.envrc.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ export CLUSTER_TOPOLOGY=true
1010
export EXP_RUNTIME_SDK=true
1111
export EXP_MACHINE_SET_PREFLIGHT_CHECKS=true
1212
export CLUSTER_NAME=test-dfkhje
13+
export SECRET_NAME=supersecret
14+
export CLOUD_NAME=test
15+
export ENCODED_CLOUDS_YAML=mybase64encodedcloudsyamlfile

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ all-tools: $(GOTESTSUM) $(go-cover-treemap) $(go-binsize-treemap) $(KIND) $(PACK
166166
##@ Development
167167

168168
env-vars-for-wl-cluster:
169-
@./hack/ensure-env-variables.sh GIT_PROVIDER_B64 GIT_ACCESS_TOKEN_B64 GIT_ORG_NAME_B64 GIT_REPOSITORY_NAME_B64 EXP_CLUSTER_RESOURCE_SET CLUSTER_TOPOLOGY CLUSTER_NAME
169+
@./hack/ensure-env-variables.sh GIT_PROVIDER_B64 GIT_ACCESS_TOKEN_B64 GIT_ORG_NAME_B64 GIT_REPOSITORY_NAME_B64 EXP_CLUSTER_RESOURCE_SET CLUSTER_TOPOLOGY CLUSTER_NAME SECRET_NAME CLOUD_NAME ENCODED_CLOUDS_YAML
170170

171171
.PHONY: cluster
172172
cluster: $(CTLPTL) $(KUBECTL) ## Creates kind-dev Cluster
@@ -569,6 +569,9 @@ builder-image-push: ## Build $(CONTROLLER_SHORT)-builder to a new version. For m
569569
# .PHONY: test
570570
# test: test-unit test-integration ## Runs all unit and integration tests.
571571

572+
create-workload-cluster-openstack: $(ENVSUBST) $(KUBECTL)
573+
cat .cluster.yaml | $(ENVSUBST) - | $(KUBECTL) apply -f -
574+
572575
.PHONY: tilt-up
573576
tilt-up: env-vars-for-wl-cluster $(ENVSUBST) $(KUBECTL) $(KUSTOMIZE) $(TILT) cluster ## Start a mgt-cluster & Tilt. Installs the CRDs and deploys the controllers
574577
EXP_CLUSTER_RESOURCE_SET=true $(TILT) up --port=10351

Tiltfile

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ def prepare_environment():
7777
local("kubectl create namespace cluster --dry-run=client -o yaml | kubectl apply -f -")
7878

7979
# if it's already present then don't copy
80-
# if not os.path.exists('.clusterstack.yaml'):
81-
# local("cp config/cspo/clusterstack.yaml .clusterstack.yaml")
80+
if not os.path.exists('.clusterstack.yaml'):
81+
local("cp config/cspo/clusterstack.yaml .clusterstack.yaml")
8282

83-
# k8s_yaml('.clusterstack.yaml')
83+
k8s_yaml('.clusterstack.yaml')
8484

85-
# if not os.path.exists('.cluster.yaml'):
86-
# local("cp config/cspo/cluster.yaml .cluster.yaml")
85+
if not os.path.exists('.secret.yaml'):
86+
local("cp config/cspo/secret.yaml .secret.yaml")
87+
88+
if not os.path.exists('.cluster.yaml'):
89+
local("cp config/cspo/cluster.yaml .cluster.yaml")
90+
91+
if not os.path.exists('.clusterstacktemplate.yaml'):
92+
local("cp config/cspo/clusterstacktemplate.yaml .clusterstacktemplate.yaml")
8793

8894
def patch_args_with_extra_args(namespace, name, extra_args):
8995
args_str = str(local("kubectl get deployments {} -n {} -o jsonpath='{{.spec.template.spec.containers[0].args}}'".format(name, namespace)))
@@ -193,8 +199,16 @@ def deploy_cspo():
193199
labels = ["cspo"],
194200
)
195201

196-
# def clusterstack():
197-
# k8s_resource(objects = ["clusterstack:clusterstack"], new_name = "clusterstack", labels = ["CLUSTERSTACK"])
202+
def create_secret():
203+
cmd = "cat .secret.yaml | {} | kubectl apply -f -".format(envsubst_cmd)
204+
local_resource('supersecret', cmd, labels=["clouds-yaml-secret"])
205+
206+
def clusterstack_template():
207+
cmd = "cat .clusterstacktemplate.yaml | {} | kubectl apply -f -".format(envsubst_cmd)
208+
local_resource('cspotemplate', cmd, labels=["cspo-template"])
209+
210+
def clusterstack():
211+
k8s_resource(objects = ["clusterstack:clusterstack"], new_name = "clusterstack", labels = ["clusterstack"])
198212

199213
def base64_encode(to_encode):
200214
encode_blob = local("echo '{}' | tr -d '\n' | base64 - | tr -d '\n'".format(to_encode), quiet = True)
@@ -260,6 +274,19 @@ deploy_cspo()
260274

261275
deploy_capo()
262276

277+
clusterstack()
278+
263279
waitforsystem()
264280

265-
prepare_environment()
281+
prepare_environment()
282+
283+
create_secret()
284+
285+
clusterstack_template()
286+
287+
cmd_button(
288+
"create workload cluster",
289+
argv=["make", "create-workload-cluster-openstack"],
290+
location=location.NAV,
291+
icon_name="add_circle",
292+
)

config/cspo/cluster.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: Cluster
3+
metadata:
4+
name: "${CLUSTER_NAME}"
5+
namespace: cluster
6+
spec:
7+
clusterNetwork:
8+
services:
9+
cidrBlocks: ["10.128.0.0/12"]
10+
pods:
11+
cidrBlocks: ["192.168.0.0/16"]
12+
serviceDomain: "cluster.local"
13+
topology:
14+
class: openstack-ferrol-1-27-v1
15+
controlPlane:
16+
metadata: {}
17+
replicas: 1
18+
variables:
19+
- name: imageRepository
20+
value: ""
21+
version: v1.27.3
22+
workers:
23+
machineDeployments:
24+
- class: workeramd64
25+
name: md-0
26+
replicas: 1
27+
failureDomain: nova

config/cspo/clusterstack.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: clusterstack.x-k8s.io/v1alpha1
2+
kind: ClusterStack
3+
metadata:
4+
name: clusterstack
5+
namespace: cluster
6+
spec:
7+
provider: openstack
8+
name: ferrol
9+
kubernetesVersion: "1.27"
10+
channel: stable
11+
autoSubscribe: false
12+
providerRef:
13+
apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
14+
kind: OpenStackClusterStackReleaseTemplate
15+
name: cspotemplate
16+
versions:
17+
- v1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: infrastructure.clusterstack.x-k8s.io/v1alpha1
2+
kind: OpenStackClusterStackReleaseTemplate
3+
metadata:
4+
name: cspotemplate
5+
namespace: cluster
6+
spec:
7+
template:
8+
spec:
9+
cloudName: "${CLOUD_NAME}"
10+
identityRef:
11+
kind: Secret
12+
name: "${SECRET_NAME}"

config/cspo/secret.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
data:
3+
clouds.yaml: ${ENCODED_CLOUDS_YAML}
4+
kind: Secret
5+
metadata:
6+
name: "${SECRET_NAME}"
7+
namespace: cluster

docs/develop.md

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,12 @@ make tilt-up
2424

2525
> To access the Tilt UI please go to: `http://localhost:10351`
2626
27-
You should make sure that everything in the UI looks green. If not, you can trigger the Tilt workflow again. To establish a connection to your OpenStack project, you must supply a secret containing the `clouds.yaml` file.
28-
29-
```bash
30-
kubectl create secret generic <my-secret> --from-file=clouds.yaml=path/to/clouds.yaml
31-
```
32-
33-
To transfer the credentials stored in the secret mentioned above to the operator, the user must create an `OpenStackClusterStackReleaseTemplate` object and specify this secret in the `identityRef` field. The `clouds.yaml` file may contain one or more clouds, so the user must specify desired connection to a specific cloud by using the `cloudName` field. Refer to the `examples/cspotemplate.yaml` file for more details. Afterward, apply this template to the local Kind cluster, which was built by the previous `make` command.
34-
35-
```bash
36-
kubectl apply -f <path-to-openstack-clusterstack-release-template>
37-
```
38-
39-
Now, proceed to apply the `ClusterStack` to the local Kind cluster. For more details see `examples/clusterstack.yaml`.
40-
41-
```bash
42-
kubectl apply -f <path-to-openstack-clusterstack>
43-
```
44-
45-
Please be patient and wait for the operator to execute the necessary tasks. In case your `ClusterStack` object encounters no errors and `openstacknodeimagereleases` is ready, you can deploy a workload cluster. This could be done by applying cluster-template. See the example of this template in `examples/cluster.yaml`.
46-
47-
```bash
48-
kubectl apply -f <path-to-cluster-template>
49-
```
27+
You should make sure that everything in the UI looks green. If not, you can trigger the Tilt workflow again. In the case of the `cspotemplate`, this might be necessary, as it cannot be applied right after the startup of the cluster and fails. Tilt unfortunately does not include a waiting period.
5028

5129
In case you want to change some code, you can do so and see that Tilt triggers on save. It will update the container of the operator automatically.
5230

31+
If you want to change something in your ClusterStack or Cluster custom resources, you can have a look at `.cluster`.yaml and `.clusterstack.yaml`, which Tilt uses.
32+
5333
To tear down the workload cluster press the "Delete Workload Cluster" button. After a few minutes, the resources should be deleted.
5434

5535
To tear down the kind cluster, use:

0 commit comments

Comments
 (0)