Skip to content

Commit b46b43c

Browse files
committed
WIP: Local kind registry
Signed-off-by: timflannagan <[email protected]>
1 parent e837e48 commit b46b43c

File tree

9 files changed

+127
-101
lines changed

9 files changed

+127
-101
lines changed

.github/actions/kube-agent-gateway-conformance-tests/action.yaml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,9 @@ runs:
3939
- name: Install kgateway via helm
4040
shell: bash
4141
run: |
42-
# Check if additional Helm values file is provided
43-
ADDITIONAL_VALUES=""
44-
if [[ -n "${HELM_ADDITIONAL_VALUES}" && -f "${HELM_ADDITIONAL_VALUES}" ]]; then
45-
ADDITIONAL_VALUES="-f ${HELM_ADDITIONAL_VALUES}"
46-
echo "Using additional Helm values from: ${HELM_ADDITIONAL_VALUES}"
47-
fi
48-
4942
if [[ -z "${{ matrix.version }}" ]]; then
50-
# If matrix.version is empty, use the local chart path specified in the Makefile.
51-
helm upgrade -i -n kgateway-system kgateway-crds ./install/helm/kgateway-crds/ \
52-
--create-namespace
53-
helm upgrade -i -n kgateway-system kgateway ./install/helm/kgateway/ \
54-
--create-namespace \
55-
--set image.tag=${VERSION} --set image.registry=ghcr.io/kgateway-dev \
56-
${ADDITIONAL_VALUES}
43+
# If matrix.version is empty, use the local chart path via Makefile target
44+
make deploy-kgateway
5745
else
5846
# TODO(tim): this will require changes once the new helm chart is integrated
5947
# and published with the release pipeline.

.github/actions/kube-gateway-api-conformance-tests/action.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ runs:
4040
shell: bash
4141
run: |
4242
if [[ -z "${{ matrix.version }}" ]]; then
43-
# If matrix.version is empty, use the local chart path specified in the Makefile.
44-
helm upgrade -i -n kgateway-system kgateway-crds ./install/helm/kgateway-crds/ \
45-
--create-namespace
46-
helm upgrade -i -n kgateway-system kgateway ./install/helm/kgateway/ \
47-
--create-namespace \
48-
--set image.tag=${VERSION} --set image.registry=ghcr.io/kgateway-dev
43+
# If matrix.version is empty, use the local chart path via Makefile target
44+
make deploy-kgateway
4945
else
5046
# TODO(tim): this will require changes once the new helm chart is integrated
5147
# and published with the release pipeline.

.github/actions/kube-gateway-api-load-tests/action.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,9 @@ runs:
2121
- name: Install KGateway via Helm
2222
shell: bash
2323
run: |
24-
# Install using local chart paths (development/testing scenario)
25-
go tool helm upgrade --install kgateway-crds ./install/helm/kgateway-crds/ \
26-
--namespace kgateway-system --create-namespace \
27-
--wait --timeout 5m
28-
29-
go tool helm upgrade --install kgateway ./install/helm/kgateway/ \
30-
--namespace kgateway-system --create-namespace \
31-
--set image.tag=${VERSION:-1.0.0-ci1} \
32-
--set image.registry=ghcr.io/kgateway-dev \
33-
--set inferenceExtension.enabled=true \
34-
--wait --timeout 5m
24+
# TODO(tim): confirm is this needs to --set the image registry.
25+
make deploy-kgateway \
26+
HELM_ADDITIONAL_FLAGS="--set inferenceExtension.enabled=true --wait --timeout 5m"
3527
3628
- name: Wait for KGateway deployment to be ready
3729
shell: bash
@@ -40,4 +32,4 @@ runs:
4032
4133
- name: Run load tests
4234
shell: bash
43-
run: make run-load-tests
35+
run: make run-load-tests

.github/actions/kube-inference-extension-conformance-tests/action.yaml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,8 @@ runs:
3939
shell: bash
4040
run: |
4141
if [[ -z "${{ matrix.version }}" ]]; then
42-
# If matrix.version is empty, use the local chart path specified in the Makefile.
43-
helm upgrade -i -n kgateway-system kgateway-crds ./install/helm/kgateway-crds/ \
44-
--create-namespace \
45-
--set inferenceExtension.enabled=true
46-
helm upgrade -i -n kgateway-system kgateway ./install/helm/kgateway/ \
47-
--create-namespace \
48-
--set image.tag=${VERSION} \
49-
--set image.registry=ghcr.io/kgateway-dev \
50-
--set inferenceExtension.enabled=true
42+
# If matrix.version is empty, use the local chart path via Makefile target
43+
make deploy-kgateway HELM_ADDITIONAL_FLAGS="--set inferenceExtension.enabled=true"
5144
else
5245
# TODO(tim): this will require changes once the new helm chart is integrated
5346
# and published with the release pipeline.

Makefile

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ help: ## Output the self-documenting make targets
2828
ROOTDIR := $(shell pwd)
2929
OUTPUT_DIR ?= $(ROOTDIR)/_output
3030

31-
export IMAGE_REGISTRY ?= ghcr.io/kgateway-dev
31+
# Image registry for container images. Defaults to localhost:5001 for local development with kind
32+
# Override via environment variable for releases (e.g., IMAGE_REGISTRY=ghcr.io/kgateway-dev)
33+
IMAGE_REGISTRY ?= localhost:5001
34+
export IMAGE_REGISTRY
3235

3336
# Kind of a hack to make sure _output exists
3437
z := $(shell mkdir -p $(OUTPUT_DIR))
3538

36-
BUILDX_BUILD ?= docker buildx build -q
37-
3839
# A semver resembling 1.0.1-dev. Most calling GHA jobs customize this. Exported for use in goreleaser.yaml.
3940
VERSION ?= 1.0.1-dev
4041
export VERSION
@@ -62,7 +63,9 @@ else
6263
endif
6364
endif
6465

65-
PLATFORM := --platform=linux/$(GOARCH)
66+
BUILDX_BUILDER_NAME ?= kind-builder
67+
BUILDX_BUILD ?= docker buildx build -q
68+
BUILDX_BUILD_ARGS ?= --push --builder $(BUILDX_BUILDER_NAME) --platform=linux/$(GOARCH)
6669

6770
GOOS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
6871

@@ -417,8 +420,9 @@ kgateway: $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH)
417420
$(CONTROLLER_OUTPUT_DIR)/Dockerfile: cmd/kgateway/Dockerfile
418421
cp $< $@
419422

423+
.PHONY: $(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
420424
$(CONTROLLER_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(CONTROLLER_OUTPUT_DIR)/kgateway-linux-$(GOARCH) $(CONTROLLER_OUTPUT_DIR)/Dockerfile
421-
$(BUILDX_BUILD) --load $(PLATFORM) $(CONTROLLER_OUTPUT_DIR) -f $(CONTROLLER_OUTPUT_DIR)/Dockerfile \
425+
$(BUILDX_BUILD) $(BUILDX_BUILD_ARGS) $(CONTROLLER_OUTPUT_DIR) -f $(CONTROLLER_OUTPUT_DIR)/Dockerfile \
422426
--build-arg GOARCH=$(GOARCH) \
423427
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
424428
-t $(IMAGE_REGISTRY)/$(CONTROLLER_IMAGE_REPO):$(VERSION)
@@ -445,8 +449,9 @@ sds: $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH)
445449
$(SDS_OUTPUT_DIR)/Dockerfile.sds: cmd/sds/Dockerfile
446450
cp $< $@
447451

452+
.PHONY: $(SDS_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
448453
$(SDS_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(SDS_OUTPUT_DIR)/sds-linux-$(GOARCH) $(SDS_OUTPUT_DIR)/Dockerfile.sds
449-
$(BUILDX_BUILD) --load $(PLATFORM) $(SDS_OUTPUT_DIR) -f $(SDS_OUTPUT_DIR)/Dockerfile.sds \
454+
$(BUILDX_BUILD) $(BUILDX_BUILD_ARGS) $(SDS_OUTPUT_DIR) -f $(SDS_OUTPUT_DIR)/Dockerfile.sds \
450455
--build-arg GOARCH=$(GOARCH) \
451456
--build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) \
452457
-t $(IMAGE_REGISTRY)/$(SDS_IMAGE_REPO):$(VERSION)
@@ -486,8 +491,9 @@ $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit: $(ENVOYINIT_DOCKERFILE) $(RUSTFORM
486491
$(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh: cmd/envoyinit/docker-entrypoint.sh
487492
cp $< $@
488493

494+
.PHONY: $(ENVOYINIT_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH)
489495
$(ENVOYINIT_OUTPUT_DIR)/.docker-stamp-$(VERSION)-$(GOARCH): $(ENVOYINIT_OUTPUT_DIR)/envoyinit-linux-$(GOARCH) $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit $(ENVOYINIT_OUTPUT_DIR)/docker-entrypoint.sh
490-
$(BUILDX_BUILD) --load $(PLATFORM) $(ENVOYINIT_OUTPUT_DIR) -f $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit \
496+
$(BUILDX_BUILD) $(BUILDX_BUILD_ARGS) $(ENVOYINIT_OUTPUT_DIR) -f $(ENVOYINIT_OUTPUT_DIR)/Dockerfile.envoyinit \
491497
--build-arg GOARCH=$(GOARCH) \
492498
--build-arg ENVOY_IMAGE=$(ENVOY_IMAGE) \
493499
--build-arg RUST_BUILD_ARCH=$(RUST_BUILD_ARCH) \
@@ -561,6 +567,8 @@ GORELEASER_ARGS ?= --snapshot --clean
561567
GORELEASER_TIMEOUT ?= 60m
562568
GORELEASER_CURRENT_TAG ?= $(VERSION)
563569

570+
# When running locally, we need to set the IMAGE_REGISTRY to override the default
571+
# localhost:5001 local registry.
564572
.PHONY: release
565573
release: ## Create a release using goreleaser
566574
GORELEASER_CURRENT_TAG=$(GORELEASER_CURRENT_TAG) $(GORELEASER) release $(GORELEASER_ARGS) --timeout $(GORELEASER_TIMEOUT)
@@ -577,9 +585,15 @@ INSTALL_NAMESPACE ?= kgateway-system
577585
# This version should stay in sync with `hack/kind/setup-kind.sh`.
578586
CLUSTER_NODE_VERSION ?= v1.34.0@sha256:7416a61b42b1662ca6ca89f02028ac133a309a2a30ba309614e8ec94d976dc5a
579587

588+
.PHONY: kind-create-builder
589+
kind-create-builder: ## Create a buildx builder for pushing to local registry
590+
@if ! docker buildx ls | grep -q $(BUILDX_BUILDER_NAME); then \
591+
docker buildx create --name $(BUILDX_BUILDER_NAME) --driver docker-container --driver-opt network=host --bootstrap --use; \
592+
fi
593+
580594
.PHONY: kind-create
581-
kind-create: ## Create a KinD cluster
582-
$(KIND) get clusters | grep $(CLUSTER_NAME) || $(KIND) create cluster --name $(CLUSTER_NAME) --image kindest/node:$(CLUSTER_NODE_VERSION)
595+
kind-create: ## Create a KinD cluster with a local registry
596+
KIND_CLUSTER_NAME=$(CLUSTER_NAME) KIND_IMAGE_VERSION=$(CLUSTER_NODE_VERSION) ./hack/kind/setup-local-registry.sh
583597

584598
CONFORMANCE_CHANNEL ?= experimental
585599
CONFORMANCE_VERSION ?= v1.4.0
@@ -606,10 +620,10 @@ deploy-kgateway: package-kgateway-charts deploy-kgateway-crd-chart deploy-kgatew
606620
setup-base: kind-create gw-api-crds gie-crds metallb ## Setup the base infrastructure (kind cluster, CRDs, and MetalLB)
607621

608622
.PHONY: setup
609-
setup: setup-base kind-build-and-load package-kgateway-charts ## Setup the complete infrastructure (base setup plus images and charts)
623+
setup: setup-base docker-build package-kgateway-charts ## Setup the complete infrastructure
610624

611625
.PHONY: run
612-
run: setup deploy-kgateway ## Set up complete development environment
626+
run: setup deploy-kgateway ## Set up complete development environment
613627

614628
.PHONY: undeploy
615629
undeploy: undeploy-kgateway undeploy-kgateway-crds ## Undeploy the application from the cluster
@@ -622,21 +636,19 @@ undeploy-kgateway: ## Undeploy the core chart from the cluster
622636
undeploy-kgateway-crds: ## Undeploy the CRD chart from the cluster
623637
$(HELM) uninstall kgateway-crds --namespace $(INSTALL_NAMESPACE) || true
624638

639+
.PHONY: docker-build ## Build and push all docker images to local registry
640+
docker-build: kind-create-builder
641+
docker-build: kgateway-docker
642+
docker-build: envoy-wrapper-docker
643+
docker-build: sds-docker
644+
625645
#----------------------------------------------------------------------------------
626646
# Build assets for kubernetes e2e tests
627647
#----------------------------------------------------------------------------------
628648

629649
kind-setup: ## Set up the KinD cluster. Deprecated: use kind-create instead.
630650
VERSION=${VERSION} CLUSTER_NAME=${CLUSTER_NAME} ./hack/kind/setup-kind.sh
631651

632-
kind-load-%:
633-
$(KIND) load docker-image $(IMAGE_REGISTRY)/$*:$(VERSION) --name $(CLUSTER_NAME)
634-
635-
# Build an image and load it into the KinD cluster
636-
# Depends on: IMAGE_REGISTRY, VERSION, CLUSTER_NAME
637-
# Envoy image may be specified via ENVOY_IMAGE on the command line or at the top of this file
638-
kind-build-and-load-%: %-docker kind-load-% ; ## Use to build specified image and load it into kind
639-
640652
# Update the docker image used by a deployment
641653
# This works for most of our deployments because the deployment name and container name both match
642654
# NOTE TO DEVS:
@@ -649,24 +661,6 @@ kind-set-image-%:
649661
kubectl patch deployment $* -n $(INSTALL_NAMESPACE) -p '{"spec": {"template":{"metadata":{"annotations":{"kgateway-kind-last-update":"$(shell date)"}}}} }'
650662
kubectl rollout resume deployment $* -n $(INSTALL_NAMESPACE)
651663

652-
# Reload an image in KinD
653-
# This is useful to developers when changing a single component
654-
# You can reload an image, which means it will be rebuilt and reloaded into the kind cluster, and the deployment
655-
# will be updated to reference it
656-
# Depends on: IMAGE_REGISTRY, VERSION, INSTALL_NAMESPACE , CLUSTER_NAME
657-
# Envoy image may be specified via ENVOY_IMAGE on the command line or at the top of this file
658-
kind-reload-%: kind-build-and-load-% kind-set-image-% ; ## Use to build specified image, load it into kind, and restart its deployment
659-
660-
.PHONY: kind-build-and-load ## Use to build all images and load them into kind
661-
kind-build-and-load: kind-build-and-load-kgateway
662-
kind-build-and-load: kind-build-and-load-envoy-wrapper
663-
kind-build-and-load: kind-build-and-load-sds
664-
665-
.PHONY: kind-load ## Use to load all images into kind
666-
kind-load: kind-load-kgateway
667-
kind-load: kind-load-envoy-wrapper
668-
kind-load: kind-load-sds
669-
670664
#----------------------------------------------------------------------------------
671665
# Load Testing
672666
#----------------------------------------------------------------------------------

hack/helm/dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ controller:
88
# rollingUpdate:
99
# maxSurge: 100%
1010
# maxUnavailable: 100%
11+
image:
12+
registry: localhost:5001

hack/kind/cluster.yaml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
kind: Cluster
21
apiVersion: kind.x-k8s.io/v1alpha4
3-
kubeadmConfigPatches:
4-
- |
5-
apiVersion: kubeadm.k8s.io/v1beta3
6-
kind: ClusterConfiguration
7-
metadata:
8-
name: config
9-
- |
10-
apiVersion: kubeadm.k8s.io/v1beta3
11-
kind: InitConfiguration
12-
metadata:
13-
name: config
2+
kind: Cluster
3+
containerdConfigPatches:
4+
- |-
5+
[plugins."io.containerd.grpc.v1.cri".registry]
6+
config_path = "/etc/containerd/certs.d"
7+
networking:
8+
apiServerAddress: "127.0.0.1"

hack/kind/setup-kind.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@ function create_kind_cluster_or_skip() {
4242
return
4343
fi
4444

45-
echo "creating cluster ${CLUSTER_NAME}"
46-
$KIND create cluster \
47-
--name "$CLUSTER_NAME" \
48-
--image "kindest/node:$CLUSTER_NODE_VERSION" \
49-
--config="$SCRIPT_DIR/cluster.yaml"
45+
echo "creating cluster ${CLUSTER_NAME} with local registry"
46+
KIND_CLUSTER_NAME=$CLUSTER_NAME KIND_IMAGE_VERSION=$CLUSTER_NODE_VERSION $SCRIPT_DIR/setup-local-registry.sh
5047
echo "Finished setting up cluster $CLUSTER_NAME"
5148

5249
# so that you can just build the kind image alone if needed
@@ -56,18 +53,15 @@ function create_kind_cluster_or_skip() {
5653
fi
5754
}
5855

59-
# 1. Create a kind cluster (or skip creation if a cluster with name=CLUSTER_NAME already exists)
56+
# 1. Create a kind cluster with local registry (or skip creation if a cluster with name=CLUSTER_NAME already exists)
6057
# This config is roughly based on: https://kind.sigs.k8s.io/docs/user/ingress/
6158
create_kind_cluster_or_skip
6259

6360
if [[ $SKIP_DOCKER == 'true' ]]; then
64-
# TODO(tim): refactor the Makefile & CI scripts so we're loading local
65-
# charts to real helm repos, and then we can remove this block.
6661
echo "SKIP_DOCKER=true, not building images or chart"
6762
else
68-
# 2. Make all the docker images and load them to the kind cluster
69-
VERSION=$VERSION CLUSTER_NAME=$CLUSTER_NAME make kind-build-and-load
70-
63+
# 2. Create buildx builder and build all docker images, pushing to local registry
64+
VERSION=$VERSION make docker-build
7165
# 3. Build the test helm chart, ensuring we have a chart in the `_test` folder
7266
VERSION=$VERSION make package-kgateway-charts
7367

hack/kind/setup-local-registry.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
6+
KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-kind}
7+
KIND_IMAGE_VERSION=${KIND_IMAGE_VERSION:-v1.34.0@sha256:7416a61b42b1662ca6ca89f02028ac133a309a2a30ba309614e8ec94d976dc5a}
8+
9+
# 1. Create registry container unless it already exists
10+
reg_name='kind-registry'
11+
reg_port='5001'
12+
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
13+
docker run \
14+
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --network bridge --name "${reg_name}" \
15+
registry:2
16+
fi
17+
18+
# 2. Create kind cluster with containerd registry config dir enabled
19+
#
20+
# NOTE: the containerd config patch is not necessary with images from kind v0.27.0+
21+
# It may enable some older images to work similarly.
22+
# If you're only supporting newer releases, you can just use `kind create cluster` here.
23+
#
24+
# See:
25+
# https://github.com/kubernetes-sigs/kind/issues/2875
26+
# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration
27+
# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md
28+
if kind get clusters | grep -qx "${KIND_CLUSTER_NAME}"; then
29+
echo "Kind cluster '${KIND_CLUSTER_NAME}' already exists; skipping create."
30+
else
31+
kind create cluster --name "${KIND_CLUSTER_NAME}" \
32+
--config hack/kind/cluster.yaml \
33+
--image="kindest/node:${KIND_IMAGE_VERSION}"
34+
fi
35+
36+
echo "Adding registry config to nodes"
37+
# 3. Add the registry config to the nodes
38+
#
39+
# This is necessary because localhost resolves to loopback addresses that are
40+
# network-namespace local.
41+
# In other words: localhost in the container is not localhost on the host.
42+
#
43+
# We want a consistent name that works from both ends, so we tell containerd to
44+
# alias localhost:${reg_port} to the registry container when pulling images
45+
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
46+
for node in $(kind get nodes --name "${KIND_CLUSTER_NAME}"); do
47+
docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
48+
cat <<EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
49+
[host."http://${reg_name}:5000"]
50+
EOF
51+
done
52+
53+
echo "Connecting registry to cluster network"
54+
# 4. Connect the registry to the cluster network if not already connected
55+
# This allows kind to bootstrap the network but ensures they're on the same network
56+
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
57+
docker network connect "kind" "${reg_name}"
58+
fi
59+
60+
# 5. Document the local registry
61+
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
62+
cat <<EOF | kubectl apply -f -
63+
apiVersion: v1
64+
kind: ConfigMap
65+
metadata:
66+
name: local-registry-hosting
67+
namespace: kube-public
68+
data:
69+
localRegistryHosting.v1: |
70+
host: "localhost:${reg_port}"
71+
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
72+
EOF

0 commit comments

Comments
 (0)