diff --git a/.envrc b/.envrc index 94c685d2..3e646636 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,4 @@ layout go dotenv_if_exists +export KUBECONFIG=$(direnv_layout_dir)/kubeconfig use flake diff --git a/Makefile b/Makefile index 0113259b..ff444f1d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +REGISTRY ?= localhost:5001 # Image URL to use all building/pushing image targets IMG ?= kubernetes-ingress-controller @@ -94,11 +95,11 @@ run: manifests generate fmt vet ## Run a controller from your host. .PHONY: docker-build docker-build: test ## Build docker image with the manager. - DOCKER_BUILDKIT=1 docker build -t ${IMG} . + DOCKER_BUILDKIT=1 docker build -t ${REGISTRY}/${IMG} . .PHONY: docker-push -docker-push: ## Push docker image with the manager. - docker push ${IMG} +docker-push: docker-build ## Push docker image with the manager. + docker push ${REGISTRY}/${IMG} ##@ Deployment @@ -115,12 +116,14 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - .PHONY: deploy -deploy: _deploy-check-env-vars docker-build manifests kustomize _helm_setup ## Deploy controller to the K8s cluster specified in ~/.kube/config. +deploy: _deploy-check-env-vars docker-push manifests kustomize _helm_setup ## Deploy controller to the K8s cluster specified in ~/.kube/config. helm upgrade ngrok-ingress-controller $(HELM_CHART_DIR) --install \ --namespace ngrok-ingress-controller \ --create-namespace \ + --set image.registry=$(REGISTRY) \ --set image.repository=$(IMG) \ --set image.tag="latest" \ + --set image.pullPolicy="Always" \ --set podAnnotations."k8s\.ngrok\.com/test"="\{\"env\": \"local\"\}" \ --set credentials.apiKey=$(NGROK_API_KEY) \ --set credentials.authtoken=$(NGROK_AUTHTOKEN) \ diff --git a/docs/developer-guide/README.md b/docs/developer-guide/README.md index abc74702..33da98f4 100644 --- a/docs/developer-guide/README.md +++ b/docs/developer-guide/README.md @@ -11,10 +11,13 @@ Have a look at the architecture guide on the internal workings of the ingress co - [Go 1.20](https://go.dev/dl/) - [Helm](https://helm.sh/docs/intro/install/) -Both of these can be obtained via [nix-direnv](https://github.com/nix-community/nix-direnv), which will automatically configure your shell for you. +Both of these can be obtained via [nix-direnv](https://github.com/nix-community/nix-direnv), which will automatically configure your shell for you. Note that it will also set `KUBECONFIG` to a file "owned" by direnv, so as not to pollute the configuration in your `$HOME`. -- A k8s cluster is available via your kubectl client. This can be a remote cluster or a local cluster like [minikube](https://minikube.sigs.k8s.io/docs/start/) - - NOTE: Depending on your cluster, you may have to take additional steps to make the image available. For example with minikube, you may need to run `eval $(minikube docker-env)` in each terminal session to make the image from `make deploy` available to the cluster. +A k8s cluster is available via your kubectl client. This can be a remote cluster or a local cluster like [kind](https://kind.sigs.k8s.io/) or [minikube](https://minikube.sigs.k8s.io/docs/start/). + +Depending on your cluster, you may have to take additional steps to make the image available. For example with minikube, you may need to run `eval $(minikube docker-env)` in each terminal session to make the image from `make deploy` available to the cluster. + +Support for `kind` is provided out of the box. `scripts/kind-up.sh` will create a kind cluster and an accompanying docker registry, and `scripts/kind-down.sh` will tear both down. The `docker-push` and `deploy` tasks in the provided `Makefile` are configured to use this registry. ### Setup diff --git a/flake.nix b/flake.nix index c97e47bd..f258295d 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,8 @@ gotools go-tools golangci-lint + kind + kubectl kubernetes-helm kubebuilder jq diff --git a/scripts/kind-down.sh b/scripts/kind-down.sh new file mode 100755 index 00000000..3b0519c0 --- /dev/null +++ b/scripts/kind-down.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +kind delete cluster --name ngrok-ingress-controller +docker stop kind-registry | xargs docker rm \ No newline at end of file diff --git a/scripts/kind-up.sh b/scripts/kind-up.sh new file mode 100755 index 00000000..99061001 --- /dev/null +++ b/scripts/kind-up.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +set -o errexit + +cluster_name=ngrok-ingress-controller + +# 1. Create registry container unless it already exists +reg_name='kind-registry' +reg_port='5001' +if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then + docker run \ + -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ + registry:2 +fi + +# 2. Create kind cluster with containerd registry config dir enabled +# TODO: kind will eventually enable this by default and this patch will +# be unnecessary. +# +# See: +# 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 <