From 66790265ef87b51fbbad8438459e762a8ef01fcf Mon Sep 17 00:00:00 2001 From: Jakob Beckmann Date: Mon, 8 Sep 2025 10:53:52 +0200 Subject: [PATCH] test: update testing infrastructure to make development easier Signed-off-by: Jakob Beckmann --- .dockerignore | 1 + Dockerfile.local | 14 +++++-- Makefile | 22 +++++++++- README.md | 58 +++++++++++++++++++++++++-- hack/nats-values.yaml | 13 ++++++ hack/run-kind-cluster.sh | 16 +++++++- hack/teardown-kind-cluster.sh | 9 +++++ hack/wadm-values.yaml | 4 ++ hack/wasmcloud-hostconfig-sample.yaml | 17 ++++++++ 9 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 hack/nats-values.yaml create mode 100755 hack/teardown-kind-cluster.sh create mode 100644 hack/wadm-values.yaml create mode 100644 hack/wasmcloud-hostconfig-sample.yaml diff --git a/.dockerignore b/.dockerignore index d656f27..6ebb37a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,3 +4,4 @@ bin/ target/ Dockerfile Makefile +.devbox/ diff --git a/Dockerfile.local b/Dockerfile.local index f386202..b6f60ed 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -1,12 +1,20 @@ # syntax=docker/dockerfile:1 -FROM rust:1.77-bookworm as builder +FROM ghcr.io/rust-cross/cargo-zigbuild:0.20.1 AS builder + +ARG TARGETARCH=x86_64 + +WORKDIR /tmp + +RUN rustup target add ${TARGETARCH}-unknown-linux-musl WORKDIR /app + COPY . . RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/app/target \ - cargo build --release && cp target/release/wasmcloud-operator . + cargo zigbuild --release --target x86_64-unknown-linux-musl --locked && \ + cp target/${TARGETARCH}-unknown-linux-musl/release/wasmcloud-operator . -FROM gcr.io/distroless/cc-debian12 +FROM scratch COPY --from=builder /app/wasmcloud-operator /usr/local/bin/ ENTRYPOINT ["/usr/local/bin/wasmcloud-operator"] diff --git a/Makefile b/Makefile index 0759b1a..e7036a7 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ repo := ghcr.io/wasmcloud/wasmcloud-operator +local_repo := localhost:5001/wasmcloud-operator version := $(shell git rev-parse --short HEAD) platforms := linux/amd64,linux/arm64 -.PHONY: build-dev-image build-image buildx-image +.PHONY: build-dev-image build-image buildx-image setup teardown build-local-dev-image push-local-dev-image deploy-local-dev-image update-local-dev-image build-image: docker build -t $(repo):$(version) . @@ -11,3 +12,22 @@ buildx-image: build-dev-image: docker build -t $(repo):$(version)-dev -f Dockerfile.local . + +setup: + cd hack && bash ./run-kind-cluster.sh + +teardown: + cd hack && bash ./teardown-kind-cluster.sh + +build-local-dev-image: + docker build -t $(local_repo):latest -f Dockerfile.local . + +push-local-dev-image: + docker push $(local_repo):latest + +deploy-local-dev-image: + kubectl kustomize deploy/local | kubectl apply -f - + +# deleting pod makes it pull a new version thanks to pullPolicy always +update-local-dev-image: + kubectl delete pod -n wasmcloud-operator -l "app=wasmcloud-operator" diff --git a/README.md b/README.md index 547bf2f..3b26067 100644 --- a/README.md +++ b/README.md @@ -212,9 +212,61 @@ data: ## Testing -- Make sure you have a Kubernetes cluster running locally. Some good options - include [Kind](https://kind.sigs.k8s.io/) or Docker Desktop. -- `RUST_LOG=info cargo run` +### KinD + +Make sure you have `kind`, `kubectl`, and `helm` installed. Then you can run `make setup` to create +a KinD cluster with NATS and wadm installed. + +### Deploy Local Code + +Once KinD is set up, run the following: + +```sh +# build a docker image from the current code +make build-local-dev-image +# push the image to a registry available to kind +make push-local-dev-image +# deploy the operator using the pushed image +make deploy-local-dev-image +``` + +### Deploying Test Custom Resources + +You can deploy custom resources to test the operator using the following commands: + +```sh +# deploy a host configuration +kubectl apply -f hack/wasmcloud-hostconfig-sample.yaml +# once the hosts are available, deploy a sample application +kubectl apply -f https://raw.githubusercontent.com/wasmCloud/wasmcloud-operator/main/examples/quickstart/hello-world-application.yaml +``` + +### Update the Image + +After performing local changes to the code, you can update the operator running in the KinD cluster +using: + +```sh +# re-build a docker image from the current code +make build-local-dev-image +# re-push the image to a registry available to kind +make push-local-dev-image +# update the existing deployment with the new image +make update-local-dev-image +``` + +### Local Deployment of the Operator + +You can locally run the operator outside any Kubernetes cluster using: + +```sh +RUST_LOG=info cargo run --bin wasmcloud-operator +``` + +> Note that the operator will try to connect to NATS using the configured URI from the +> `WasmCloudHostConfig` resources. Since this is likely a DNS entry only resolvable within the +> Kuberntees cluster, you will need to ensure traffic is correctly routed to NATS in order for this +> to work (e.g. using an entry in your `/etc/hosts` and a port-forward to the NATS service. ## Types crate diff --git a/hack/nats-values.yaml b/hack/nats-values.yaml new file mode 100644 index 0000000..cef1caf --- /dev/null +++ b/hack/nats-values.yaml @@ -0,0 +1,13 @@ +config: + cluster: + enabled: true + replicas: 3 + leafnodes: + enabled: true + jetstream: + enabled: true + fileStore: + pvc: + size: 10Gi + merge: + domain: default diff --git a/hack/run-kind-cluster.sh b/hack/run-kind-cluster.sh index 515aa30..781de20 100755 --- a/hack/run-kind-cluster.sh +++ b/hack/run-kind-cluster.sh @@ -18,7 +18,7 @@ fi # https://github.com/kubernetes-sigs/kind/issues/2875 # https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration # See: https://github.com/containerd/containerd/blob/main/docs/hosts.md -cat <