feat: add ansible lint, update taskfiles, and makejinja to not strip trailing newlines (#1172)

Signed-off-by: Devin Buhl <devin@buhl.casa>
This commit is contained in:
Devin Buhl authored and GitHub committed 2024-01-16 14:23:08 -05:00
1 parent b41ccc8145
commit 528508e834
13 files changed
+160 -127

No files matched your search

-1
View File
@@ -1,4 +1,3 @@
# Test: k0s
--- ---
ci_test: true ci_test: true
+3 -6
View File
@@ -112,13 +112,10 @@ jobs:
shell: bash shell: bash
run: task configure --yes run: task configure --yes
- name: Run configure again to ensure idempotency - name: Run Ansible lint
if: ${{ steps.config-env.outputs.distribution == 'k3s' || steps.config-env.outputs.distribution == 'k0s' }}
shell: bash shell: bash
run: task configure --yes run: task ansible:lint
- name: Run kubeconform
shell: bash
run: ./.github/scripts/kubeconform.sh ./kubernetes
- name: List Hosts with Ansible - name: List Hosts with Ansible
if: ${{ steps.config-env.outputs.distribution == 'k3s' || steps.config-env.outputs.distribution == 'k0s' }} if: ${{ steps.config-env.outputs.distribution == 'k3s' || steps.config-env.outputs.distribution == 'k0s' }}
+37 -34
View File
@@ -4,7 +4,10 @@ version: "3"
vars: vars:
PYTHON_BIN: python3 PYTHON_BIN: python3
ANSIBLE_LINT_FILE: "{{.ANSIBLE_DIR}}/.ansible-lint"
ANSIBLE_INVENTORY_FILE: "{{.ANSIBLE_DIR}}/inventory/hosts.yaml" ANSIBLE_INVENTORY_FILE: "{{.ANSIBLE_DIR}}/inventory/hosts.yaml"
ANSIBLE_REQUIREMENTS_FILE: "{{.ROOT_DIR}}/requirements.yaml"
PIP_REQUIREMENTS_FILE: "{{.ROOT_DIR}}/requirements.txt"
env: env:
PATH: "{{.ROOT_DIR}}/.venv/bin:$PATH" PATH: "{{.ROOT_DIR}}/.venv/bin:$PATH"
@@ -31,66 +34,66 @@ tasks:
playbook: Playbook to run (required) playbook: Playbook to run (required)
prompt: Run Ansible playbook '{{.playbook}}'... continue? prompt: Run Ansible playbook '{{.playbook}}'... continue?
deps: ["deps"] deps: ["deps"]
cmd: | cmd: .venv/bin/ansible-playbook --inventory {{.ANSIBLE_INVENTORY_FILE}} {{.ANSIBLE_DIR}}/playbooks/{{.playbook}}.yaml {{.CLI_ARGS}}
.venv/bin/ansible-playbook --inventory {{.ANSIBLE_INVENTORY_FILE}} \
{{.ANSIBLE_DIR}}/playbooks/{{.playbook}}.yaml {{.CLI_ARGS}}
preconditions: preconditions:
- { msg: "Argument (playbook) is required", sh: "test -n {{.playbook}}" } - sh: test -n {{.playbook}}
- { msg: "Venv not found", sh: "test -d {{.ROOT_DIR}}/.venv" } - sh: test -d {{.ROOT_DIR}}/.venv
- { msg: "Inventory not found", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" } - sh: test -f {{.ANSIBLE_INVENTORY_FILE}}
- { msg: "Playbook not found", sh: "test -f {{.ANSIBLE_DIR}}/playbooks/{{.playbook}}.yaml" } - sh: test -f {{.ANSIBLE_DIR}}/playbooks/{{.playbook}}.yaml
poweroff: poweroff:
desc: Shutdown all the k8s nodes desc: Shutdown all the k8s nodes
deps: ["deps"] deps: ["deps"]
cmd: | cmd: .venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} -a '/usr/bin/systemctl poweroff' --become
.venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} \
-a '/usr/bin/systemctl poweroff' --become
preconditions: preconditions:
- { msg: "Venv not found", sh: "test -d {{.ROOT_DIR}}/.venv" } - sh: test -d {{.ROOT_DIR}}/.venv
- { msg: "Inventory not found", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" } - sh: test -f {{.ANSIBLE_INVENTORY_FILE}}
list: list:
desc: List all the hosts desc: List all the hosts
deps: ["deps"] deps: ["deps"]
cmd: | cmd: .venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} --list-hosts
.venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} \
--list-hosts
preconditions: preconditions:
- { msg: "Venv not found", sh: "test -d {{.ROOT_DIR}}/.venv" } - sh: test -d {{.ROOT_DIR}}/.venv
- { msg: "Inventory not found", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" } - sh: test -f {{.ANSIBLE_INVENTORY_FILE}}
ping: ping:
desc: Ping all the hosts desc: Ping all the hosts
deps: ["deps"] deps: ["deps"]
cmd: | cmd: .venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} --one-line -m 'ping'
.venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} \
--one-line -m 'ping'
preconditions: preconditions:
- { msg: "Venv not found", sh: "test -d {{.ROOT_DIR}}/.venv" } - sh: test -d {{.ROOT_DIR}}/.venv
- { msg: "Inventory not found", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" } - sh: test -f {{.ANSIBLE_INVENTORY_FILE}}
uptime: uptime:
desc: Uptime of all the hosts desc: Uptime of all the hosts
deps: ["deps"] deps: ["deps"]
cmd: | cmd: .venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} --one-line -a 'uptime'
.venv/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} \
--one-line -a 'uptime'
preconditions: preconditions:
- { msg: "Venv not found", sh: "test -d {{.ROOT_DIR}}/.venv" } - sh: test -d {{.ROOT_DIR}}/.venv
- { msg: "Inventory not found", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" } - sh: test -f {{.ANSIBLE_INVENTORY_FILE}}
lint:
desc: Lint Ansible
deps: ["deps"]
cmd: ./.venv/bin/ansible-lint --config-file {{.ANSIBLE_LINT_FILE}} {{.ANSIBLE_DIR}}/**/*.yaml
preconditions:
- sh: test -d {{.ANSIBLE_DIR}}
- sh: test -f {{.ANSIBLE_LINT_FILE}}
.venv: .venv:
internal: true internal: true
cmds: cmds:
- true && {{.PYTHON_BIN}} -m venv {{.ROOT_DIR}}/.venv - "{{.PYTHON_BIN}} -m venv {{.ROOT_DIR}}/.venv"
- .venv/bin/python3 -m pip install --upgrade pip setuptools wheel - .venv/bin/python3 -m pip install --upgrade pip setuptools wheel
- .venv/bin/python3 -m pip install --upgrade --requirement "{{.ROOT_DIR}}/requirements.txt" - .venv/bin/python3 -m pip install --upgrade --requirement "{{.PIP_REQUIREMENTS_FILE}}"
- .venv/bin/ansible-galaxy install --role-file "{{.ROOT_DIR}}/requirements.yaml" {{if eq .force "true"}}--force{{end}} - .venv/bin/ansible-galaxy install --role-file "{{.ANSIBLE_REQUIREMENTS_FILE}}" {{if eq .force "true"}}--force{{end}}
vars:
force: '{{.force | default "true"}}'
sources: sources:
- "{{.ROOT_DIR}}/requirements.txt" - "{{.PIP_REQUIREMENTS_FILE}}"
- "{{.ROOT_DIR}}/requirements.yaml" - "{{.ANSIBLE_REQUIREMENTS_FILE}}"
generates: generates:
- "{{.ROOT_DIR}}/.venv/pyvenv.cfg" - "{{.ROOT_DIR}}/.venv/pyvenv.cfg"
preconditions:
- sh: command -v {{.PYTHON_BIN}}
vars:
force: '{{.force | default "true"}}'
+34 -21
View File
@@ -12,22 +12,26 @@ tasks:
desc: Bootstrap Flux into a Kubernetes cluster desc: Bootstrap Flux into a Kubernetes cluster
cmds: cmds:
# Install essential Prometheus Operator CRDs # Install essential Prometheus Operator CRDs
- kubectl apply --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml
- kubectl apply --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml
- kubectl apply --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_scrapeconfigs.yaml
- kubectl apply --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/{{.PROMETHEUS_OPERATOR_VERSION}}/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
# Install Flux # Install Flux
- kubectl apply --server-side --kustomize {{.KUBERNETES_DIR}}/bootstrap - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --kustomize {{.KUBERNETES_DIR}}/bootstrap
# Install Secrets and Kustomizations # Install Secrets and Kustomizations
- cat {{.ROOT_DIR}}/age.key | kubectl -n flux-system create secret generic sops-age --from-file=age.agekey=/dev/stdin - cat {{.SOPS_AGE_FILE}} | kubectl -n flux-system create secret generic sops-age --from-file=age.agekey=/dev/stdin
- sops --decrypt {{.KUBERNETES_DIR}}/flux/vars/cluster-secrets.sops.yaml | kubectl apply --server-side --filename - - sops --decrypt {{.KUBERNETES_DIR}}/flux/vars/cluster-secrets.sops.yaml | kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename -
- sops --decrypt {{.KUBERNETES_DIR}}/flux/vars/cluster-secrets-user.sops.yaml | kubectl apply --server-side --filename - - sops --decrypt {{.KUBERNETES_DIR}}/flux/vars/cluster-secrets-user.sops.yaml | kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename -
- kubectl apply --server-side --filename {{.KUBERNETES_DIR}}/flux/vars/cluster-settings.yaml - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename {{.KUBERNETES_DIR}}/flux/vars/cluster-settings.yaml
- kubectl apply --server-side --filename {{.KUBERNETES_DIR}}/flux/vars/cluster-settings-user.yaml - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename {{.KUBERNETES_DIR}}/flux/vars/cluster-settings-user.yaml
- kubectl apply --server-side --kustomize {{.KUBERNETES_DIR}}/flux/config - kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --kustomize {{.KUBERNETES_DIR}}/flux/config
preconditions: preconditions:
- { msg: "Flux already appears installed", sh: "kubectl get namespace flux-system &>/dev/null && exit 1 || exit 0" } - sh: command -v flux
- { msg: "Age private key not found", sh: "test -f {{.ROOT_DIR}}/age.key" } - sh: command -v kubectl
- sh: command -v sops
- sh: test -f {{.SOPS_AGE_FILE}}
- sh: test -f {{.KUBECONFIG_FILE}}
- sh: kubectl get namespace flux-system &>/dev/null && exit 1 || exit 0
apply: apply:
desc: Apply a Flux Kustomization resource for a cluster desc: Apply a Flux Kustomization resource for a cluster
@@ -36,27 +40,36 @@ tasks:
path: Path containing the Flux Kustomization resource (ks.yaml) (required) path: Path containing the Flux Kustomization resource (ks.yaml) (required)
ns: Namespace the Flux Kustomization exists in (default: flux-system) ns: Namespace the Flux Kustomization exists in (default: flux-system)
cmd: | cmd: |
flux build ks $(basename {{.path}}) \ flux --kubeconfig {{.KUBECONFIG_FILE}} build ks $(basename {{.path}}) \
--namespace {{.ns}} \ --namespace {{.ns}} \
--kustomization-file {{.KUBERNETES_DIR}}/apps/{{.path}}/ks.yaml \ --kustomization-file {{.KUBERNETES_DIR}}/apps/{{.path}}/ks.yaml \
--path {{.KUBERNETES_DIR}}/apps/{{.path}} \ --path {{.KUBERNETES_DIR}}/apps/{{.path}} \
{{- if contains "not found" .ks }}--dry-run \{{ end }} {{- if contains "not found" .ks }}--dry-run \{{ end }}
| \ | \
kubectl apply --server-side \ kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side \
--field-manager=kustomize-controller -f - --field-manager=kustomize-controller -f -
preconditions:
- sh: command -v flux
- sh: command -v kubectl
- sh: test -f {{.KUBECONFIG_FILE}}
- sh: test -f {{.KUBERNETES_DIR}}/apps/{{.path}}/ks.yaml
vars: vars:
path: '{{ or .path (fail "Argument (path) is required") }}' path: '{{ or .path (fail "Argument (path) is required") }}'
ns: '{{.ns | default "flux-system"}}' ns: '{{.ns | default "flux-system"}}'
ks: ks:
sh: flux --namespace {{.ns}} get kustomizations $(basename {{.path}}) 2>&1 sh: flux --kubeconfig {{.KUBECONFIG_FILE}} --namespace {{.ns}} get kustomizations $(basename {{.path}}) 2>&1
preconditions:
- { msg: "Kustomization file not found", sh: "test -f {{.KUBERNETES_DIR}}/apps/{{.path}}/ks.yaml" }
reconcile: reconcile:
desc: Force update Flux to pull in changes from your Git repository desc: Force update Flux to pull in changes from your Git repository
cmd: flux reconcile --namespace flux-system kustomization cluster --with-source cmd: flux --kubeconfig {{.KUBECONFIG_FILE}} reconcile --namespace flux-system kustomization cluster --with-source
preconditions:
- sh: command -v flux
- sh: test -f {{.KUBECONFIG_FILE}}
github-deploy-key: github-deploy-key:
cmd: sops --decrypt {{.KUBERNETES_DIR}}/bootstrap/github-deploy-key.sops.yaml | kubectl apply --server-side --filename - cmd: sops --decrypt {{.KUBERNETES_DIR}}/bootstrap/github-deploy-key.sops.yaml | kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename -
preconditions: preconditions:
- { msg: "Flux is not installed", sh: "kubectl get namespace flux-system &>/dev/null && exit 0 || exit 1" } - sh: command -v kubectl
- sh: command -v sops
- sh: test -f {{.KUBECONFIG_FILE}}
- sh: kubectl get namespace flux-system &>/dev/null && exit 0 || exit 1
+20 -13
View File
@@ -7,27 +7,34 @@ env:
tasks: tasks:
kubeconfig:
desc: Gets k0s cluster kubeconfig
cmds:
- k0sctl kubeconfig --config {{.ROOT_DIR}}/k0s-config.yaml > kubeconfig
preconditions:
- { msg: "k0s-config.yaml not found", sh: "test -f {{.ROOT_DIR}}/k0s-config.yaml" }
apply: apply:
desc: Apply k0s cluster k0s-config.yaml desc: Apply k0s cluster config
cmds: cmds:
- k0sctl apply --config {{.ROOT_DIR}}/k0s-config.yaml - k0sctl apply --config {{.K0S_CONFIG_FILE}}
- task: kubeconfig - task: kubeconfig
preconditions: preconditions:
- { msg: "k0s-config.yaml not found", sh: "test -f {{.ROOT_DIR}}/k0s-config.yaml" } - sh: command -v k0sctl
- sh: test -f {{.K0S_CONFIG_FILE}}
reset: reset:
desc: Resets the k0s cluster desc: Resets k0s cluster
deps: [":ansible:deps"]
cmds: cmds:
- k0sctl reset --config {{.ROOT_DIR}}/k0s-config.yaml - k0sctl reset --config {{.K0S_CONFIG_FILE}}
- task: :ansible:run - task: :ansible:run
vars: vars:
playbook: cluster-nuke playbook: cluster-nuke
preconditions: preconditions:
- { msg: "k0s-config.yaml not found", sh: "test -f {{.ROOT_DIR}}/k0s-config.yaml" } - sh: command -v k0sctl
- sh: test -f {{.K0S_CONFIG_FILE}}
kubeconfig:
desc: Gets k0s cluster kubeconfig
cmd: k0sctl kubeconfig --config {{.K0S_CONFIG_FILE}} > {{.KUBECONFIG_FILE}}
sources:
- "{{.K0S_CONFIG_FILE}}"
generates:
- "{{.KUBECONFIG_FILE}}"
preconditions:
- sh: command -v k0sctl
- sh: test -f {{.K0S_CONFIG_FILE}}
+12 -1
View File
@@ -2,6 +2,9 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json # yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3" version: "3"
vars:
KUBECONFORM_SCRIPT: "{{.TASKFILE_DIR}}/.taskfiles/Kubernetes/kubeconform.sh"
tasks: tasks:
mount: mount:
@@ -47,7 +50,7 @@ tasks:
ns: '{{.ns | default "default"}}' ns: '{{.ns | default "default"}}'
claim: '{{ or .claim (fail "Argument (claim) is required") }}' claim: '{{ or .claim (fail "Argument (claim) is required") }}'
preconditions: preconditions:
- { msg: "PVC not found", sh: "kubectl -n {{.ns}} get persistentvolumeclaim {{.claim}}" } - sh: kubectl -n {{.ns}} get persistentvolumeclaim {{.claim}}
resources: resources:
desc: Gather common resources in your cluster, useful when asking for support desc: Gather common resources in your cluster, useful when asking for support
@@ -65,3 +68,11 @@ tasks:
certificaterequests certificaterequests
ingresses ingresses
pods pods
kubeconform:
desc: Validate Kubernetes manifests with kubeconform
cmd: bash {{.KUBECONFORM_SCRIPT}} {{.KUBERNETES_DIR}}
preconditions:
- sh: command -v kubeconform
- sh: command -v kustomize
- sh: test -f {{.KUBECONFORM_SCRIPT}}
File renamed without changes.
+7 -7
View File
@@ -11,23 +11,23 @@ tasks:
- rm -rf {{.ROOT_DIR}}/.github/tests - rm -rf {{.ROOT_DIR}}/.github/tests
- rm -rf {{.ROOT_DIR}}/.github/workflows/e2e.yaml - rm -rf {{.ROOT_DIR}}/.github/workflows/e2e.yaml
# Move bootstrap directory to gitignored directory # Move bootstrap directory to gitignored directory
- mkdir -p {{.ROOT_DIR}}/.private - mv {{.BOOTSTRAP_DIR}} {{.PRIVATE_DIR}}/bootstrap-{{now | date "150405"}}
- mv {{.BOOTSTRAP_DIR}} {{.ROOT_DIR}}/.private/bootstrap-{{now | date "150405"}} - mv {{.MAKEJINJA_CONFIG_FILE}} {{.PRIVATE_DIR}}/makejinja-{{now | date "150405"}}.toml
- mv {{.ROOT_DIR}}/makejinja.toml {{.ROOT_DIR}}/.private/makejinja-{{now | date "150405"}}.toml
# Update renovate.json5 # Update renovate.json5
- sed -i {{if eq OS "darwin"}}''{{end}} 's/(..\.j2)\?(..\.j2)\?//g' {{.ROOT_DIR}}/.github/renovate.json5 - sed -i {{if eq OS "darwin"}}''{{end}} 's/(..\.j2)\?(..\.j2)\?//g' {{.ROOT_DIR}}/.github/renovate.json5
preconditions: preconditions:
- { msg: "bootstrap dir not found", sh: "test -d {{.BOOTSTRAP_DIR}}" } - sh: test -d {{.BOOTSTRAP_DIR}}
- { msg: "renovate.json5 not found", sh: "test -f {{.ROOT_DIR}}/.github/renovate.json5" } - sh: test -d {{.PRIVATE_DIR}}
- sh: test -f {{.ROOT_DIR}}/.github/renovate.json5
reset: reset:
desc: Reset templated configuration files desc: Reset templated configuration files
prompt: Reset templated configuration files... continue? prompt: Reset templated configuration files... continue?
cmds: cmds:
- rm -rf {{.ROOT_DIR}}/.sops.yaml - rm -rf {{.SOPS_CONFIG_FILE}}
- rm -rf {{.ROOT_DIR}}/k0s-config.yaml
- rm -rf {{.ANSIBLE_DIR}} - rm -rf {{.ANSIBLE_DIR}}
- rm -rf {{.KUBERNETES_DIR}} - rm -rf {{.KUBERNETES_DIR}}
- rm -rf {{.K0S_CONFIG_FILE}}
force-reset: force-reset:
desc: Reset repo back to HEAD desc: Reset repo back to HEAD
+5 -5
View File
@@ -6,9 +6,9 @@ tasks:
age-keygen: age-keygen:
desc: Initialize Age Key for Sops desc: Initialize Age Key for Sops
cmd: age-keygen --output {{.ROOT_DIR}}/age.key cmd: age-keygen --output {{.SOPS_AGE_FILE}}
status: status:
- test -f "{{.ROOT_DIR}}/age.key" - test -f "{{.SOPS_AGE_FILE}}"
encrypt: encrypt:
desc: Encrypt a secret desc: Encrypt a secret
@@ -19,8 +19,8 @@ tasks:
vars: vars:
claim: '{{ or .file (fail "Argument (file) is required") }}' claim: '{{ or .file (fail "Argument (file) is required") }}'
preconditions: preconditions:
- { msg: "Sops config not found", sh: "test -f {{.ROOT_DIR}}/.sops.yaml" } - sh: test -f {{.SOPS_CONFIG_FILE}}
- { msg: "Age key not found", sh: "test -f {{.ROOT_DIR}}/age.key" } - sh: test -f {{.SOPS_AGE_FILE}}
encrypt:all: encrypt:all:
desc: Encrypt all Kubernetes SOPS secrets desc: Encrypt all Kubernetes SOPS secrets
@@ -28,7 +28,7 @@ tasks:
- for: { var: file } - for: { var: file }
task: encrypt task: encrypt
vars: vars:
file: '{{.ITEM}}' file: "{{.ITEM}}"
vars: vars:
file: file:
sh: find {{.KUBERNETES_DIR}} -type f -name "*.sops.*" sh: find {{.KUBERNETES_DIR}} -type f -name "*.sops.*"
+10 -15
View File
@@ -2,34 +2,29 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json # yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3" version: "3"
vars:
ARCHFILE: "{{.ROOT_DIR}}/.taskfiles/Workstation/Archfile"
BREWFILE: "{{.ROOT_DIR}}/.taskfiles/Workstation/Brewfile"
tasks: tasks:
brew: brew:
desc: Install workstation dependencies with Brew desc: Install workstation dependencies with Brew
cmd: brew bundle --file {{.ROOT_DIR}}/.taskfiles/Workstation/Brewfile cmd: brew bundle --file {{.BREWFILE}}
preconditions: preconditions:
- sh: command -v brew - sh: command -v brew
msg: | - sh: test -f {{.BREWFILE}}
Homebrew is not installed. Using MacOS, Linux or WSL?
Head over to https://brew.sh to get up and running.
- { msg: "Brewfile not found", sh: "test -f {{.ROOT_DIR}}/.taskfiles/Workstation/Brewfile" }
paru: paru:
desc: Install workstation dependencies with Paru desc: Install workstation dependencies with Paru
cmd: paru -Syu --needed --noconfirm --noprogressbar $(cat {{.ROOT_DIR}}/.taskfiles/Workstation/Archfile | xargs) cmd: paru -Syu --needed --noconfirm --noprogressbar $(cat {{.ARCHFILE}} | xargs)
preconditions: preconditions:
- sh: command -v paru - sh: command -v paru
msg: | - sh: test -f {{.ARCHFILE}}
Paru is not installed. Using ArchLinux?
Head over to https://github.com/Morganamilo/paru to get up and running.
- { msg: "Archfile not found", sh: "test -f {{.ROOT_DIR}}/.taskfiles/Workstation/Archfile" }
yay: yay:
desc: Install workstation dependencies with Yay desc: Install workstation dependencies with Yay
cmd: yay -Syu --needed --noconfirm --noprogressbar $(cat {{.ROOT_DIR}}/.taskfiles/Workstation/Archfile | xargs) cmd: yay -Syu --needed --noconfirm --noprogressbar $(cat {{.ARCHFILE}} | xargs)
preconditions: preconditions:
- sh: command -v yay - sh: command -v yay
msg: | - sh: test -f {{.ARCHFILE}}
Yay is not installed. Using ArchLinux?
Head over to https://github.com/Jguer/yay to get up and running.
- { msg: "Archfile not found", sh: "test -f {{.ROOT_DIR}}/.taskfiles/Workstation/Archfile" }
+30 -23
View File
@@ -3,12 +3,19 @@
version: "3" version: "3"
vars: vars:
BOOTSTRAP_DIR: "{{.ROOT_DIR}}/bootstrap" # Directories
ANSIBLE_DIR: "{{.ROOT_DIR}}/ansible" ANSIBLE_DIR: "{{.ROOT_DIR}}/ansible"
BOOTSTRAP_DIR: "{{.ROOT_DIR}}/bootstrap"
KUBERNETES_DIR: "{{.ROOT_DIR}}/kubernetes" KUBERNETES_DIR: "{{.ROOT_DIR}}/kubernetes"
PRIVATE_DIR: "{{.ROOT_DIR}}/.private"
env: # Files
KUBECONFIG: "{{.ROOT_DIR}}/kubeconfig" BOOTSTRAP_ADDONS_FILE: "{{.BOOTSTRAP_DIR}}/vars/addons.yaml"
BOOTSTRAP_CONFIG_FILE: "{{.BOOTSTRAP_DIR}}/vars/config.yaml"
K0S_CONFIG_FILE: "{{.ROOT_DIR}}/k0s-config.yaml"
KUBECONFIG_FILE: "{{.ROOT_DIR}}/kubeconfig"
MAKEJINJA_CONFIG_FILE: "{{.ROOT_DIR}}/makejinja.toml"
SOPS_AGE_FILE: "{{.ROOT_DIR}}/age.key"
SOPS_CONFIG_FILE: "{{.ROOT_DIR}}/.sops.yaml"
includes: includes:
ansible: .taskfiles/Ansible/Taskfile.yaml ansible: .taskfiles/Ansible/Taskfile.yaml
@@ -26,21 +33,22 @@ tasks:
default: task -l default: task -l
init: init:
desc: Initialize configuration files desc: Initialize template files and directories
cmds: cmds:
- cp -n {{.BOOTSTRAP_DIR}}/vars/addons.sample.yaml {{.BOOTSTRAP_DIR}}/vars/addons.yaml - mkdir -p {{.PRIVATE_DIR}}
- cp -n {{.BOOTSTRAP_DIR}}/vars/config.sample.yaml {{.BOOTSTRAP_DIR}}/vars/config.yaml - cp -n {{.BOOTSTRAP_ADDONS_FILE | replace ".yaml" ".sample.yaml"}} {{.BOOTSTRAP_ADDONS_FILE}}
- cmd: echo "=== Configuration files copied ===" - cp -n {{.BOOTSTRAP_CONFIG_FILE | replace ".yaml" ".sample.yaml"}} {{.BOOTSTRAP_CONFIG_FILE}}
- cmd: echo === Configuration files copied ===
silent: true silent: true
- cmd: echo "Proceed with updating the configuration files..." - cmd: echo Proceed with updating the configuration files...
silent: true silent: true
- cmd: echo "{{.BOOTSTRAP_DIR}}/vars/config.yaml" - cmd: echo {{.BOOTSTRAP_CONFIG_FILE}}
silent: true silent: true
- cmd: echo "{{.BOOTSTRAP_DIR}}/vars/addons.yaml" - cmd: echo {{.BOOTSTRAP_ADDONS_FILE}}
silent: true silent: true
status: status:
- test -f "{{.BOOTSTRAP_DIR}}/vars/addons.yaml" - test -f {{.BOOTSTRAP_ADDONS_FILE}}
- test -f "{{.BOOTSTRAP_DIR}}/vars/config.yaml" - test -f {{.BOOTSTRAP_CONFIG_FILE}}
configure: configure:
desc: Configure repository from Ansible vars desc: Configure repository from Ansible vars
@@ -56,22 +64,21 @@ tasks:
env: env:
ANSIBLE_DISPLAY_SKIPPED_HOSTS: "false" ANSIBLE_DISPLAY_SKIPPED_HOSTS: "false"
preconditions: preconditions:
- { msg: "addons file not found", sh: "test -f {{.BOOTSTRAP_DIR}}/vars/addons.yaml" } - sh: test -f {{.BOOTSTRAP_ADDONS_FILE}}
- { msg: "config file not found", sh: "test -f {{.BOOTSTRAP_DIR}}/vars/config.yaml" } - sh: test -f {{.BOOTSTRAP_CONFIG_FILE}}
.template: .template:
internal: true internal: true
cmds: cmds:
- ./.venv/bin/makejinja --force - ./.venv/bin/makejinja --keep-trailing-newline --force
- task: sops:encrypt:all - task: sops:encrypt:all
preconditions: preconditions:
- { msg: "bootstrap addons file not found", sh: "test -f {{.BOOTSTRAP_DIR}}/vars/addons.yaml" } - sh: test -f {{.BOOTSTRAP_ADDONS_FILE}}
- { msg: "bootstrap config file not found", sh: "test -f {{.BOOTSTRAP_DIR}}/vars/config.yaml" } - sh: test -f {{.BOOTSTRAP_CONFIG_FILE}}
- { msg: "makejinja loader file not found", sh: "test -f {{.BOOTSTRAP_DIR}}/scripts/loader.py" } - sh: test -f {{.BOOTSTRAP_DIR}}/scripts/loader.py
- { msg: "makejinja config file not found", sh: "test -f {{.ROOT_DIR}}/makejinja.toml" } - sh: test -f {{.MAKEJINJA_CONFIG_FILE}}
.post-validate: .post-validate:
internal: true internal: true
cmd: ./.github/scripts/kubeconform.sh {{.KUBERNETES_DIR}} cmds:
preconditions: - task: kubernetes:kubeconform
- { msg: "kubeconform file not found", sh: "test -f ./.github/scripts/kubeconform.sh" }
@@ -1,4 +1,5 @@
skip_list: skip_list:
- yaml[commas]
- yaml[line-length] - yaml[line-length]
- var-naming - var-naming
warn_list: warn_list:
@@ -46,7 +46,7 @@
wait_sleep: 10 wait_sleep: 10
wait_timeout: 360 wait_timeout: 360
loop: loop:
- { name: cilium, kind: HelmChart, namespace: kube-system } - { name: cilium, kind: HelmChart, namespace: kube-system } # noqa: yaml[commas]
- { name: coredns, kind: HelmChart, namespace: kube-system } - { name: coredns, kind: HelmChart, namespace: kube-system }
- name: Coredns - name: Coredns