Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 45 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
GINKGO ?= $(LOCALBIN)/ginkgo
GOVULNCHECK ?= $(LOCALBIN)/govulncheck
CLUSTERCTL ?= clusterctl

## Local development (clusterctl) configuration
DEV_KIND_CLUSTER ?= capcs-mgmt
# example.invalid never resolves, so imagePullPolicy: IfNotPresent can only use the kind-loaded image.
DEV_IMG ?= example.invalid/capcs/manager:dev
# Must match a release series in metadata.yaml (currently 1.0 / v1beta2).
DEV_PROVIDER_VERSION ?= v1.0.99
# clusterctl reads its overrides layer from $$XDG_CONFIG_HOME/cluster-api/overrides and falls back
# to ~/.cluster-api/overrides when that directory does not exist. Careful: the XDG library clusterctl
# uses resolves $$XDG_CONFIG_HOME to ~/Library/Application Support on macOS (NOT ~/.config), so the
# home-dir fallback below is the location that behaves the same on Linux and macOS. Point
# CLUSTERCTL_OVERRIDES_DIR at your XDG overrides dir if you deliberately keep one.
CLUSTERCTL_OVERRIDES_DIR ?= $(HOME)/.cluster-api/overrides
DEV_OVERRIDES_DIR := $(CLUSTERCTL_OVERRIDES_DIR)/infrastructure-cloudscale-ch-cloudscale/$(DEV_PROVIDER_VERSION)

##@ E2E Testing

Expand Down Expand Up @@ -346,30 +361,36 @@ release-manifests: build-installer ## Build all release artifacts into dist/ (in
cp templates/cluster-template*.yaml dist/
cp templates/cluster-class*.yaml dist/

##@ Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
@out="$$( "$(KUSTOMIZE)" build config/crd 2>/dev/null || true )"; \
if [ -n "$$out" ]; then echo "$$out" | "$(KUBECTL)" apply -f -; else echo "No CRDs to install; skipping."; fi

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
@out="$$( "$(KUSTOMIZE)" build config/crd 2>/dev/null || true )"; \
if [ -n "$$out" ]; then echo "$$out" | "$(KUBECTL)" delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && "$(KUSTOMIZE)" edit set image controller=${IMG}
"$(KUSTOMIZE)" build config/default | "$(KUBECTL)" apply -f -

.PHONY: undeploy
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
"$(KUSTOMIZE)" build config/default | "$(KUBECTL)" delete --ignore-not-found=$(ignore-not-found) -f -
##@ Local development
# These targets install CAPCS to a local kind cluster which gets created on the fly when invoking `dev-deploy`.

.PHONY: dev-kind-cluster
dev-kind-cluster: ## Create the dev kind management cluster if it does not exist.
@$(KIND) get clusters | grep -qx $(DEV_KIND_CLUSTER) || $(KIND) create cluster --name $(DEV_KIND_CLUSTER)

.PHONY: dev-deploy
dev-deploy: IMG = $(DEV_IMG)
dev-deploy: docker-build release-manifests dev-kind-cluster ## Build image and install CAPCS into a local kind cluster via clusterctl's overrides layer (requires CLOUDSCALE_API_TOKEN).
git checkout -- config/manager/kustomization.yaml # release-manifests/build-installer mutates this
$(KIND) load docker-image $(IMG) --name $(DEV_KIND_CLUSTER)
mkdir -p "$(DEV_OVERRIDES_DIR)"
cp dist/infrastructure-components.yaml dist/metadata.yaml dist/cluster-template*.yaml dist/cluster-class*.yaml "$(DEV_OVERRIDES_DIR)/"
$(KIND) export kubeconfig --name $(DEV_KIND_CLUSTER)
$(CLUSTERCTL) init --infrastructure cloudscale-ch-cloudscale:$(DEV_PROVIDER_VERSION)

.PHONY: dev-redeploy
dev-redeploy: IMG = $(DEV_IMG)
dev-redeploy: docker-build ## Rebuild the manager image and restart CAPCS in the kind cluster.
$(KIND) load docker-image $(IMG) --name $(DEV_KIND_CLUSTER)
$(KUBECTL) -n capcs-system rollout restart deployment/capcs-controller-manager
$(KUBECTL) -n capcs-system rollout status deployment/capcs-controller-manager

.PHONY: dev-clean
dev-clean: ## Tear down the dev kind cluster and remove the dev provider overrides.
-$(KIND) delete cluster --name $(DEV_KIND_CLUSTER)
-rm -rf "$(DEV_OVERRIDES_DIR)"

##@ Tooling

## Tool Versions
KUSTOMIZE_VERSION ?= v5.8.1
Expand Down
37 changes: 31 additions & 6 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ a kustomize overlay).

## Tilt

The fastest inner loop is Cluster API's
[Tilt setup](https://cluster-api.sigs.k8s.io/developer/core/tilt.html). It runs
out of a local clone of [cluster-api](https://github.com/kubernetes-sigs/cluster-api),
**not** out of this repository.
The best way to develop CAPCS is using Cluster APIs [Tilt setup](https://cluster-api.sigs.k8s.io/developer/core/tilt.html). It runs
out of a local clone of [cluster-api](https://github.com/kubernetes-sigs/cluster-api), **not** out of this repository.

Drop a `tilt-settings.yaml` next to the cluster-api checkout:
Drop a `tilt-settings.yaml` into the cluster-api directory:

```yaml
default_registry: ""
Expand Down Expand Up @@ -131,7 +129,7 @@ template_dirs:
# - tempo
```

Then `tilt up` from the cluster-api checkout.
Then `tilt up` from the cluster-api directory.

The `deploy_observability` block is processed by the cluster-api Tiltfile and
brings up Prometheus, Grafana, Tempo, and friends in the management cluster;
Expand All @@ -141,6 +139,33 @@ for what each component does and how to reach the resulting UIs. CAPCS's
enabled. For production metric/tracing setup, see
[Observability](observability.md).

## Deploying locally without Tilt

For a quick manual check of a locally-built image, without pulling in the Tilt toolchain,
deploy CAPCS against a `kind` cluster:

```bash
# create kind cluster and deploy cluster api and capcs with a locally built image
make dev-deploy

# re-deploy in case you made changes
make dev-redeploy

# clean up the kind cluster
make dev-clean
```

By default `dev-deploy` writes clusterctl overrides to `~/.cluster-api/overrides` (`CLUSTERCTL_OVERRIDES_DIR`). That is
the home-dir location clusterctl falls back to on both Linux and macOS. Note that
clusterctl actually prefers `$XDG_CONFIG_HOME/cluster-api/overrides` and only falls back
to the home dir when that directory does **not** exist.
If you keep an XDG overrides directory (e.g. you exported
`XDG_CONFIG_HOME`), point the targets at it:

```bash
make dev-deploy CLUSTERCTL_OVERRIDES_DIR="$XDG_CONFIG_HOME/cluster-api/overrides"
```

## Tests

| Layer | Location | What it covers |
Expand Down