refactor start

This commit is contained in:
Ariel Sosnovsky committed 2023-04-13 20:41:56 +00:00
1 parent c812acf459
commit d1894535bb
102 files changed
+387 -43

No files matched your search

+5 -1
View File
@@ -1 +1,5 @@
{}
{
"yaml.schemas": {
"https://json.schemastore.org/helmfile.json": "file:///workspaces/homelab/k8s/argocd/templates/configurations.yaml"
}
}
+22 -9
View File
@@ -6,11 +6,8 @@ deployment=${2:-dev}
app=$(basename $full_path)
location=$(dirname $full_path)
tmp_path=".tmp/$location/$deployment-$app.yaml"
argocd_values_path=$(realpath k8s/argocd/values.yaml)
argocd_values_deployment_path=$(realpath k8s/argocd/values-$deployment.yaml)
echo "> writing $location/$app to $tmp_path"
echo "> using argo values of $argocd_values_path"
cat $argocd_values_path | yq
mkdir -p $(dirname $tmp_path)
pushd $full_path &> /dev/null
@@ -23,12 +20,28 @@ if [ -f "$tmp_path" ]; then
mv $tmp_path $tmp_path".old"
fi
extraArgs=""
for f in k8s/argocd/values/shared/*.yaml; do
full_file_path=$(realpath $f)
extraArgs=$extraArgs" --values ${full_file_path}"
done
for f in k8s/argocd/values/$deployment/*.yaml; do
full_file_path=$(realpath $f)
extraArgs=$extraArgs" --values ${full_file_path}"
done
echo $extraArgs
helm template $app $full_path --namespace $app \
--debug \
--values $argocd_values_path \
--values $argocd_values_deployment_path \
--values $full_path/values.yaml \
--values $full_path/values-$deployment.yaml \
$extraArgs \
> $tmp_path
echo $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
+29 -5
View File
@@ -1,12 +1,36 @@
#!/bin/bash
mkdir -p .tmp
helm template argocd k8s/argocd \
--namespace argocd \
deployment=${1:-dev}
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"
echo " -> Renaming old file to "$tmp_path".old"
mv $tmp_path $tmp_path".old"
fi
helm template $app $full_path --namespace $app \
--debug \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-dev.yaml \
--set selfapp.deployment="${deployment}" \
--set selfapp.enabled="true" \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)" \
> .tmp/argocd.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
-2
View File
@@ -13,7 +13,6 @@ helm install argocd k8s/argocd \
--namespace argocd \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-$DEPLOYMENT.yaml \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)"
watch -n1 "kubectl -n argocd get all"
@@ -26,7 +25,6 @@ helm upgrade argocd k8s/argocd \
--namespace argocd \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-$DEPLOYMENT.yaml \
--set selfapp.enabled="true" \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)"
-1
View File
@@ -8,7 +8,6 @@ typeofapp=$(basename $location)
mkdir -p $full_path/templates
touch $full_path/values.yaml
touch $full_path/values-{dev,prod}.yaml
cat <<EOT >> $full_path/Chart.yaml
apiVersion: v2
name: $app
+6
View File
@@ -0,0 +1,6 @@
apiVersion: v2
name: argoapps
description: An k8s service for homelab
type: application
version: 0.1.0
dependencies: []
@@ -1,18 +1,17 @@
{{- if .Values.selfapp.enabled -}}
{{ define "homelab.argo.project" }}
---
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: infrastructure
namespace: "{{ .Release.Namespace }}"
name: {{ .name }}
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
description: "infrastructure services"
description: {{ .description }}
orphanedResources:
warn: false
sourceRepos:
- "git@github.com:{{ .Values.selfapp.repo }}.git"
- "git@github.com:{{ .Values.gitops.repo }}.git"
destinations:
- server: "*"
namespace: '*'
@@ -20,4 +19,4 @@ spec:
clusterResourceWhitelist:
- group: "*"
kind: "*"
{{- end -}}
{{ end }}
+35
View File
@@ -0,0 +1,35 @@
{{- $infraChartProjectName := "infrastructure-charts" -}}
{{ include "homelab.argo.project" (dict "Values" $.Values "name" $infraChartProjectName "description" "infrastructure helm charts")}}
{{ range $chartName, $chartProps := .Values.infrastructureCharts }}
{{- $namespace := (printf "chart-%s" $chartName) -}}
---
apiVersion: v1
kind: Namespace
metadata:
name: "{{ $namespace }}"
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: chart-{{ $chartName }}
spec:
project: {{ $infraChartProjectName }}
source:
chart: {{ $chartProps.chart | default $chartName }}
repoURL: {{ $chartProps.repoURL }}
targetRevision: {{ $chartProps.targetRevision }}
helm:
values: |-
{{- tpl ($chartProps.values | default "") $ | nindent 8}}
releaseName: {{ $chartName }}
destination:
server: https://kubernetes.default.svc
namespace: {{ $namespace }}
syncPolicy:
automated:
selfHeal: true
{{ end }}
File renamed without changes.
+60 -4
View File
@@ -1,4 +1,38 @@
{{- if .Values.selfapp.enabled -}}
---
{{ $currentScope := .}}
{{- $appvalues := dict -}}
{{ range $path, $_ := .Files.Glob "values/shared/**.yaml" }}
{{- with $currentScope }}
{{ $newobj := .Files.Get $path | fromYaml }}
{{ $appvalues := merge $appvalues $newobj }}
{{- end -}}
{{ end }}
{{- $deploymentPath := printf "values/%s/**.yaml" .Values.selfapp.deployment -}}
{{ range $path, $_ := .Files.Glob $deploymentPath }}
{{- with $currentScope }}
{{ $newobj := .Files.Get $path | fromYaml }}
{{ $appvalues := merge $appvalues $newobj }}
{{- end -}}
{{ end }}
---
apiVersion: v1
kind: Secret
metadata:
name: argo-repo-main
namespace: "{{ .Release.Namespace }}"
labels:
argocd.argoproj.io/secret-type: repository
annotations:
link.argocd.argoproj.io/external-link: "https://github.com/{{ $appvalues.gitops.repo }}"
stringData:
type: git
url: "git@github.com:{{ $appvalues.gitops.repo }}.git"
sshPrivateKey: {{ .Values.selfapp.sshkey | quote }}
{{ if .Values.selfapp.enabled }}
---
apiVersion: argoproj.io/v1alpha1
kind: Application
@@ -8,13 +42,12 @@ metadata:
spec:
project: default
source:
repoURL: "git@github.com:{{ .Values.selfapp.repo }}.git"
targetRevision: "{{ .Values.selfapp.commit }}"
repoURL: "git@github.com:{{ $appvalues.gitops.repo }}.git"
targetRevision: "{{ $appvalues.gitops.commit }}"
path: k8s/argocd
helm:
valueFiles:
- values.yaml
- values-{{ .Values.global.deployment }}.yaml
parameters:
- name: "selfapp.enabled"
value: "true"
@@ -23,4 +56,27 @@ spec:
destination:
server: https://kubernetes.default.svc
namespace: "{{ .Release.Namespace }}"
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: "argoapps"
namespace: "{{ .Release.Namespace }}"
spec:
project: default
source:
repoURL: "git@github.com:{{ $appvalues.gitops.repo }}.git"
targetRevision: "{{ $appvalues.gitops.commit }}"
path: k8s/argoapps
helm:
valueFiles:
- values.yaml
values: |-
{{- $appvalues | toYaml | nindent 8 }}
destination:
server: https://kubernetes.default.svc
namespace: "{{ .Release.Namespace }}"
{{- end -}}
+1 -15
View File
@@ -14,20 +14,6 @@ argo-cd:
enabled: false
ingressGrpc:
enabled: false
debugger:
enabled: false
selfapp:
commit: "stable"
repo: "asosnovsky/homelab"
sshkey: ""
global:
email: "ariel@sosnovsky.ca"
tls:
enabled: false
issuer: ""
secretName: ""
domain: ""
deployment: ""
nfs:
server: "changme"
timezone: America/Toronto
sshkey: ""
+4
View File
@@ -0,0 +1,4 @@
global:
deployment: dev
ingress:
domain: "me.local"
+10
View File
@@ -0,0 +1,10 @@
global:
deployment: prod
ingress:
domain: "home.sosnovsky.ca"
tls:
enabled: true
issuer: "letsencrypt"
nfs:
server: "192.168.8.107"
share: "/mnt/EightTerra/k3s-cluster"
+16
View File
@@ -0,0 +1,16 @@
global:
deployment: ""
email: "ariel@sosnovsky.ca"
timezone: America/Toronto
ingress:
domain: ""
tls:
enabled: false
issuer: ""
nfs:
storageClass: "nfs-generic"
server: "changme"
share: "changeme"
gitops:
commit: "stable"
repo: "asosnovsky/homelab"
@@ -0,0 +1,24 @@
infrastructureCharts:
cert-manager:
repoURL: "https://charts.jetstack.io"
targetRevision: 1.10.2"
values: |-
installCRDs: true
external-secrets:
repoURL: "https://charts.external-secrets.io"
targetRevision: "0.7.2"
values: |-
installCRDs: true
nfs-generic-storageclass:
chart: nfs-subdir-external-provisioner
repoURL: "https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/"
targetRevision: "v4.0.2"
values: |-
storageClass:
name: "{{ .Values.global.nfs.storageClass }}"
nfs:
server: "{{ .Values.global.nfs.server }}"
path: "{{ .Values.global.nfs.share }}"
kubernetes-secret-generator:
repoURL: "https://helm.mittwald.de"
targetRevision: "v3.4.0"
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
set -e
full_path=${1}
deployment=${2:-dev}
app=$(basename $full_path)
location=$(dirname $full_path)
tmp_path=".tmp/$location/$deployment-$app.yaml"
argocd_values_path=$(realpath k8s/argocd/values.yaml)
argocd_values_deployment_path=$(realpath k8s/argocd/values-$deployment.yaml)
echo "> writing $location/$app to $tmp_path"
echo "> using argo values of $argocd_values_path"
cat $argocd_values_path | yq
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"
echo "renaming old file to "$tmp_path".old"
mv $tmp_path $tmp_path".old"
fi
helm template $app $full_path --namespace $app \
--debug \
--values $argocd_values_path \
--values $argocd_values_deployment_path \
--values $full_path/values.yaml \
--values $full_path/values-$deployment.yaml \
> $tmp_path
echo $tmp_path
+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
mkdir -p .tmp
helm template argocd k8s/argocd \
--namespace argocd \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-dev.yaml \
--set selfapp.enabled="true" \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)" \
> .tmp/argocd.yaml
+33
View File
@@ -0,0 +1,33 @@
#!/bin/bash
set -e
pushd k8s/argocd
helm dependency update
DEPLOYMENT=${1:-dev}
popd
helm install argocd k8s/argocd \
--namespace argocd \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-$DEPLOYMENT.yaml \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)"
watch -n1 "kubectl -n argocd get all"
argocd login cd.argoproj.io --core
kubectl config set-context --current --namespace argocd
argocd admin initial-password
helm upgrade argocd k8s/argocd \
--namespace argocd \
--create-namespace \
--values k8s/argocd/values.yaml \
--values k8s/argocd/values-$DEPLOYMENT.yaml \
--set selfapp.enabled="true" \
--set selfapp.sshkey="$(cat ~/.ssh/id_rsa)"
argocd app sync argocd/argocd
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+9
View File
@@ -0,0 +1,9 @@
apiVersion: v2
name: argocd
description: Homelab Infra
type: application
version: 0.1.0
dependencies:
- name: argo-cd
version: 5.22.1
repository: https://argoproj.github.io/argo-helm
+26
View File
@@ -0,0 +1,26 @@
{{- if .Values.selfapp.enabled -}}
---
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: "{{ .Release.Name }}"
namespace: "{{ .Release.Namespace }}"
spec:
project: default
source:
repoURL: "git@github.com:{{ .Values.selfapp.repo }}.git"
targetRevision: "{{ .Values.selfapp.commit }}"
path: k8s/argocd
helm:
valueFiles:
- values.yaml
- values-{{ .Values.global.deployment }}.yaml
parameters:
- name: "selfapp.enabled"
value: "true"
- name: "selfapp.sshkey"
value: {{ .Values.selfapp.sshkey | quote }}
destination:
server: https://kubernetes.default.svc
namespace: "{{ .Release.Namespace }}"
{{- end -}}
File renamed without changes.
File renamed without changes.
+33
View File
@@ -0,0 +1,33 @@
argo-cd:
configs:
cm:
exec.enabled: true
params:
server.insecure: true
server.basehref: /
server.rootpath: ""
crds:
install: true
keep: false
server:
ingress:
enabled: false
ingressGrpc:
enabled: false
debugger:
enabled: false
selfapp:
commit: "stable"
repo: "asosnovsky/homelab"
sshkey: ""
global:
email: "ariel@sosnovsky.ca"
tls:
enabled: false
issuer: ""
secretName: ""
domain: ""
deployment: ""
nfs:
server: "changme"
timezone: America/Toronto
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+23
View File
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
File renamed without changes.
File renamed without changes.
File renamed without changes.
Whitespace-only changes.
Loaded 100 of 102 files, more files were not shown because too many files have changed in this diff. Show more