diff --git a/.envrc.sample b/.envrc.sample index ffcec034..8e66c3aa 100644 --- a/.envrc.sample +++ b/.envrc.sample @@ -1,5 +1,4 @@ export KUBECONFIG=$PWD/.mgt-cluster-kubeconfig.yaml -export K8S_VERSION=1-27 export GIT_PROVIDER_B64=Z2l0aHVi export GIT_ACCESS_TOKEN_B64=mybase64encodedtoken export GIT_ORG_NAME_B64=U292ZXJlaWduQ2xvdWRTdGFjaw== diff --git a/Makefile b/Makefile index 8cd5f370..6010566f 100644 --- a/Makefile +++ b/Makefile @@ -572,6 +572,12 @@ builder-image-push: ## Build $(CONTROLLER_SHORT)-builder to a new version. For m create-workload-cluster-openstack: $(ENVSUBST) $(KUBECTL) cat .cluster.yaml | $(ENVSUBST) - | $(KUBECTL) apply -f - +delete-workload-cluster-openstack: $(ENVSUBST) $(KUBECTL) + cat .cluster.yaml | $(ENVSUBST) - | $(KUBECTL) delete -f - + +get-kubeconfig-workload-cluster: + ./hack/get-kubeconfig-of-workload-cluster.sh + .PHONY: tilt-up tilt-up: env-vars-for-wl-cluster $(ENVSUBST) $(KUBECTL) $(KUSTOMIZE) $(TILT) cluster ## Start a mgt-cluster & Tilt. Installs the CRDs and deploys the controllers EXP_CLUSTER_RESOURCE_SET=true $(TILT) up --port=10351 diff --git a/Tiltfile b/Tiltfile index 2c40a5cb..39b2f9e9 100644 --- a/Tiltfile +++ b/Tiltfile @@ -88,8 +88,8 @@ def prepare_environment(): if not os.path.exists('.cluster.yaml'): local("cp config/cspo/cluster.yaml .cluster.yaml") - if not os.path.exists('.clusterstacktemplate.yaml'): - local("cp config/cspo/clusterstacktemplate.yaml .clusterstacktemplate.yaml") + if not os.path.exists('.cspotemplate.yaml'): + local("cp config/cspo/cspotemplate.yaml .cspotemplate.yaml") def patch_args_with_extra_args(namespace, name, extra_args): args_str = str(local("kubectl get deployments {} -n {} -o jsonpath='{{.spec.template.spec.containers[0].args}}'".format(name, namespace))) @@ -203,8 +203,8 @@ def create_secret(): cmd = "cat .secret.yaml | {} | kubectl apply -f -".format(envsubst_cmd) local_resource('supersecret', cmd, labels=["clouds-yaml-secret"]) -def clusterstack_template(): - cmd = "cat .clusterstacktemplate.yaml | {} | kubectl apply -f -".format(envsubst_cmd) +def cspo_template(): + cmd = "cat .cspotemplate.yaml | {} | kubectl apply -f -".format(envsubst_cmd) local_resource('cspotemplate', cmd, labels=["cspo-template"]) def clusterstack(): @@ -242,6 +242,7 @@ def waitforsystem(): local("kubectl wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-bootstrap-system") local("kubectl wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system") local("kubectl wait --for=condition=ready --timeout=300s pod --all -n capi-system") + local("kubectl wait --for=condition=ready --timeout=300s pod --all -n capo-system") def deploy_observability(): k8s_yaml(blob(str(local("{} build {}".format(kustomize_cmd, "./hack/observability/"), quiet = True)))) @@ -282,7 +283,7 @@ prepare_environment() create_secret() -clusterstack_template() +cspo_template() cmd_button( "create workload cluster", @@ -290,3 +291,10 @@ cmd_button( location=location.NAV, icon_name="add_circle", ) + +cmd_button( + "delete workload cluster", + argv=["make", "delete-workload-cluster-openstack"], + location=location.NAV, + icon_name="cancel", +) diff --git a/config/cspo/clusterstacktemplate.yaml b/config/cspo/cspotemplate.yaml similarity index 100% rename from config/cspo/clusterstacktemplate.yaml rename to config/cspo/cspotemplate.yaml diff --git a/config/cspo/secret.yaml b/config/cspo/secret.yaml index 16a3fc33..cd6f0e68 100644 --- a/config/cspo/secret.yaml +++ b/config/cspo/secret.yaml @@ -3,5 +3,7 @@ data: clouds.yaml: ${ENCODED_CLOUDS_YAML} kind: Secret metadata: + labels: + clusterctl.cluster.x-k8s.io/move: "true" name: "${SECRET_NAME}" namespace: cluster diff --git a/docs/develop.md b/docs/develop.md index 8c995944..a5f8236e 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -26,11 +26,22 @@ make tilt-up 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. +If everything is green, then you can already check for your clusterstack that has been deployed. You can use a tool like k9s to have a look at the management cluster and its custom resources. + +In case your clusterstack shows that it is ready, you can deploy a workload cluster. This could be done through the Tilt UI, by pressing the button in the top right corner `Create Workload Cluster`. This triggers the `make create-workload-cluster-openstack`, which uses the environment variables and the cluster-template. + +To interact with your freshly created workload cluster, you can use these commands: + +```shell +make get-kubeconfig-workload-cluster #KUBECONFIG for the workload cluster is placed here: ".workload-cluster-kubeconfig.yaml" +export KUBECONFIG=$PWD/.workload-cluster-kubeconfig.yaml +``` + 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. 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. -To tear down the workload cluster press the "Delete Workload Cluster" button. After a few minutes, the resources should be deleted. +To tear down the workload cluster, click on the `Delete Workload Cluster` button in the top right corner of the Tilt UI. This action triggers the execution of `make delete-workload-cluster-openstack`. After a few minutes, the resources should be successfully deleted. To tear down the kind cluster, use: diff --git a/hack/get-kubeconfig-of-workload-cluster.sh b/hack/get-kubeconfig-of-workload-cluster.sh new file mode 100755 index 00000000..8964374c --- /dev/null +++ b/hack/get-kubeconfig-of-workload-cluster.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright 2023 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. + +if [ -z "$CLUSTER_NAME" ]; then + echo "env var CLUSTER_NAME is missing. Failed to get kubeconfig of workload cluster" + exit 1 +fi +namespace=$(kubectl get cluster -A| grep "${CLUSTER_NAME}" | head -1 | cut -d' ' -f1) +kubeconfig=".workload-cluster-kubeconfig.yaml" +kubectl get secrets -n "$namespace" "${CLUSTER_NAME}-kubeconfig" -ojsonpath='{.data.value}' | base64 -d > "$kubeconfig" + +if [ ! -s "$kubeconfig" ]; then + echo "failed to get kubeconfig of workload cluster" + exit 1 +fi + +chmod a=,u=rw $kubeconfig