Skip to content

Commit 44a06a9

Browse files
committed
build: Add make recipes for deploying local builds
Running `make dev.run-on-kind` will start a KinD cluster, use `clusterctl` to deploy relevant providers, build Docker images, copy to the KinD cluster, and deploy the extensions via Helm.
1 parent c6720c7 commit 44a06a9

16 files changed

+219
-5
lines changed

.github/workflows/checks.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ jobs:
5252
with:
5353
asdf_branch: v0.11.0
5454

55+
- name: Build and install on KinD
56+
run: make dev.run-on-kind
57+
5558
- name: Run e2e tests
5659
run: make e2e-test
5760
env:
5861
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5962

63+
- name: Cleanup KinD cluster
64+
if: always()
65+
run: make kind.delete
66+
67+
6068
lint:
6169
runs-on: ubuntu-22.04
6270
steps:

.go-tools

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ github.com/segmentio/[email protected]
33
gotest.tools/[email protected]
44
sigs.k8s.io/controller-runtime/tools/[email protected]
55
github.com/google/go-containerregistry/cmd/[email protected]
6+
github.com/drone/envsubst/cmd/[email protected] # FREEZE

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ repos:
100100
rev: v1.2.0
101101
hooks:
102102
- id: helm-docs
103+
stages: [commit]
103104
args:
104105
# Make the tool search for charts only under the `example-charts` directory
105106
- --chart-search-root=charts

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ golangci-lint 1.50.1
88
goreleaser 1.15.0
99
helm 3.11.0
1010
helm-docs 1.11.0
11+
kind 0.17.0
1112
kube-controller-tools 0.11.2
1213
kubectl 1.26.1
1314
kustomize 4.5.7

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,17 @@
66
# CAPI Runtime Extensions Server
77

88
See [upstream documentation](https://cluster-api.sigs.k8s.io/tasks/experimental-features/runtime-sdk/index.html).
9+
10+
## Development
11+
12+
To deploy a local build, either initial install to update an existing deployment, run:
13+
14+
```shell
15+
make dev.run-on-kind
16+
```
17+
18+
To delete the dev KinD cluster, run:
19+
20+
```shell
21+
make kind.delete
22+
```

hack/common.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env bash
22

3+
# Copyright 2023 D2iQ, Inc. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
36
GIT_REPO_ROOT="$(git rev-parse --show-toplevel)"
47
export GIT_REPO_ROOT

hack/kind/create-cluster.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 D2iQ, Inc. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -euo pipefail
7+
IFS=$'\n\t'
8+
9+
SCRIPT_NAME="$(basename "$0")"
10+
readonly SCRIPT_NAME
11+
12+
function print_usage {
13+
cat >&2 <<EOF
14+
Usage: ${SCRIPT_NAME} [COMMAND] [OPTIONS]
15+
Creates kind cluster with given configuration
16+
Options:
17+
--cluster-name Name of the KinD cluster
18+
--output-dir Output directory for generated resources.
19+
--base-config Base configuration of KinD cluster.
20+
--kindest-image KinD image used in controller-plane
21+
EOF
22+
}
23+
24+
function assert_not_empty {
25+
local -r arg_name="$1"
26+
local -r arg_value="$2"
27+
28+
if [[ -z $arg_value ]]; then
29+
echo "The value for '$arg_name' cannot be empty"
30+
print_usage
31+
exit 1
32+
fi
33+
}
34+
35+
function run_cmd() {
36+
local cluster_name=""
37+
local output_dir=""
38+
local base_config=""
39+
local kindest_image=""
40+
41+
# read options
42+
while [[ $# -gt 0 ]]; do
43+
local key="$1"
44+
case "$key" in
45+
--cluster-name)
46+
cluster_name="$2"
47+
shift
48+
;;
49+
--output-dir)
50+
output_dir="$2"
51+
shift
52+
;;
53+
--base-config)
54+
base_config="$2"
55+
shift
56+
;;
57+
--kindest-image)
58+
kindest_image="$2"
59+
shift
60+
;;
61+
--help)
62+
print_usage
63+
exit
64+
;;
65+
esac
66+
shift
67+
done
68+
69+
# validate parameters
70+
assert_not_empty "--cluster-name" "$cluster_name"
71+
assert_not_empty "--output-dir" "$output_dir"
72+
assert_not_empty "--base-config" "$base_config"
73+
assert_not_empty "--kindest-image" "$kindest_image"
74+
75+
local cluster_config="$output_dir/kind-config.yaml"
76+
77+
# make sure output directory exist
78+
mkdir -p "$output_dir"
79+
80+
# create/override base config
81+
export KINDEST_IMAGE="${kindest_image}"
82+
envsubst <"$base_config" >"$cluster_config"
83+
84+
kind create cluster --name "$cluster_name" --config "$cluster_config"
85+
}
86+
87+
run_cmd "$@"

hack/kind/kind-base-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
kind: Cluster
5+
apiVersion: kind.x-k8s.io/v1alpha4
6+
containerdConfigPatches:
7+
- |-
8+
[plugins."io.containerd.grpc.v1.cri".registry.configs."registry-1.docker.io".auth]
9+
username = "${DOCKER_USERNAME}"
10+
password = "${DOCKER_PASSWORD}"
11+
- |-
12+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
13+
endpoint = ["${DOCKER_MIRROR:-https://registry-1.docker.io}"]
14+
kubeadmConfigPatches:
15+
- |
16+
apiVersion: kubelet.config.k8s.io/v1beta1
17+
kind: KubeletConfiguration
18+
nodeStatusMaxImages: -1
19+
nodes:
20+
- role: control-plane
21+
image: "${KINDEST_IMAGE}"
22+
extraMounts:
23+
- containerPath: "/var/run/docker.sock"
24+
hostPath: "/var/run/docker.sock"

make/all.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ include $(INCLUDE_DIR)ci.mk
1717
include $(INCLUDE_DIR)tag.mk
1818
include $(INCLUDE_DIR)upx.mk
1919
include $(INCLUDE_DIR)addons.mk
20+
include $(INCLUDE_DIR)kind.mk
21+
include $(INCLUDE_DIR)clusterctl.mk
22+
include $(INCLUDE_DIR)dev.mk

make/clusterctl.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
.PHONY: clusterctl.init
5+
clusterctl.init: install-tool.clusterctl
6+
env CLUSTER_TOPOLOGY=true EXP_RUNTIME_SDK=true clusterctl init \
7+
--kubeconfig=$(KIND_KUBECONFIG) \
8+
--infrastructure docker \
9+
--wait-providers
10+
11+
.PHONY: clusterctl.delete
12+
clusterctl.delete: install-tool.clusterctl
13+
clusterctl delete --kubeconfig=$(KIND_KUBECONFIG) --all

make/dev.mk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
.PHONY: dev.run-on-kind
5+
dev.run-on-kind: kind.create clusterctl.init install-tool.helm install-tool.gojq
6+
ifndef SKIP_BUILD
7+
$(MAKE) release-snapshot
8+
endif
9+
kind load docker-image --name $(KIND_CLUSTER_NAME) \
10+
$$(gojq -r '.[] | select(.type=="Docker Image") | select(.goarch=="$(GOARCH)") | .name' dist/artifacts.json)
11+
helm upgrade --install --kubeconfig $(KIND_KUBECONFIG) capi-runtime-extensions ./charts/capi-runtime-extensions \
12+
--set-string image.tag=$$(gojq -r .version dist/metadata.json) \
13+
--wait --wait-for-jobs
14+
kubectl --kubeconfig $(KIND_KUBECONFIG) rollout restart deployment capi-runtime-extensions
15+
kubectl --kubeconfig $(KIND_KUBECONFIG) rollout status deployment capi-runtime-extensions

make/go.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ E2E_FLAKE_ATTEMPTS ?= 1
7878

7979
.PHONY: e2e-test
8080
e2e-test: ## Runs e2e tests
81+
ifneq ($(wildcard test/e2e/*),)
8182
e2e-test: install-tool.golang install-tool.ginkgo install-tool.gojq
8283
$(info $(M) running e2e tests$(if $(E2E_LABEL), labelled "$(E2E_LABEL)")$(if $(E2E_FOCUS), matching "$(E2E_FOCUS)"))
83-
ifneq ($(wildcard test/e2e/*),)
8484
ifneq ($(SKIP_BUILD),true)
8585
$(MAKE) GORELEASER_FLAGS=$$'--config=<(env GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) gojq --yaml-input --yaml-output \'del(.builds[0].goarch) | del(.builds[0].goos) | .builds[0].targets|=(["linux_amd64","linux_arm64",env.GOOS+"_"+env.GOARCH] | unique | map(. | sub("_amd64";"_amd64_v1")))\' .goreleaser.yml) --clean --skip-validate --skip-publish' release
8686
endif

make/kind.mk

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2023 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
KIND_DIR := $(REPO_ROOT)/.local/kind
5+
6+
KIND_CLUSTER_NAME ?= $(GITHUB_REPOSITORY)-dev
7+
KIND_KUBECONFIG ?= $(KIND_DIR)/$(KIND_CLUSTER_NAME)/kubeconfig
8+
9+
KINDEST_NODE_IMAGE ?= kindest/node
10+
KINDEST_NODE_VERSION_v1.24 ?= v1.24.7@sha256:577c630ce8e509131eab1aea12c022190978dd2f745aac5eb1fe65c0807eb315
11+
KINDEST_NODE_VERSION_v1.25 ?= v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1
12+
KINDEST_NODE_VERSION_v1.26 ?= v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352
13+
# Allow easy override of Kubernetes version to use via `make KIND_KUBERNETES_VERSION=v1.23` to use in CI
14+
KIND_KUBERNETES_VERSION ?= v1.26
15+
ifndef KINDEST_NODE_VERSION_$(KIND_KUBERNETES_VERSION)
16+
$(error Unsupported Kind Kubernetes version: $(KIND_KUBERNETES_VERSION) (use on of: [$(patsubst KINDEST_NODE_VERSION_%,%,$(filter KINDEST_NODE_VERSION_%,$(.VARIABLES)))]))
17+
endif
18+
19+
KINDEST_IMAGE = $(KINDEST_NODE_IMAGE):$(KINDEST_NODE_VERSION_$(KIND_KUBERNETES_VERSION))
20+
21+
.PHONY: kind.recreate
22+
kind.recreate: ## Re-creates new KinD cluster if necessary
23+
kind.recreate: kind.delete kind.create
24+
25+
.PHONY: kind.create
26+
kind.create: ## Creates new KinD cluster
27+
kind.create: install-tool.kubectl install-tool.kind install-tool.go.envsubst ; $(info $(M) creating kind cluster - $(KIND_CLUSTER_NAME))
28+
(kind get clusters | grep -Eq '^$(KIND_CLUSTER_NAME)$$' && echo '$(KIND_CLUSTER_NAME) already exists') || \
29+
env KUBECONFIG=$(KIND_KUBECONFIG) $(REPO_ROOT)/hack/kind/create-cluster.sh \
30+
--cluster-name $(KIND_CLUSTER_NAME) \
31+
--kindest-image $(KINDEST_IMAGE) \
32+
--output-dir $(KIND_DIR)/$(KIND_CLUSTER_NAME) \
33+
--base-config $(REPO_ROOT)/hack/kind/kind-base-config.yaml
34+
35+
.PHONY: kind.delete
36+
kind.delete: ## Deletes KinD cluster
37+
kind.delete: install-tool.kind ; $(info $(M) deleting kind cluster - $(KIND_CLUSTER_NAME))
38+
(kind get clusters | grep -Eq '^$(KIND_CLUSTER_NAME)$$' && kind delete cluster --name $(KIND_CLUSTER_NAME)) || \
39+
echo '$(KIND_CLUSTER_NAME) does not exist'
40+
rm -rf $(KIND_DIR)/$(KIND_CLUSTER_NAME)
41+
42+
.PHONY: kind.kubeconfig
43+
kind.kubeconfig: ## Prints export definition for kubeconfig
44+
echo "export KUBECONFIG=$(KIND_KUBECONFIG)"

make/repo.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ GIT_COMMIT := $(shell git rev-parse "HEAD^{commit}")
99
export GIT_TAG ?= $(shell git describe --tags "$(GIT_COMMIT)^{commit}" --match v* --abbrev=0 2>/dev/null)
1010
export GIT_CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
1111

12-
export GITHUB_ORG ?= $(notdir $(realpath $(dir $(REPO_ROOT))))
13-
export GITHUB_REPOSITORY ?= $(notdir $(REPO_ROOT))
12+
export GITHUB_ORG := $(notdir $(realpath $(dir $(REPO_ROOT))))
13+
export GITHUB_REPOSITORY := $(notdir $(REPO_ROOT))
1414

1515
ifneq ($(shell git status --porcelain 2>/dev/null; echo $$?), 0)
1616
export GIT_TREE_STATE := dirty

make/tools.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export PATH := $(GOBIN):$(PATH)
1313
ifneq ($(wildcard $(GO_TOOLS_FILE)),)
1414
define install_go_tool
1515
mkdir -p $(GOBIN)
16-
CGO_ENABLED=0 go install -v $$(grep $1 $(GO_TOOLS_FILE))
16+
CGO_ENABLED=0 go install -v $$(grep -Eo '^.+$1[^ ]+' $(GO_TOOLS_FILE))
1717
endef
1818

1919
.PHONY:

pkg/addons/templates/cni/calico-cni-installation-crs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ spec:
1414
name: tigera-operator
1515
- kind: ConfigMap
1616
name: calico-cni-installation
17-
strategy: ApplyAlways
17+
strategy: ApplyOnce

0 commit comments

Comments
 (0)