Skip to content

Commit

Permalink
Fixes:
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jacobweinstock committed Jun 8, 2024
1 parent 1299c18 commit 4cd45ac
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
10 changes: 5 additions & 5 deletions playground/config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,5 +24,5 @@ vm:
virtualBMC:
containerName: "virtualbmc"
image: ghcr.io/jacobweinstock/virtualbmc
user: "admin"
pass: "passwordq"
user: "root"
pass: "calvin"
4 changes: 3 additions & 1 deletion playground/scripts/generate_hardware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions playground/scripts/generate_secret.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion playground/scripts/generate_state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions playground/scripts/virtualbmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")

}
Expand Down
14 changes: 10 additions & 4 deletions playground/tasks/Taskfile-capi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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}}
Expand All @@ -142,4 +148,4 @@ tasks:
generates:
- "{{.OUTPUT_DIR}}/{{.CLUSTER_NAME}}.yaml"
cmds:
- kubectl kustomize {{.OUTPUT_DIR}} -o {{.OUTPUT_DIR}}/{{.CLUSTER_NAME}}.yaml
- KUBECONFIG="{{.KUBECONFIG}}" kubectl kustomize {{.OUTPUT_DIR}} -o {{.OUTPUT_DIR}}/{{.CLUSTER_NAME}}.yaml
26 changes: 16 additions & 10 deletions playground/tasks/Taskfile-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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" ]]
2 changes: 1 addition & 1 deletion playground/tasks/Taskfile-vbmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down
2 changes: 1 addition & 1 deletion playground/templates/hardware.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4cd45ac

Please sign in to comment.