This commit is contained in:
ari committed 2024-10-30 10:31:46 -04:00
1 parent d307ceb5bb
commit 94d67e4982
17 files changed
+244 -146

No files matched your search

Executable
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
set -e
# Bootstrap
set -e
ROOT_FOLDER=$(realpath $0 | xargs dirname | xargs dirname)
. $ROOT_FOLDER/bin/extra/common.sh
# Bootstrap
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)"
while ! check-argo-alive; do
echo "Waiting on argo to get started"
kubectl -n argocd get all
sleep 1
done
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
}
function run-new-chart() {
: Create a new helm chart
: dev new-chart {path-to-chart}
full_path=${1}
app=$(basename $full_path)
location=$(dirname $full_path)
typeofapp=$(basename $location)
mkdir -p $full_path/templates
touch $full_path/values.yaml
cat <<EOT >> $full_path/Chart.yaml
apiVersion: v2
name: $app
description: An $typeofapp service for homelab
type: application
version: 0.1.0
dependencies: []
EOT
}
start_cli $@
File renamed without changes.
+62
View File
@@ -0,0 +1,62 @@
#!/bin/sh
## Colors
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m'
BOLD='\033[1m'
BLUE_BOLD='\033[1;34m'
YELLOW_BOLD='\033[1;33m'
function list_run_functions() {
declare -F | awk '$3 ~ /^run-/{sub("run-", "", $3); print $3}'
}
function start_cli() {
MENAME=$(basename $0)
all_functions=$(list_run_functions)
for f in ${all_functions[@]}; do
if [ "$1" == "$f" ]; then
echo -e "Running ${BLUE_BOLD}$1${NC}"
run-$1 ${@:2} 2>&1 | sed "s/^/\t│ /"
ecode=$(echo $?)
echo -e "\t└──${NC}DONE ${BLUE_BOLD}$1${NC}"
exit $ecode
fi
done
echo -e "Invalid Command '$1' please select one of${NC}"
for function_name in $all_functions; do
start_line=$(grep -n -m 1 "function run-$function_name" "${BASH_SOURCE[1]}" | cut -d: -f1)
end_line=$(awk "NR > $start_line && /^}/ {print NR; exit}" "${BASH_SOURCE[1]}")
function_body=$(sed -n "${start_line},${end_line}p" "${BASH_SOURCE[1]}")
description=$(echo "$function_body" | sed -n '/^\s*:/,/^\s*[^:]/p' | sed 's/^\s*:\s*/ │ /')
echo -e "$BOLD\r$MENAME \`${function_name}\`$NC\n${description}\n └──────────\n"
done
}
function check-deploy-name() {
deploy=${1}
if [[ "$deploy" == "prod" || "$deploy" == "dev" ]]; then
echo "Deploy environment is set to $deploy."
else
echo "Invalid deploy environment. Must be 'dev' or 'prod', but got '${deploy}'."
exit 1
fi
}
function check-argo-alive() {
pod_statuses=$(kubectl -n argocd get pod -o json | jq -r '.items[].status.phase')
# Check if all pod statuses are "Running"
for pod_status in $pod_statuses; do
if [[ "$status" != "Running" ]]; then
return 0
fi
done
return 1
}
-45
View File
@@ -1,45 +0,0 @@
#!/usr/bin/env bash
mkdir -p .tmp
deployment=${1:-dev}
keep_old=${2:-no}
keep_old=$(echo "${keep_old:0:1}" | tr '[:upper:]' '[:lower:]')
app=argocd
location=k8s/$app
full_path=$(realpath $location)
tmp_path=".tmp/$location/$deployment-$app.yaml"
mkdir -p $(dirname $tmp_path)
pushd $full_path &> /dev/null
helm dependency update &> /dev/null
popd &> /dev/null
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 $tmp_path".old"*
echo " -> Renaming old file to "$tmp_path".old"
mv $tmp_path $tmp_path".old"
fi
fi
helm template $app $full_path --namespace $app \
--debug \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-${deployment}.yaml \
--set selfapp.deployment="${deployment}" \
--set selfapp.enabled="true" \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)" \
> $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
-40
View File
@@ -1,40 +0,0 @@
#!/usr/bin/env bash
set -e
pushd k8s/argocd
echo "Installing dependencies..."
helm dependency update
popd
DEPLOYMENT=${1:-dev}
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"
watch -n1 "kubectl -n argocd get all"
echo "Login to argo"
argocd login cd.argoproj.io --core
kubectl config set-context --current --namespace argocd
argocd admin initial-password
echo "Enabling selfapp"
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)"
echo "Final sync"
argocd app sync argocd/
-45
View File
@@ -1,45 +0,0 @@
#!/usr/bin/env bash
mkdir -p .tmp
deployment=${1:-dev}
keep_old=${2:-no}
keep_old=$(echo "${keep_old:0:1}" | tr '[:upper:]' '[:lower:]')
app=argocd
location=k8s/$app
full_path=$(realpath $location)
tmp_path=".tmp/$location/$deployment-$app.yaml"
mkdir -p $(dirname $tmp_path)
pushd $full_path &> /dev/null
helm dependency update &> /dev/null
popd &> /dev/null
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 $tmp_path".old"*
echo " -> Renaming old file to "$tmp_path".old"
mv $tmp_path $tmp_path".old"
fi
fi
helm template $app $full_path --namespace $app \
--debug \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-${deployment}.yaml \
--set selfapp.deployment="${deployment}" \
--set selfapp.enabled="true" \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)" \
> $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
@@ -0,0 +1,29 @@
{{ define "homelab.argo.applicaton" }}
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: "{{ .name }}"
spec:
project: {{ .project }}
source:
repoURL: "git@github.com:{{ .Values.gitops.repo }}.git"
targetRevision: "{{ .Values.gitops.commit }}"
path: 'k8s/apps/{{ .name }}'
helm:
valueFiles:
- values.yaml
- values-{{.Values.global.deployment}}.yaml
values: |-
global:
{{- .Values.global | toYaml | nindent 12 }}
releaseName: {{ .name }}
destination:
server: https://kubernetes.default.svc
namespace: {{ .namespace }}
{{- if .syncPolicy }}
syncPolicy:
{{- .syncPolicy | toYaml | nindent 4 }}
{{ end }}
{{ end }}
@@ -0,0 +1,25 @@
{{- $argoappsetInfra := "infrastructure" -}}
{{- include "homelab.argo.project" (dict "name" $argoappsetInfra "description" "Infrastructure related charts") -}}
{{- range $appName, $appProps := .Values.infrastructure -}}
{{- $_ := set $appProps "Values" $.Values -}}
{{- $_ := set $appProps "name" (default $appProps.name (printf "infra-%s" $appName)) -}}
{{- $_ := set $appProps "project" (default $appProps.project $argoappsetInfra) -}}
{{- $_ := set $appProps "namespace" (default $appProps.namespace $appName) -}}
{{- if (not $appProps.disabled) -}}
{{- if $appProps.createNamespace -}}
---
apiVersion: v1
kind: Namespace
metadata:
name: "{{ $appProps.namespace }}"
{{ end }}
{{- include "homelab.argo.applicaton" $appProps -}}
{{- end -}}
{{- end -}}
+10 -1
View File
@@ -8,4 +8,13 @@ global:
infrastructureCharts: {}
apps: {}
apps: {}
infrastructure:
metallb:
createNamespace: true
namespace: metallb-system
syncPolicy:
automated:
selfHeal: true
syncOptions:
- ServerSideApply=true
-15
View File
@@ -1,15 +0,0 @@
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: first-pool
namespace: metallb-system
spec:
addresses:
- 10.0.100.1-10.0.100.255
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: l2ad
namespace: metallb-system
+10
View File
@@ -0,0 +1,10 @@
apiVersion: v2
name: cluster
description: An infrastructure collection of manifests for homelab
type: application
version: 0.1.0
dependencies:
- name: metallb
version: 0.14.8
repository: https://metallb.github.io/metallb
@@ -0,0 +1,15 @@
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: homelab-pool
namespace: "{{ .Release.Namespace }}"
spec:
addresses:
{{- .Values.homelab.addresses | toYaml | nindent 4 }}
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: l2ad
namespace: "{{ .Release.Namespace }}"
Whitespace-only changes.
Whitespace-only changes.
+4
View File
@@ -0,0 +1,4 @@
homelab:
addresses:
- 10.0.100.1-10.0.100.255
+2
View File
@@ -5,6 +5,8 @@ pkgs.mkShell {
git
kubectl
kubernetes-helm
jsonnet
jsonnet-language-server
argocd
yq
jq
View File
Whitespace-only changes.