From 4cd45acc0ec44fbb40a8b7d6c976dd7d668d452b Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Sat, 8 Jun 2024 11:55:00 -0600 Subject: [PATCH] Fixes: Fixes some non-customizable values. Add KUBECONFIG to all commands. There seems to be an issue when the users existing env has a KUBECONFIG defined. The KUBECONFIG in the `env` section of Tasks doesn't take precedence. Signed-off-by: Jacob Weinstock --- playground/config.yaml | 10 +++++----- playground/scripts/generate_hardware.sh | 4 +++- playground/scripts/generate_secret.sh | 4 ++-- playground/scripts/generate_state.sh | 2 +- playground/scripts/virtualbmc.sh | 5 +++-- playground/tasks/Taskfile-capi.yaml | 14 +++++++++---- playground/tasks/Taskfile-create.yaml | 26 +++++++++++++++---------- playground/tasks/Taskfile-vbmc.yaml | 2 +- playground/templates/hardware.tmpl | 2 +- 9 files changed, 42 insertions(+), 27 deletions(-) diff --git a/playground/config.yaml b/playground/config.yaml index 1a89d09e..dc835c73 100644 --- a/playground/config.yaml +++ b/playground/config.yaml @@ -1,10 +1,10 @@ --- clusterName: "capt-playground" -outputDir: "/home/tink/repos/tinkerbell/cluster-api-provider-tinkerbell/playground/new/output" -namespace: "tink-system" +outputDir: "output" +namespace: "tink" counts: controlPlanes: 1 - workers: 2 + workers: 1 spares: 1 versions: capt: 0.5.3 @@ -24,5 +24,5 @@ vm: virtualBMC: containerName: "virtualbmc" image: ghcr.io/jacobweinstock/virtualbmc - user: "admin" - pass: "passwordq" + user: "root" + pass: "calvin" diff --git a/playground/scripts/generate_hardware.sh b/playground/scripts/generate_hardware.sh index 8a21a845..a87516d2 100755 --- a/playground/scripts/generate_hardware.sh +++ b/playground/scripts/generate_hardware.sh @@ -8,6 +8,7 @@ function main() { # Generate hardware declare -r STATE_FILE="$1" declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE") + declare -r NS=$(yq eval '.namespace' "$STATE_FILE") rm -f "$OUTPUT_DIR"/hardware*.yaml @@ -16,7 +17,8 @@ function main() { export NODE_MAC="$mac" export NODE_ROLE="$role" export NODE_IP="$ip" - export GATEWAY_IP="$gateway" + export GATEWAY_IP="$gateway" + export NAMESPACE="$NS" envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" < templates/hardware.tmpl > "$OUTPUT_DIR"/hardware-"$NODE_NAME".yaml unset NODE_ROLE unset NODE_NAME diff --git a/playground/scripts/generate_secret.sh b/playground/scripts/generate_secret.sh index c8cf9b9a..6e3f7c19 100755 --- a/playground/scripts/generate_secret.sh +++ b/playground/scripts/generate_secret.sh @@ -6,8 +6,8 @@ function main() { declare -r STATE_FILE="$1" declare -r OUTPUT_DIR=$(yq eval '.outputDir' "$STATE_FILE") export NAMESPACE=$(yq eval '.namespace' "$STATE_FILE") - export BMC_USER_BASE64=$(yq eval '.virtualBMC.user' "$STATE_FILE" | base64) - export BMC_PASS_BASE64=$(yq eval '.virtualBMC.pass' "$STATE_FILE" | base64) + export BMC_USER_BASE64=$(yq eval '.virtualBMC.user' "$STATE_FILE" | tr -d '\n' | base64) + export BMC_PASS_BASE64=$(yq eval '.virtualBMC.pass' "$STATE_FILE" | tr -d '\n' | base64) envsubst "$(printf '${%s} ' $(env | cut -d'=' -f1))" < templates/bmc-secret.tmpl > "$OUTPUT_DIR"/bmc-secret.yaml unset BMC_USER_BASE64 diff --git a/playground/scripts/generate_state.sh b/playground/scripts/generate_state.sh index 3438eeb5..af3cadbc 100755 --- a/playground/scripts/generate_state.sh +++ b/playground/scripts/generate_state.sh @@ -72,7 +72,7 @@ function main() { if [[ "$output_dir" = /* ]]; then echo else - current_dir=$(realpath) + current_dir=$(pwd) output_dir="$current_dir/$output_dir" fi config_file=$(realpath "$CONFIG_FILE") diff --git a/playground/scripts/virtualbmc.sh b/playground/scripts/virtualbmc.sh index f85dd74d..0a0ab167 100755 --- a/playground/scripts/virtualbmc.sh +++ b/playground/scripts/virtualbmc.sh @@ -11,9 +11,10 @@ function main() { username=$(yq eval '.virtualBMC.user' "$STATE_FILE") password=$(yq eval '.virtualBMC.pass' "$STATE_FILE") + container_name=$(yq eval '.virtualBMC.containerName' "$STATE_FILE") while IFS=$',' read -r name port; do - docker exec virtualbmc vbmc add --username "$username" --password "$password" --port "$port" "$name" - docker exec virtualbmc vbmc start "$name" + docker exec "$container_name" vbmc add --username "$username" --password "$password" --port "$port" "$name" + docker exec "$container_name" vbmc start "$name" done < <(yq e '.vm.details.[] | [key, .bmc.port] | @csv' "$STATE_FILE") } diff --git a/playground/tasks/Taskfile-capi.yaml b/playground/tasks/Taskfile-capi.yaml index b470dd30..9e60eb3e 100644 --- a/playground/tasks/Taskfile-capi.yaml +++ b/playground/tasks/Taskfile-capi.yaml @@ -56,10 +56,12 @@ tasks: sh: echo $(yq eval '.outputDir' config.yaml) KIND_GATEWAY_IP: sh: yq eval '.kind.gatewayIP' {{.STATE_FILE_FQ_PATH}} + KUBECONFIG: + sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} cmds: - - clusterctl --config {{.OUTPUT_DIR}}/clusterctl.yaml init --infrastructure tinkerbell + - KUBECONFIG="{{.KUBECONFIG}}" clusterctl --config {{.OUTPUT_DIR}}/clusterctl.yaml init --infrastructure tinkerbell status: - - expected=1; got=$(kubectl get pods -n capt-system |grep -ce "capt-controller"); [[ "$got" == "$expected" ]] + - expected=1; got=$(KUBECONFIG="{{.KUBECONFIG}}" kubectl get pods -n capt-system |grep -ce "capt-controller"); [[ "$got" == "$expected" ]] generate-cluster-yaml: summary: | @@ -92,8 +94,10 @@ tasks: sh: yq eval '.counts.workers' {{.STATE_FILE_FQ_PATH}} NAMESPACE: sh: yq eval '.namespace' {{.STATE_FILE_FQ_PATH}} + KUBECONFIG: + sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} cmds: - - clusterctl generate cluster {{.CLUSTER_NAME}} --config {{.OUTPUT_DIR}}/clusterctl.yaml --kubernetes-version "{{.KUBE_VERSION}}" --control-plane-machine-count="{{.CP_COUNT}}" --worker-machine-count="{{.WORKER_COUNT}}" --target-namespace={{.NAMESPACE}} --write-to {{.OUTPUT_DIR}}/prekustomization.yaml + - KUBECONFIG="{{.KUBECONFIG}}" clusterctl generate cluster {{.CLUSTER_NAME}} --config {{.OUTPUT_DIR}}/clusterctl.yaml --kubernetes-version "{{.KUBE_VERSION}}" --control-plane-machine-count="{{.CP_COUNT}}" --worker-machine-count="{{.WORKER_COUNT}}" --target-namespace={{.NAMESPACE}} --write-to {{.OUTPUT_DIR}}/prekustomization.yaml status: - grep -q "{{.KUBE_VERSION}}" {{.OUTPUT_DIR}}/prekustomization.yaml @@ -133,6 +137,8 @@ tasks: vars: CLUSTER_NAME: sh: yq eval '.clusterName' {{.STATE_FILE_FQ_PATH}} + KUBECONFIG: + sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} env: KUBECONFIG: sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} @@ -142,4 +148,4 @@ tasks: generates: - "{{.OUTPUT_DIR}}/{{.CLUSTER_NAME}}.yaml" cmds: - - kubectl kustomize {{.OUTPUT_DIR}} -o {{.OUTPUT_DIR}}/{{.CLUSTER_NAME}}.yaml \ No newline at end of file + - KUBECONFIG="{{.KUBECONFIG}}" kubectl kustomize {{.OUTPUT_DIR}} -o {{.OUTPUT_DIR}}/{{.CLUSTER_NAME}}.yaml \ No newline at end of file diff --git a/playground/tasks/Taskfile-create.yaml b/playground/tasks/Taskfile-create.yaml index f82b2a72..eb4f45e0 100644 --- a/playground/tasks/Taskfile-create.yaml +++ b/playground/tasks/Taskfile-create.yaml @@ -48,9 +48,9 @@ tasks: sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} cmds: - kind create cluster --name {{.CLUSTER_NAME}} --kubeconfig "{{.KUBECONFIG}}" - - until kubectl wait --for=condition=ready node --all --timeout=5m; do echo "Waiting for nodes to be ready..."; sleep 1; done + - until KUBECONFIG="{{.KUBECONFIG}}" kubectl wait --for=condition=ready node --all --timeout=5m; do echo "Waiting for nodes to be ready..."; sleep 1; done status: - - kind get clusters | grep -q {{.CLUSTER_NAME}} + - KUBECONFIG="{{.KUBECONFIG}}" kind get clusters | grep -q {{.CLUSTER_NAME}} update-state: #deps: [validate-deps, kind-cluster] @@ -114,9 +114,9 @@ tasks: sh: yq eval '.namespace' {{.STATE_FILE_FQ_PATH}} CHART_NAME: tink-stack cmds: - - helm install {{.CHART_NAME}} oci://ghcr.io/tinkerbell/charts/stack --version "{{.STACK_CHART_VERSION}}" --create-namespace --namespace {{.NAMESPACE}} --wait --set "smee.trustedProxies={{.TRUSTED_PROXIES}}" --set "hegel.trustedProxies={{.TRUSTED_PROXIES}}" --set "stack.loadBalancerIP={{.LB_IP}}" --set "smee.publicIP={{.LB_IP}}" + - KUBECONFIG="{{.KUBECONFIG}}" helm install {{.CHART_NAME}} oci://ghcr.io/tinkerbell/charts/stack --version "{{.STACK_CHART_VERSION}}" --create-namespace --namespace {{.NAMESPACE}} --wait --set "smee.trustedProxies={{.TRUSTED_PROXIES}}" --set "hegel.trustedProxies={{.TRUSTED_PROXIES}}" --set "stack.loadBalancerIP={{.LB_IP}}" --set "smee.publicIP={{.LB_IP}}" status: - - helm list -n {{.NAMESPACE}} | grep -q {{.CHART_NAME}} + - KUBECONFIG="{{.KUBECONFIG}}" helm list -n {{.NAMESPACE}} | grep -q {{.CHART_NAME}} vms: #deps: [validate-deps, kind-cluster, update-state] @@ -139,13 +139,15 @@ tasks: vars: NAMESPACE: sh: yq eval '.namespace' {{.STATE_FILE_FQ_PATH}} + KUBECONFIG: + sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} env: KUBECONFIG: sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} cmds: - - kubectl apply -f {{.OUTPUT_DIR}}/bmc-secret.yaml + - KUBECONFIG="{{.KUBECONFIG}}" kubectl apply -f {{.OUTPUT_DIR}}/bmc-secret.yaml status: - - kubectl get secret bmc-creds -n {{.NAMESPACE}} + - KUBECONFIG="{{.KUBECONFIG}}" kubectl get secret bmc-creds -n {{.NAMESPACE}} apply-bmc-machines: #deps: [validate-deps, bmc-machine-cr] @@ -161,14 +163,16 @@ tasks: sh: yq eval '.vm.baseName' {{.STATE_FILE_FQ_PATH}} NAMESPACE: sh: yq eval '.namespace' {{.STATE_FILE_FQ_PATH}} + KUBECONFIG: + sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} env: KUBECONFIG: sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} cmds: - for: { var: NAMES } - cmd: kubectl apply -f {{.OUTPUT_DIR}}/bmc-machine-{{.ITEM}}.yaml + cmd: KUBECONFIG="{{.KUBECONFIG}}" kubectl apply -f {{.OUTPUT_DIR}}/bmc-machine-{{.ITEM}}.yaml status: - - expected={{.TOTAL_HARDWARE}}; got=$(kubectl get machines.bmc -n {{.NAMESPACE}} | grep -ce "{{.VM_BASE_NAME}}*"); [[ "$got" == "$expected" ]] + - expected={{.TOTAL_HARDWARE}}; got=$(KUBECONFIG="{{.KUBECONFIG}}" kubectl get machines.bmc -n {{.NAMESPACE}} | grep -ce "{{.VM_BASE_NAME}}*"); [[ "$got" == "$expected" ]] apply-hardware: #deps: [validate-deps, hardware-cr] @@ -183,11 +187,13 @@ tasks: sh: yq eval '.vm.baseName' {{.STATE_FILE_FQ_PATH}} NAMESPACE: sh: yq eval '.namespace' {{.STATE_FILE_FQ_PATH}} + KUBECONFIG: + sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} env: KUBECONFIG: sh: yq eval '.kind.kubeconfig' {{.STATE_FILE_FQ_PATH}} cmds: - for: { var: NAMES } - cmd: kubectl apply -f {{.OUTPUT_DIR}}/hardware-{{.ITEM}}.yaml + cmd: KUBECONFIG="{{.KUBECONFIG}}" kubectl apply -f {{.OUTPUT_DIR}}/hardware-{{.ITEM}}.yaml status: - - expected={{.TOTAL_HARDWARE}}; got=$(kubectl get hardware -n {{.NAMESPACE}} | grep -ce "{{.VM_BASE_NAME}}*"); [[ "$got" == "$expected" ]] + - expected={{.TOTAL_HARDWARE}}; got=$(KUBECONFIG="{{.KUBECONFIG}}" kubectl get hardware -n {{.NAMESPACE}} | grep -ce "{{.VM_BASE_NAME}}*"); [[ "$got" == "$expected" ]] diff --git a/playground/tasks/Taskfile-vbmc.yaml b/playground/tasks/Taskfile-vbmc.yaml index bd73735c..0486e846 100644 --- a/playground/tasks/Taskfile-vbmc.yaml +++ b/playground/tasks/Taskfile-vbmc.yaml @@ -20,7 +20,7 @@ tasks: VBMC_CONTAINER_IMAGE: sh: yq eval '.virtualBMC.image' {{.STATE_FILE_FQ_PATH}} cmds: - - docker run -d --rm --network kind -v /var/run/libvirt/libvirt-sock-ro:/var/run/libvirt/libvirt-sock-ro -v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock --name {{.VBMC_CONTAINER_NAME}} {{.VBMC_CONTAINER_IMAGE}} + - docker run -d --privileged --rm --network kind -v /var/run/libvirt/libvirt-sock-ro:/var/run/libvirt/libvirt-sock-ro -v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock --name {{.VBMC_CONTAINER_NAME}} {{.VBMC_CONTAINER_IMAGE}} status: - docker ps | grep -q {{.VBMC_CONTAINER_NAME}} diff --git a/playground/templates/hardware.tmpl b/playground/templates/hardware.tmpl index 024b21c5..bdfdd840 100644 --- a/playground/templates/hardware.tmpl +++ b/playground/templates/hardware.tmpl @@ -4,7 +4,7 @@ metadata: labels: tinkerbell.org/role: $NODE_ROLE name: $NODE_NAME - namespace: tink-system + namespace: $NAMESPACE spec: bmcRef: apiGroup: bmc.tinkerbell.org