diff --git a/.envrc.sample b/.envrc.sample index 8e66c3aa..8a45adb0 100644 --- a/.envrc.sample +++ b/.envrc.sample @@ -11,4 +11,4 @@ export EXP_MACHINE_SET_PREFLIGHT_CHECKS=true export CLUSTER_NAME=test-dfkhje export SECRET_NAME=supersecret export CLOUD_NAME=test -export ENCODED_CLOUDS_YAML=mybase64encodedcloudsyamlfile +export ENCODED_CLOUDS_YAML=bXliYXNlNjRlbmNvZGVkY2xvdWRzeWFtbGZpbGUK \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9908a07d..697782a7 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,7 @@ temp # Tilt files. .tiltbuild /tilt.d -tilt-settings.json +tilt-settings.yaml tilt_config.json baremetalhosts.yaml @@ -70,3 +70,8 @@ __pycache__/ /_output tmp_* +.cluster.yaml +.clusterstack.yaml +.cspotemplate.yaml +.secret.yaml +.release \ No newline at end of file diff --git a/Tiltfile b/Tiltfile index 39b2f9e9..6e087951 100644 --- a/Tiltfile +++ b/Tiltfile @@ -17,10 +17,11 @@ settings = { "allowed_contexts": [ "kind-cspo", ], + "local_mode": False, "deploy_cert_manager": True, "preload_images_for_kind": True, "kind_cluster_name": "cspo", - "capi_version": "v1.5.2", + "capi_version": "v1.6.0", "cso_version": "v0.1.0-alpha.2", "capo_version": "v0.8.0", "cert_manager_version": "v1.13.1", @@ -29,8 +30,8 @@ settings = { } # global settings -settings.update(read_json( - "tilt-settings.json", +settings.update(read_yaml( + "tilt-settings.yaml", default = {}, )) @@ -61,12 +62,55 @@ def deploy_capi(): if kb_extra_args: patch_args_with_extra_args("capi-kubeadm-bootstrap-system", "capi-kubeadm-bootstrap-controller-manager", kb_extra_args) +## This should have the same versions as the Dockerfile +if settings.get("local_mode"): + tilt_dockerfile_header_cso = """ + FROM ghcr.io/sovereigncloudstack/cso:v0.1.0-alpha.2 as builder + + FROM docker.io/library/alpine:3.18.0 as tilt + WORKDIR / + COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm + COPY --from=builder /manager /manager + COPY .release/ /tmp/downloads/cluster-stacks/ + """ +else: + tilt_dockerfile_header_cso = """ + FROM ghcr.io/sovereigncloudstack/cso:v0.1.0-alpha.2 as builder + + FROM docker.io/library/alpine:3.18.0 as tilt + WORKDIR / + COPY --from=builder /usr/local/bin/helm /usr/local/bin/helm + COPY --from=builder /manager /manager + """ + + def deploy_cso(): + # yaml = str(kustomizesub("./hack/observability")) # build an observable kind deployment by default version = settings.get("cso_version") cso_uri = "https://github.com/sovereignCloudStack/cluster-stack-operator/releases/download/{}/cso-infrastructure-components.yaml".format(version) cmd = "curl -sSL {} | {} | kubectl apply -f -".format(cso_uri, envsubst_cmd) local(cmd, quiet = True) + entrypoint = ["/manager"] + extra_args = settings.get("extra_args") + if extra_args: + entrypoint.extend(extra_args) + + # Set up an image build for the provider. The live update configuration syncs the output from the local_resource + # build into the container. + if settings.get("local_mode"): + docker_build_with_restart( + ref = "ghcr.io/sovereigncloudstack/cso", + context = ".", + dockerfile_contents = tilt_dockerfile_header_cso, + target = "tilt", + entrypoint = entrypoint, + live_update = [ + sync(".release", "/tmp/downloads/cluster-stacks"), + ], + ignore = ["templates"], + ) + def deploy_capo(): version = settings.get("capo_version") capo_uri = "https://github.com/kubernetes-sigs/cluster-api-provider-openstack/releases/download/{}/infrastructure-components.yaml".format(version) @@ -124,14 +168,25 @@ def fixup_yaml_empty_arrays(yaml_str): return yaml_str.replace("storedVersions: null", "storedVersions: []") ## This should have the same versions as the Dockerfile -tilt_dockerfile_header_cspo = """ -FROM docker.io/alpine/helm:3.12.2 as helm - -FROM docker.io/library/alpine:3.18.0 as tilt -WORKDIR / -COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm -COPY manager . -""" +if settings.get("local_mode"): + tilt_dockerfile_header_cspo = """ + FROM docker.io/alpine/helm:3.12.2 as helm + + FROM docker.io/library/alpine:3.18.0 as tilt + WORKDIR / + COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm + COPY .tiltbuild/manager . + COPY .release/ /tmp/downloads/cluster-stacks/ + """ +else: + tilt_dockerfile_header_cspo = """ + FROM docker.io/alpine/helm:3.12.2 as helm + + FROM docker.io/library/alpine:3.18.0 as tilt + WORKDIR / + COPY --from=helm --chown=root:root --chmod=755 /usr/bin/helm /usr/local/bin/helm + COPY manager . + """ # Build cspo and add feature gates @@ -166,18 +221,31 @@ def deploy_cspo(): # Set up an image build for the provider. The live update configuration syncs the output from the local_resource # build into the container. - docker_build_with_restart( - ref = "ghcr.io/sovereigncloudstack/cspo-staging", - context = "./.tiltbuild/", - dockerfile_contents = tilt_dockerfile_header_cspo, - target = "tilt", - entrypoint = entrypoint, - only = "manager", - live_update = [ - sync(".tiltbuild/manager", "/manager"), - ], - ignore = ["templates"], - ) + if settings.get("local_mode"): + docker_build_with_restart( + ref = "ghcr.io/sovereigncloudstack/cspo-staging", + context = ".", + dockerfile_contents = tilt_dockerfile_header_cspo, + target = "tilt", + entrypoint = entrypoint, + live_update = [ + sync(".tiltbuild/manager", "/manager"), + sync(".release", "/tmp/downloads/cluster-stacks"), + ], + ignore = ["templates"], + ) + else: + docker_build_with_restart( + ref = "ghcr.io/sovereigncloudstack/cspo-staging", + context = "./.tiltbuild/", + dockerfile_contents = tilt_dockerfile_header_cspo, + target = "tilt", + entrypoint = entrypoint, + live_update = [ + sync(".tiltbuild/manager", "/manager"), + ], + ignore = ["templates"], + ) k8s_yaml(blob(yaml)) k8s_resource(workload = "cspo-controller-manager", labels = ["cspo"]) k8s_resource( diff --git a/config/cspo/cluster.yaml b/config/cspo/cluster.yaml index d58f6d7e..93ebe35e 100644 --- a/config/cspo/cluster.yaml +++ b/config/cspo/cluster.yaml @@ -11,7 +11,7 @@ spec: cidrBlocks: ["192.168.0.0/16"] serviceDomain: "cluster.local" topology: - class: openstack-ferrol-1-27-v1 + class: openstack-scs-1-27-v2 controlPlane: metadata: {} replicas: 1 diff --git a/config/cspo/clusterstack.yaml b/config/cspo/clusterstack.yaml index 96a584bc..91879fa9 100644 --- a/config/cspo/clusterstack.yaml +++ b/config/cspo/clusterstack.yaml @@ -5,7 +5,7 @@ metadata: namespace: cluster spec: provider: openstack - name: ferrol + name: scs kubernetesVersion: "1.27" channel: stable autoSubscribe: false @@ -14,4 +14,4 @@ spec: kind: OpenStackClusterStackReleaseTemplate name: cspotemplate versions: - - v1 + - v2 \ No newline at end of file diff --git a/docs/develop.md b/docs/develop.md index 2dd3218f..56aa1799 100644 --- a/docs/develop.md +++ b/docs/develop.md @@ -50,3 +50,44 @@ make delete-bootstrap-cluster ``` If you have any trouble finding the right command, then you can use `make help` to get a list of all available make targets. + +## Toggle between local_mode and remote mode +We can retrieve cluster-stacks in two modes. One way is to let the controller fetch it from GitHub which is remote mode and other is we mount the cluster-stacks inside the container at `/tmp/downloads/cluster-stacks` directory. + +> [!NOTE] +> Using remote mode is the default behavior. + +Switching between both modes is relatively simple if you're using Tilt. There is a file at the root of the repo `tilt-settings.yaml.example` +Make a copy of that file with the name of `tilt-settings.yaml` +```bash +cp tilt-settings.yaml.example tilt-settings.yaml +``` +Now, open the file and set the `local_mode` to `true` to use cluster-stacks in local_mode. It should look the following content wise. +```yaml +local_mode: true +``` + +> [!NOTE] +> In this mode you need to have cluster-stacks present locally. + +Downloading cluster-stacks can be achieved by many ways but below is a simple way to download it quickly. +```bash +mkdir -p .release/openstack-scs-1-27-v1/ +cd .release/openstack-scs-1-27-v1 +gh release download --repo sovereigncloudstack/cluster-stacks openstack-scs-1-27-v1 +``` +Change the repo and tag as per the requirement. You can also download it directly from browser and move it to `.release` directory. + +Please make sure the directory structure remains the same otherwise you'll not be able to start the tilt setup. Here's an example of structuring `openstack-scs-1-27-v1` cluster-stack. +```bash +$ tree .release/openstack-scs-1-27-v1/ +.release/openstack-scs-1-27-v1/ +├── clusterstack.yaml +├── metadata.yaml +└── openstack-scs-1-27-cluster-class-v1.tgz +``` + +> [!IMPORTANT] +There's an alternative way to get clusterstacks using [csmctl](https://github.com/sovereigncloudstack/csmctl). You can follow the README of csmctl for specific instructions and a good quickstart. + +You can use `csmctl create` subcommand to create clusterstack locally. You'll need a csmctl.yaml file in the cluster-stack configuration directory. Please read more about creating configuration file for csmctl in the csmctl docs. diff --git a/tilt-settings.yaml.example b/tilt-settings.yaml.example new file mode 100644 index 00000000..1ca36e89 --- /dev/null +++ b/tilt-settings.yaml.example @@ -0,0 +1,11 @@ +--- +allowed_contexts: +- kind-cspo +local_mode: false +deploy_cert_manager: true +preload_images_for_kind: true +kind_cluster_name: cspo +capi_version: v1.6.0 +cso_version: v0.1.0-alpha.2 +capo_version: v0.8.0 +cert_manager_version: v1.13.1 \ No newline at end of file