From 5a9af71cc915d0afce277664edd94b56b99ef9d9 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Wed, 13 Nov 2024 12:15:50 +0000 Subject: [PATCH 1/8] chore(local-dev): add node0 affinity on the patches for local dev with EC --- dev/patches/kotsadm-up.yaml | 9 +++++++++ dev/patches/kotsadm-web-up.yaml | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/dev/patches/kotsadm-up.yaml b/dev/patches/kotsadm-up.yaml index ea0958a1e7..cef1cd8fc6 100644 --- a/dev/patches/kotsadm-up.yaml +++ b/dev/patches/kotsadm-up.yaml @@ -6,6 +6,15 @@ spec: hostPath: path: __PROJECT_DIR__ type: Directory + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - node0 containers: - name: kotsadm image: kotsadm-api-dev diff --git a/dev/patches/kotsadm-web-up.yaml b/dev/patches/kotsadm-web-up.yaml index 0595d2f135..0cb81a3ffd 100644 --- a/dev/patches/kotsadm-web-up.yaml +++ b/dev/patches/kotsadm-web-up.yaml @@ -1,6 +1,15 @@ spec: template: spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - node0 volumes: - name: dev hostPath: From f347a88cd5bffe4ae7482862d4f38536f86d7a26 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Thu, 14 Nov 2024 13:43:34 +0000 Subject: [PATCH 2/8] chore: use EC_NODE for dev script --- dev/patches/kotsadm-up.yaml | 2 +- dev/patches/kotsadm-web-up.yaml | 2 +- dev/patches/kurl-proxy-up.yaml | 9 +++++++++ dev/scripts/common.sh | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dev/patches/kotsadm-up.yaml b/dev/patches/kotsadm-up.yaml index cef1cd8fc6..2f42b1fca5 100644 --- a/dev/patches/kotsadm-up.yaml +++ b/dev/patches/kotsadm-up.yaml @@ -14,7 +14,7 @@ spec: - key: kubernetes.io/hostname operator: In values: - - node0 + - __NODE_NAME__ containers: - name: kotsadm image: kotsadm-api-dev diff --git a/dev/patches/kotsadm-web-up.yaml b/dev/patches/kotsadm-web-up.yaml index 0cb81a3ffd..f0e91d225a 100644 --- a/dev/patches/kotsadm-web-up.yaml +++ b/dev/patches/kotsadm-web-up.yaml @@ -9,7 +9,7 @@ spec: - key: kubernetes.io/hostname operator: In values: - - node0 + - __NODE_NAME__ volumes: - name: dev hostPath: diff --git a/dev/patches/kurl-proxy-up.yaml b/dev/patches/kurl-proxy-up.yaml index c924d4fb0c..b3cef0ca82 100644 --- a/dev/patches/kurl-proxy-up.yaml +++ b/dev/patches/kurl-proxy-up.yaml @@ -10,6 +10,15 @@ spec: hostPath: path: __PROJECT_DIR__/kurl_proxy/assets type: Directory + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - __NODE_NAME__ containers: - name: proxy image: kurl-proxy-dev diff --git a/dev/scripts/common.sh b/dev/scripts/common.sh index 700790fb1d..c7da9239ae 100644 --- a/dev/scripts/common.sh +++ b/dev/scripts/common.sh @@ -73,7 +73,7 @@ function render() { # The embedded-cluster container mounts the KOTS project at /replicatedhq/kots function ec_render() { - sed "s|__PROJECT_DIR__|/replicatedhq/kots|g" "$1" + sed "s|__PROJECT_DIR__|/replicatedhq/kots|g ; s|__NODE_NAME__|$(ec_node)|g" "$1" } # Get the embedded cluster node name From 440334ac58c37762fa8d79422859005d38631186 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Fri, 15 Nov 2024 20:28:02 +0000 Subject: [PATCH 3/8] chore: use gomplate and make node affinity conditional --- Makefile | 14 +++++++++----- dev/patches/kotsadm-up.yaml | 6 ++++-- dev/scripts/common.sh | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 744437e79f..e28fd9cb6c 100644 --- a/Makefile +++ b/Makefile @@ -90,24 +90,28 @@ mock: mockgen -source=pkg/handlers/interface.go -destination=pkg/handlers/mock/mock.go mockgen -source=pkg/operator/client/client_interface.go -destination=pkg/operator/client/mock/mock.go +.PHONY: install-gomplate +install-gomplate: + go install github.com/hairyhenderson/gomplate/v4/cmd/gomplate@latest + .PHONY: dev -dev: +dev: install-gomplate @dev/scripts/dev.sh .PHONY: %-up -%-up: +%-up: install-gomplate @dev/scripts/up.sh $* .PHONY: %-down -%-down: +%-down: install-gomplate @dev/scripts/down.sh $* .PHONY: %-up-ec -%-up-ec: +%-up-ec: install-gomplate @dev/scripts/up-ec.sh $* .PHONY: %-down-ec -%-down-ec: +%-down-ec: install-gomplate @dev/scripts/down-ec.sh $* .PHONY: reset diff --git a/dev/patches/kotsadm-up.yaml b/dev/patches/kotsadm-up.yaml index 2f42b1fca5..167c7c417e 100644 --- a/dev/patches/kotsadm-up.yaml +++ b/dev/patches/kotsadm-up.yaml @@ -4,8 +4,9 @@ spec: volumes: - name: dev hostPath: - path: __PROJECT_DIR__ + path: {{ .Env.PROJECT_DIR }} type: Directory +{{- if .Env.EC_NODE }} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: @@ -14,7 +15,8 @@ spec: - key: kubernetes.io/hostname operator: In values: - - __NODE_NAME__ + - {{ .Env.EC_NODE }} +{{- end }} containers: - name: kotsadm image: kotsadm-api-dev diff --git a/dev/scripts/common.sh b/dev/scripts/common.sh index c7da9239ae..77649b2fe3 100644 --- a/dev/scripts/common.sh +++ b/dev/scripts/common.sh @@ -68,12 +68,12 @@ function restart() { # the mounted directories from the macOS host filesystem into the Docker Desktop VM. # This is required for using HostPath volumes in Kubernetes. function render() { - sed "s|__PROJECT_DIR__|/host_mnt$(pwd)|g" "$1" + PROJECT_DIR="/host_mnt$(pwd)" gomplate --missing-key zero -f "$1" } # The embedded-cluster container mounts the KOTS project at /replicatedhq/kots function ec_render() { - sed "s|__PROJECT_DIR__|/replicatedhq/kots|g ; s|__NODE_NAME__|$(ec_node)|g" "$1" + EC_NODE=$(ec_node) PROJECT_DIR="/replicatedhq/kots" gomplate --missing-key zero -f "$1" } # Get the embedded cluster node name From 1e2f5a93f1d976384b42d73aadf74ceed38c23e2 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Fri, 15 Nov 2024 20:30:45 +0000 Subject: [PATCH 4/8] chore: down* targets don't need gomplate --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e28fd9cb6c..ac2ab853ff 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,7 @@ dev: install-gomplate @dev/scripts/up.sh $* .PHONY: %-down -%-down: install-gomplate +%-down: @dev/scripts/down.sh $* .PHONY: %-up-ec @@ -111,7 +111,7 @@ dev: install-gomplate @dev/scripts/up-ec.sh $* .PHONY: %-down-ec -%-down-ec: install-gomplate +%-down-ec: @dev/scripts/down-ec.sh $* .PHONY: reset From 0cdaadb4b82af0ecf6b6284b91a7e82245dd43b5 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Fri, 15 Nov 2024 20:36:28 +0000 Subject: [PATCH 5/8] chore: missing templates --- dev/patches/kotsadm-web-up.yaml | 8 +++++--- dev/patches/kurl-proxy-up.yaml | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dev/patches/kotsadm-web-up.yaml b/dev/patches/kotsadm-web-up.yaml index f0e91d225a..b1c28eb971 100644 --- a/dev/patches/kotsadm-web-up.yaml +++ b/dev/patches/kotsadm-web-up.yaml @@ -1,6 +1,7 @@ spec: template: spec: +{{- if .Env.EC_NODE }} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: @@ -9,15 +10,16 @@ spec: - key: kubernetes.io/hostname operator: In values: - - __NODE_NAME__ + - {{ .Env.EC_NODE }} +{{- end }} volumes: - name: dev hostPath: - path: __PROJECT_DIR__/web + path: {{ .Env.PROJECT_DIR }}/web type: Directory - name: yarncache hostPath: - path: __PROJECT_DIR__/dev/.yarncache + path: {{ .Env.PROJECT_DIR }}/dev/.yarncache type: Directory containers: - name: kotsadm-web diff --git a/dev/patches/kurl-proxy-up.yaml b/dev/patches/kurl-proxy-up.yaml index b3cef0ca82..1d2bd1659a 100644 --- a/dev/patches/kurl-proxy-up.yaml +++ b/dev/patches/kurl-proxy-up.yaml @@ -4,12 +4,13 @@ spec: volumes: - name: dev hostPath: - path: __PROJECT_DIR__ + path: {{ .Env.PROJECT_DIR }} type: Directory - name: assets hostPath: - path: __PROJECT_DIR__/kurl_proxy/assets + path: {{ .Env.PROJECT_DIR }}/kurl_proxy/assets type: Directory +{{- if .Env.EC_NODE }} affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: @@ -18,7 +19,8 @@ spec: - key: kubernetes.io/hostname operator: In values: - - __NODE_NAME__ + - {{ .Env.EC_NODE }} +{{- end }} containers: - name: proxy image: kurl-proxy-dev From bf5dce9eff3841b338b7daa8232cf5c46acd2df1 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Tue, 19 Nov 2024 15:51:31 +0000 Subject: [PATCH 6/8] chore: create dev-deps script --- Makefile | 12 ++++++------ dev/scripts/dev-deps.sh | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100755 dev/scripts/dev-deps.sh diff --git a/Makefile b/Makefile index ac2ab853ff..8e03a180b9 100644 --- a/Makefile +++ b/Makefile @@ -90,16 +90,16 @@ mock: mockgen -source=pkg/handlers/interface.go -destination=pkg/handlers/mock/mock.go mockgen -source=pkg/operator/client/client_interface.go -destination=pkg/operator/client/mock/mock.go -.PHONY: install-gomplate -install-gomplate: - go install github.com/hairyhenderson/gomplate/v4/cmd/gomplate@latest +.PHONY: dev-deps +dev-deps: + @dev/scripts/dev-deps.sh .PHONY: dev -dev: install-gomplate +dev: dev-deps @dev/scripts/dev.sh .PHONY: %-up -%-up: install-gomplate +%-up: dev-deps @dev/scripts/up.sh $* .PHONY: %-down @@ -107,7 +107,7 @@ dev: install-gomplate @dev/scripts/down.sh $* .PHONY: %-up-ec -%-up-ec: install-gomplate +%-up-ec: dev-deps @dev/scripts/up-ec.sh $* .PHONY: %-down-ec diff --git a/dev/scripts/dev-deps.sh b/dev/scripts/dev-deps.sh new file mode 100755 index 0000000000..2825e66a9a --- /dev/null +++ b/dev/scripts/dev-deps.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +function is_not_in_path() { + if ! which "$1" > /dev/null; then + echo "$1 is not installed" + return 0 + fi + return 1 +} + +function check_gomplate() { + if is_not_in_path gomplate; then + echo "gomplate is not installed. Installing it now." + go install github.com/hairyhenderson/gomplate/v4/cmd/gomplate@latest + fi +} + +check_gomplate From 8bbd1a7183aef23daae3ec99ff2e147acdf26456 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Tue, 19 Nov 2024 18:08:52 +0000 Subject: [PATCH 7/8] chore: also install jq and update README.md --- README.md | 3 ++- dev/scripts/dev-deps.sh | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1fcfae0d99..2083d1b4b2 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ cosign verify-blob --key sbom/key.pub --signature sbom/kots-sbom.tgz.sig sbom/ko - MacOS - Docker Desktop with Kubernetes enabled -- jq +- gomplate (we'll automatically install this for you) +- jq (we'll automatically install this for you using brew if available) ### Running the Development Environment diff --git a/dev/scripts/dev-deps.sh b/dev/scripts/dev-deps.sh index 2825e66a9a..2a66c83ad4 100755 --- a/dev/scripts/dev-deps.sh +++ b/dev/scripts/dev-deps.sh @@ -3,7 +3,7 @@ set -e function is_not_in_path() { - if ! which "$1" > /dev/null; then + if ! command -v "$1" > /dev/null; then echo "$1 is not installed" return 0 fi @@ -17,4 +17,16 @@ function check_gomplate() { fi } +function check_jq() { + if is_not_in_path jq; then + echo "jq is not installed. Attempting to install it using brew." + if is_not_in_path brew; then + echo "brew is not installed. Please install jq manually." + return + fi + brew install jq + fi +} + check_gomplate +check_jq From 0ada73752f8e4d608a282a18d1799013f9b876ac Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Tue, 19 Nov 2024 19:30:21 +0000 Subject: [PATCH 8/8] chore: update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 2083d1b4b2..33a5da6a72 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,7 @@ cosign verify-blob --key sbom/key.pub --signature sbom/kots-sbom.tgz.sig sbom/ko - MacOS - Docker Desktop with Kubernetes enabled -- gomplate (we'll automatically install this for you) -- jq (we'll automatically install this for you using brew if available) +- Homebrew ### Running the Development Environment