Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up local testing by priming Kind cluster's docker registry with all required images #340

Closed
wants to merge 8 commits into from
Closed
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
4 changes: 4 additions & 0 deletions .kind-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
endpoint = ["http://kind-registry:5000"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["http://kind-registry:5000"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."quay.io"]
endpoint = ["http://kind-registry:5000"]
106 changes: 59 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,82 +21,113 @@ endif

all: manager

# Create a local docker registry, start kind cluster, and install Orkestra
## Create kind cluster with local registry and prepopulate the local registry.
setup: kind-create prepopulate-kind-registry

## Deploy the Orkestra helm chart (values-ci.yaml) with Orkestra controller disabled.
dev:
make kind-create
helm upgrade --install orkestra chart/orkestra --wait --atomic -n orkestra --create-namespace --values ${CI_VALUES}

## Deploy the Orkestra helm chart (values-ci.yaml) with Orkestra controller enabled (in debug mode).
debug: dev
go run main.go --debug --log-level ${DEBUG_LEVEL}

## Cleanup any Orkestra installation and the kind cluster with registry.
clean: kind-delete
@rm -rf $(BIN_DIR)

## Cleanup any previous Orkestra helm chart installation.
clean-chart:
helm delete orkestra -n orkestra 2>&1 || true
@rm -rf $(BIN_DIR)

## Run tests.
test: install
go test -v ./... -coverprofile coverage.txt -timeout 35m

## Run tests using Ginkgo.
ginkgo-test: install
go get github.com/onsi/ginkgo/ginkgo
ginkgo ./... -cover -coverprofile coverage.txt

# Run tests
test: install
go test -v ./... -coverprofile coverage.txt -timeout 35m
## Prepare code for PR.
prepare-for-pr: vet fmt api-docs
@echo "\n> ❗️ Remember to run the tests"

# Build manager binary
## Build manager binary.
manager: generate fmt vet
go build -o bin/manager main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
## Run against the configured Kubernetes cluster in ~/.kube/config.
run: generate fmt vet manifests
go run ./main.go

# Install CRDs into a cluster
## Install CRDs into a cluster.
install: manifests
kustomize build config/crd | kubectl apply -f -

# Uninstall CRDs from a cluster
## Uninstall CRDs from a cluster.
uninstall: manifests
kustomize build config/crd | kubectl delete -f -

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
# #Deploy controller in the configured Kubernetes cluster in ~/.kube/config.
deploy: manifests
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
## Generate code.
generate: controller-gen
mahalrs marked this conversation as resolved.
Show resolved Hide resolved
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

## Generate manifests e.g. CRD, RBAC etc.
manifests: generate
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=chart/orkestra/crds

# Prepare code for PR
prepare-for-pr: vet fmt api-docs

# Generate API reference documentation
## Generate API reference documentation.
api-docs: gen-crd-api-reference-docs
$(API_REF_GEN) -api-dir=./api/v1alpha1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/api.md

# Run go fmt against code
## Create kind cluster with the local registry enabled in containerd.
kind-create:
@echo "> 🔨 Creating kind cluster with local registry...\n"
bash ./hack/create-kind-with-registry.sh
@echo "> 👍 Done\n"

## Delete kind cluster with the local registry enabled in containerd.
kind-delete:
@echo "> 🔨 Deleting kind cluster with local registry...\n"
bash ./hack/teardown-kind-with-registry.sh
@echo "> 👍 Done\n"

## Prepopulate kind registry with required docker images.
prepopulate-kind-registry:
@echo "> 🔨 Prepopulating kind registry...\n"
bash ./hack/prepopulate-kind-registry.sh
@echo "> 👍 Done\n"

## Run go fmt against code.
fmt:
go fmt ./...

# Run go vet against code
## Run go vet against code.
vet:
go vet ./...

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# Build the docker image
## Build the docker image.
docker-build: test
docker build . -t ${IMG}

# Push the docker image
## Push the docker image.
docker-push:
docker push ${IMG}

# setup kubebuilder
## setup kubebuilder.
setup-kubebuilder:
bash hack/setup-envtest.sh;
bash hack/setup-kubebuilder.sh

# find or download controller-gen
# download controller-gen if necessary
## Find or download controller-gen.
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
Expand All @@ -112,7 +143,7 @@ else
CONTROLLER_GEN=$(shell which controller-gen)
endif

# Find or download gen-crd-api-reference-docs
## Find or download gen-crd-api-reference-docs.
gen-crd-api-reference-docs:
ifeq (, $(shell which gen-crd-api-reference-docs))
@{ \
Expand All @@ -127,22 +158,3 @@ API_REF_GEN=$(GOBIN)/gen-crd-api-reference-docs
else
API_REF_GEN=$(shell which gen-crd-api-reference-docs)
endif
## --------------------------------------
## Kind
## --------------------------------------
KIND_CLUSTER_NAME ?= orkestra

kind-create:
./hack/create-kind-cluster.sh
kind load docker-image $(IMG) --name $(KIND_CLUSTER_NAME)

kind-delete:
./hack/teardown-kind-with-registry.sh

## --------------------------------------
## Cleanup
## --------------------------------------

clean:
./hack/teardown-kind-with-registry.sh
@rm -rf $(BIN_DIR)
22 changes: 9 additions & 13 deletions hack/create-kind-cluster.sh → hack/create-kind-with-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,27 @@

set -o errexit

# If you wish to change the cluster name, reg_name or reg_port, make sure to also update
# the following files:
# teardown-kind-with-registry.sh
# .kind-cluster.yaml
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-orkestra}"
reg_name='kind-registry'
reg_port='5000'

if kind get clusters | grep -q ^"${KIND_CLUSTER_NAME}"$ ; then
echo "cluster already exists, moving on"
exit 0
fi

# Create registry container unless it already exists
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
echo "> Creating kind Registry container..."
echo "> Creating Kind Registry container ..."
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
registry:2
else
echo "> Kind Registry container already exists, moving on ..."
fi

# create a kind cluster with the local registry enabled in containerd

kind create cluster --name "${KIND_CLUSTER_NAME}" --config=.kind-cluster.yaml
# Create kind cluster with the local registry enabled in containerd unless it already exists
if kind get clusters | grep -q ^"${KIND_CLUSTER_NAME}"$ ; then
echo "> Kind cluster already exists, moving on ..."
else
kind create cluster --name "${KIND_CLUSTER_NAME}" --config=.kind-cluster.yaml
fi

# connect the registry to the cluster network
# (the network may already be connected)
Expand Down
56 changes: 56 additions & 0 deletions hack/prepopulate-kind-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
mahalrs marked this conversation as resolved.
Show resolved Hide resolved

set -o errexit

KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-orkestra}"
reg_name='kind-registry'

# Check if kind registry container exists.
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
echo "> Kind Registry container ${reg_name} doesn't exist ..."
echo "> Stopping prepopulating kind registry ..."
exit 0
fi

images_to_push=(
"azureorkestra/orkestra:latest"
"chartmuseum/chartmuseum:v0.12.0"
"fluxcd/helm-controller:v0.9.0"
"fluxcd/source-controller:v0.10.0"
"quay.io/argoproj/argocli:v3.0.2"
"quay.io/argoproj/workflow-controller:v3.0.2"
)

# Pull, tag, and push all images to local registry.
# Docker will pull images from remote only if one is not available locally or is not upto date.
# NOTE: We are pushing these images to local registry instead of loading to kind because
# these images either have tag "latest" or have the image pull policy "Always". In both of
# these cases, kind will pull new image even if one is available. So, we want kind to first
# try pulling these images from local registry, and if one is not available, pull from
# remote repository.
for image in ${images_to_push[@]}; do
echo ""
echo "> 🔨 Pull, tag, and push ${image}"
docker pull ${image}
docker tag ${image} localhost:5000/${image}
docker push localhost:5000/${image}
done

images_to_load=(
"docker.io/istio/examples-bookinfo-details-v1:1.16.2"
"docker.io/istio/examples-bookinfo-productpage-v1:1.16.2"
"docker.io/istio/examples-bookinfo-ratings-v1:1.16.2"
"docker.io/istio/examples-bookinfo-reviews-v1:1.16.2"
"docker.io/datawire/aes:1.12.1"
"prom/statsd-exporter:v0.8.1"
"redis:5.0.1"
)

# Pull image if not available locally or is not upto date and then load to kind.
for image in ${images_to_load[@]}; do
echo ""
echo "> 🔨 Pull, load to kind ${image}"
docker pull ${image}
kind load docker-image ${image} --name ${KIND_CLUSTER_NAME}
done
mahalrs marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions hack/teardown-kind-with-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

set -o errexit

KIND_CLUSTER_NAME='orkestra'
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-orkestra}"
reg_name='kind-registry'

# Delete registry container if it exists
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" == 'true' ]; then
cid="$(docker inspect -f '{{.ID}}' "${reg_name}")"
echo "> Stopping and deleting Kind Registry container..."
echo "> Stopping and deleting Kind Registry container ..."
docker stop $cid >/dev/null
docker rm $cid >/dev/null
else
echo "Kind Registry doesn't exist, moving on ..."
fi

kind delete cluster --name=$KIND_CLUSTER_NAME 2>&1