diff --git a/bin/dev b/bin/dev index f0d363a..be053b9 100755 --- a/bin/dev +++ b/bin/dev @@ -10,60 +10,9 @@ ROOT_FOLDER=$(realpath $0 | xargs dirname | xargs dirname) pushd $ROOT_FOLDER > /dev/null - - -function run-bootstrap-argo() { - : Initial setup for argocd - : - deployment=${1} - check-deploy-name $deployment - echo "Installing initial Chart..." - helm install argocd k8s/argocd \ - --namespace argocd \ - --create-namespace \ - --values k8s/argocd/values.yaml \ - --set selfapp.deployment="${DEPLOYMENT}" \ - --set selfapp.sshkey="$(cat ~/.ssh/github_ed)" - - echo "Waiting on argo to get started..." - while ! check-argo-alive; do - echo "Waiting on argo to get started..." - kubectl -n argocd get all - sleep 1 - done - sleep 5 - - echo "Login to argo" - argocd login cd.argoproj.io --core - kubectl config set-context --current --namespace argocd - argocd admin initial-password -} - -function run-upgrade-argo() { - : Manually upgrade argocd from disk - : - deployment=${1} - check-deploy-name $deployment - - pushd $ROOT_FOLDER/k8s/argocd - helm dependency update - popd - - helm upgrade argocd k8s/argocd \ - --namespace argocd \ - --create-namespace \ - --values k8s/argocd/values.yaml \ - --set selfapp.enabled="true" \ - --set selfapp.deployment="${deployment}" \ - --set selfapp.sshkey="$(cat ~/.ssh/github_ed)" -} - -function run-port-forward-argo() { - : Port forward argocd to local - : - local_port=${1:-8080} - kubectl port-forward services/argocd-server $local_port:80 -n argocd -} +tfvar_file=$ROOT_FOLDER/var.auto.tfvars +tfvar_ns=default +kubectl config use-context homelab function run-new-chart() { : Create a new helm chart @@ -86,4 +35,21 @@ dependencies: [] EOT } +function run-upload-tfvars() { + : Uploads tfvars to k8s cluster + : dev upload-tfvars + kubectl -n $tfvar_ns create secret generic tfvars \ + --dry-run=client \ + --save-config \ + --from-file=tfvars=./$tfvar_file \ + -o yaml | \ + kubectl -n $tfvar_ns apply -f - +} + +function run-download-tfvars() { + : Download tfvars from k8s cluster + : dev download-tfvars + kubectl -n $tfvar_ns get secrets/tfvars -o jsonpath='{.data.tfvars}' | base64 -d > $tfvar_file +} + start_cli $@ \ No newline at end of file diff --git a/bin/dryrun-app b/bin/dryrun-app deleted file mode 100755 index 308ccaa..0000000 --- a/bin/dryrun-app +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -set -e - -full_path=${1} -deployment=${2:-dev} -keep_old=${3:-no} -keep_old=$(echo "${keep_old:0:1}" | tr '[:upper:]' '[:lower:]') -app=$(basename $full_path) -location=$(dirname $full_path) -tmp_path=".tmp/$location/$deployment-$app.yaml" -chart_checksum_path=".tmp/.checksums/$location/$deployment-$app.chart.yaml.checksum" - -echo "Running for $app:$deployment" - -mkdir -p $(dirname $tmp_path) - -previous_checksum="" -if [ -f "$chart_checksum_path" ]; then - previous_checksum=$(cat $chart_checksum_path) -else - mkdir -p $(dirname $chart_checksum_path) -fi -pushd $full_path &> /dev/null -chart_checksum=$(sha256sum Chart.yaml | cut -d ' ' -f 1) -echo " > Current Chart.yaml checksum: $chart_checksum" -echo " > Previous Chart.yaml checksum: $previous_checksum" -if [ "$chart_checksum" == "$previous_checksum" ]; then - echo " > skipping helm update!" -else - echo " > updating dependencies..." - helm dependency update -fi -popd &> /dev/null -echo $chart_checksum > $chart_checksum_path - -if [ -f "$tmp_path" ]; then - echo "Found existing file" - if [[ -f "$tmp_path".old && "${keep_old:0:1}" == "y" ]]; then - num_files=$(ls -1q "${tmp_path}.old"* 2> /dev/null | wc -l | tr -d '[:space:]') - echo " -> Renaming old file to "$tmp_path".old.${num_files}" - mv $tmp_path $tmp_path".old.${num_files}" - else - rm -f $tmp_path".old.*" - echo " -> Renaming old file to "$tmp_path".old" - mv $tmp_path $tmp_path".old" - fi -fi - -echo " > running..." - -helm template $app $full_path --namespace $app \ ---debug \ ---values $full_path/values.yaml \ ---values $full_path/values-$deployment.yaml \ -> $tmp_path - -echo "Wrote Template! --> $tmp_path" -echo "===============" - -if [ -f "$tmp_path.old" ]; then - echo " -> creating diff -- $tmp_path.diff" - diff -u $tmp_path".old" $tmp_path > "$tmp_path.diff" -fi \ No newline at end of file diff --git a/flake.nix b/flake.nix index 81493dc..bec12a2 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,7 @@ bat jq # k8s + kubectx k3d (wrapHelm kubernetes-helm { plugins = with pkgs.kubernetes-helmPlugins; [ @@ -33,7 +34,7 @@ shellHook = '' echo "$(pwd)" export PATH="$(pwd)/bin:$PATH" - export PROMPT="🏠> $PROMPT" + export PROMPT="🏠|$(kubectx -c)/$(kubens -c)> $PROMPT" export KUBE_CONFIG_PATH=~/.kube/config echo "Welcome to HomeLab!" '';