Skip to content

Commit

Permalink
feat: ./hack/launch-local-ca.sh for dev prod
Browse files Browse the repository at this point in the history
  • Loading branch information
elankath committed Nov 21, 2024
1 parent db938d5 commit 5cb92cf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cluster-autoscaler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Session.vim
.netrwhist
.vscode
./integration/logs
.env
integration/logs/autoscaler_processs.log
58 changes: 58 additions & 0 deletions cluster-autoscaler/hack/launch-local-ca.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env zsh
set -eo pipefail

echoErr() { echo "$@" 1>&2; }


CURRENT_DIR=$(pwd)
PROJECT_ROOT="${CURRENT_DIR}"

if ! command -v gum &>/dev/null; then
echoErr "gum not installed. Kindly first install gum (https://github.com/charmbracelet/gum) using relevant procedure for your OS"
exit 1
fi

devEnvFile="$PROJECT_ROOT/.env"
if [[ ! -f "$devEnvFile" ]]; then
echoErr "ERROR: $devEnvFile is not created. Kindly execute ./hack/local_setup.sh before running this script."
exit 2
fi

source "$devEnvFile"

if [[ ! -f "$CONTROL_KUBECONFIG" ]]; then
echoErr "ERROR: Control Cluster kubeconfig is not at expected path $CONTROL_KUBECONFIG. Please ensure that ./hack/local_setup.sh is run correctly."
exit 3
fi

if [[ -z "$GARDEN_PROJECT" ]]; then
echoErr "ERROR: GARDEN_PROJECT env-var not set. Please ensure that ./hack/local_setup.sh is run correctly and check $devEnvFile.."
exit 4
fi

if [[ -z "$SHOOT" ]]; then
echoErr "ERROR: SHOOT env-var not set. Please ensure that ./hack/local_setup.sh is run correctly and check $devEnvFile."
exit 5
fi

if [[ ! -f "main.go" ]]; then
echoErr "ERROR: CA main.go missing in current dir. Please ensure you are in the right cluster-autoscaler dir."
exit 6
fi

echo "NOTE: This script generates a /tmp/local-ca.sh which launches the local CA with the same configuration as that of the remote CA in the configured shoot's control plane"

echo "Targeting control plane of sap-landscape-dev:$GARDEN_PROJECT:$SHOOT"
gardenctl target --garden sap-landscape-dev --project "$GARDEN_PROJECT" --shoot aw --control-plane
caDeploJsonPath="/tmp/ca-deploy.json"
kubectl get deploy cluster-autoscaler -ojson > "$caDeploJsonPath"
echo "Downloaded CA Deployment JSON YAML into $caDeploJsonPath"

commandArgs=$(jq -r '.spec.template.spec.containers[0].command[]' "$caDeploJsonPath" | sed 1d | sed /--kubeconfig/d | tr '\n' ' ')
export CONTROL_KUBECONFIG="$CONTROL_KUBECONFIG"
export CONTROL_NAMESPACE="$CONTROL_NAMESPACE"
export TARGET_KUBECONFIG="$TARGET_KUBECONFIG"
launchCommand="go run main.go --kubeconfig=$TARGET_KUBECONFIG $commandArgs 2>&1 | tee /tmp/ca.log"
gum confirm "Launch local CA using following command: '$launchCommand' ?" && echo "$launchCommand" && eval "$launchCommand"


18 changes: 18 additions & 0 deletions cluster-autoscaler/hack/local_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ GARDEN_NAMESPACE=garden
gardenctl target --garden sap-landscape-dev
eval $(gardenctl kubectl-env bash)

if [[ ! -d "$KUBECONFIG_PATH" ]]; then
mkdir -p "$KUBECONFIG_PATH"
echo "Created dirs $KUBECONFIG_PATH"
fi

#setting kubeconfig of control cluster

echo "$(kubectl create -f $PROJECT_ROOT/hack/kubeconfig-request.json --raw /apis/core.gardener.cloud/v1beta1/namespaces/${GARDEN_NAMESPACE}/shoots/${SEED}/adminkubeconfig | jq -r ".status.kubeconfig" | base64 -d)" > $KUBECONFIG_PATH/kubeconfig_control.yaml
Expand All @@ -63,3 +68,16 @@ echo "kubeconfigs have been downloaded and kept at /dev/kubeconfigs/kubeconfig_<
export CONTROL_NAMESPACE=shoot--$PROJECT--$SHOOT
export CONTROL_KUBECONFIG=$KUBECONFIG_PATH/kubeconfig_control.yaml
export TARGET_KUBECONFIG=$KUBECONFIG_PATH/kubeconfig_target.yaml

devEnvFile="$PROJECT_ROOT/.env"
cat << EOF >"$devEnvFile"
CONTROL_NAMESPACE="$CONTROL_NAMESPACE"
CONTROL_KUBECONFIG="$CONTROL_KUBECONFIG"
TARGET_KUBECONFIG="$TARGET_KUBECONFIG"
PROJECT_ROOT="$PROJECT_ROOT"
GARDEN_PROJECT="$PROJECT"
GARDEN_PROJECT_NAMESPACE="$NAMESPACE"
SHOOT="$SHOOT"
EOF

echo "Wrote $devEnvFile"

0 comments on commit 5cb92cf

Please sign in to comment.