Skip to content

Commit

Permalink
Merge pull request #450 from angryninja48/update-cluster
Browse files Browse the repository at this point in the history
Update cluster
  • Loading branch information
angryninja48 authored May 14, 2024
2 parents 74725c7 + 2a08c61 commit fe25584
Show file tree
Hide file tree
Showing 185 changed files with 3,148 additions and 2,381 deletions.
12 changes: 10 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#shellcheck disable=SC2148,SC2155
export KUBECONFIG="$(expand_path ./kubeconfig)"
export SOPS_AGE_KEY_FILE="$(expand_path ./age.key)"
# ansible
# Venv
PATH_add "$(expand_path ./.venv/bin)"
export VIRTUAL_ENV="$(expand_path ./.venv)"
export PYTHONDONTWRITEBYTECODE="1"
# Ann Seabelle
export ANSIBLE_COLLECTIONS_PATH=$(expand_path ./.venv/galaxy)
export ANSIBLE_ROLES_PATH=$(expand_path ./.venv/galaxy/ansible_roles)
export ANSIBLE_VARS_ENABLED="host_group_vars,community.sops.sops"
export ANSIBLE_VARS_ENABLED="host_group_vars"
export ANSIBLE_LOCALHOST_WARNING="False"
export ANSIBLE_INVENTORY_UNPARSED_WARNING="False"
export K8S_AUTH_KUBECONFIG="$(expand_path ./kubeconfig)"
# Talos
export TALOSCONFIG="$(expand_path ./kubernetes/bootstrap/talos/clusterconfig/talosconfig)"
# Bin
PATH_add "$(expand_path ./.bin)"
88 changes: 88 additions & 0 deletions .taskfiles/Ansible/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"

vars:
ANSIBLE_LINT_FILE: "{{.ANSIBLE_DIR}}/.ansible-lint"
ANSIBLE_INVENTORY_FILE: "{{.ANSIBLE_DIR}}/inventory/hosts.yaml"
ANSIBLE_REQUIREMENTS_FILE: "{{.ANSIBLE_DIR}}/requirements.yaml"
ANSIBLE_PIP_REQUIREMENTS_FILE: "{{.ANSIBLE_DIR}}/requirements.txt"

env:
ANSIBLE_COLLECTIONS_PATH: "{{.VIRTUAL_ENV}}/galaxy"
ANSIBLE_ROLES_PATH: "{{.VIRTUAL_ENV}}/galaxy/ansible_roles"
ANSIBLE_VARS_ENABLED: "host_group_vars"
ANSIBLE_LOCALHOST_WARNING: "False"
ANSIBLE_INVENTORY_UNPARSED_WARNING: "False"

tasks:

deps:
desc: Set up Ansible dependencies
deps: [":workstation:venv"]
cmds:
- '{{.VIRTUAL_ENV}}/bin/python3 -m pip install --upgrade --requirement "{{.ANSIBLE_PIP_REQUIREMENTS_FILE}}"'
- '{{.VIRTUAL_ENV}}/bin/ansible-galaxy install --role-file "{{.ANSIBLE_REQUIREMENTS_FILE}}" {{if eq .force "true"}}--force{{end}}'
preconditions:
- { msg: "Missing Ansible requirements file", sh: "test -f {{.ANSIBLE_REQUIREMENTS_FILE}}" }
- { msg: "Missing Pip requirements file", sh: "test -f {{.ANSIBLE_PIP_REQUIREMENTS_FILE}}" }
sources:
- "{{.ANSIBLE_REQUIREMENTS_FILE}}"
- "{{.ANSIBLE_PIP_REQUIREMENTS_FILE}}"
generates:
- "{{.VIRTUAL_ENV}}/bin/ansible"
- "{{.VIRTUAL_ENV}}/bin/ansible-galaxy"
vars:
force: '{{.force | default "true"}}'

run:
desc: Run an Ansible playbook for configuring a cluster
summary: |
Args:
playbook: Playbook to run (required)
prompt: Run Ansible playbook '{{.playbook}}'... continue?
deps: ["deps"]
cmd: "{{.VIRTUAL_ENV}}/bin/ansible-playbook --inventory {{.ANSIBLE_INVENTORY_FILE}} {{.ANSIBLE_DIR}}/playbooks/{{.playbook}}.yaml {{.CLI_ARGS}}"
requires:
vars: ["playbook"]
preconditions:
- { msg: "Missing Ansible inventory file", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" }

poweroff:
desc: Shutdown all the k8s nodes
deps: ["deps"]
cmd: "{{.VIRTUAL_ENV}}/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} -a '/usr/bin/systemctl poweroff' --become"
preconditions:
- { msg: "Missing Ansible inventory file", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" }

list:
desc: List all the hosts
deps: ["deps"]
cmd: "{{.VIRTUAL_ENV}}/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} --list-hosts"
preconditions:
- { msg: "Missing Ansible inventory file", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" }

ping:
desc: Ping all the hosts
deps: ["deps"]
cmd: "{{.VIRTUAL_ENV}}/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} --one-line -m 'ping'"
preconditions:
- { msg: "Missing Ansible inventory file", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" }

uptime:
desc: Uptime of all the hosts
deps: ["deps"]
cmd: "{{.VIRTUAL_ENV}}/bin/ansible kubernetes --inventory {{.ANSIBLE_INVENTORY_FILE}} --one-line -a 'uptime'"
preconditions:
- { msg: "Missing Ansible inventory file", sh: "test -f {{.ANSIBLE_INVENTORY_FILE}}" }

lint:
desc: Lint Ansible
deps: ["deps"]
cmd: "{{.VIRTUAL_ENV}}/bin/ansible-lint --config-file {{.ANSIBLE_LINT_FILE}} {{.ANSIBLE_DIR}}/**/*.yaml"
preconditions:
- { msg: "Missing Ansible lint file", sh: "test -f {{.ANSIBLE_LINT_FILE}}" }

.reset:
internal: true
cmd: rm -rf {{.ANSIBLE_DIR}}
54 changes: 0 additions & 54 deletions .taskfiles/AnsibleTasks.yaml

This file was deleted.

25 changes: 0 additions & 25 deletions .taskfiles/BrewTasks.yaml

This file was deleted.

81 changes: 0 additions & 81 deletions .taskfiles/ClusterTasks.yaml

This file was deleted.

68 changes: 68 additions & 0 deletions .taskfiles/Flux/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"

vars:
# renovate: datasource=github-releases depName=prometheus-operator/prometheus-operator
PROMETHEUS_OPERATOR_VERSION: v0.73.2
CLUSTER_SECRET_SOPS_FILE: "{{.KUBERNETES_DIR}}/flux/vars/cluster-secrets.sops.yaml"
CLUSTER_SETTINGS_FILE: "{{.KUBERNETES_DIR}}/flux/vars/cluster-settings.yaml"
GITHUB_DEPLOY_KEY_FILE: "{{.KUBERNETES_DIR}}/bootstrap/flux/github-deploy-key.sops.yaml"

tasks:

bootstrap:
desc: Bootstrap Flux into a Kubernetes cluster
cmds:
- 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 --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 --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 --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
- kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --kustomize {{.KUBERNETES_DIR}}/bootstrap/flux
- cat {{.AGE_FILE}} | kubectl -n flux-system create secret generic sops-age --from-file=age.agekey=/dev/stdin
- sops --decrypt {{.CLUSTER_SECRET_SOPS_FILE}} | kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename -
- kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename {{.CLUSTER_SETTINGS_FILE}}
- kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --kustomize {{.KUBERNETES_DIR}}/flux/config
preconditions:
- { msg: "Missing kubeconfig", sh: "test -f {{.KUBECONFIG_FILE}}" }
- { msg: "Missing Sops Age key file", sh: "test -f {{.AGE_FILE}}" }

apply:
desc: Apply a Flux Kustomization resource for a cluster
summary: |
Args:
path: Path under apps containing the Flux Kustomization resource (ks.yaml) (required)
ns: Namespace the Flux Kustomization exists in (default: flux-system)
cmd: |
flux --kubeconfig {{.KUBECONFIG_FILE}} build ks $(basename {{.path}}) \
--namespace {{.ns}} \
--kustomization-file {{.KUBERNETES_DIR}}/apps/{{.path}}/ks.yaml \
--path {{.KUBERNETES_DIR}}/apps/{{.path}} \
{{- if contains "not found" .ks }}--dry-run \{{ end }}
| \
kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side \
--field-manager=kustomize-controller -f -
requires:
vars: ["path"]
vars:
ns: '{{.ns | default "flux-system"}}'
ks:
sh: flux --kubeconfig {{.KUBECONFIG_FILE}} --namespace {{.ns}} get kustomizations $(basename {{.path}}) 2>&1
preconditions:
- { msg: "Missing kubeconfig", sh: "test -f {{.KUBECONFIG_FILE}}" }
- { msg: "Missing Flux Kustomization for app {{.path}}", sh: "test -f {{.KUBERNETES_DIR}}/apps/{{.path}}/ks.yaml" }

reconcile:
desc: Force update Flux to pull in changes from your Git repository
cmd: flux --kubeconfig {{.KUBECONFIG_FILE}} reconcile --namespace flux-system kustomization cluster --with-source
preconditions:
- { msg: "Missing kubeconfig", sh: "test -f {{.KUBECONFIG_FILE}}" }

github-deploy-key:
cmds:
- kubectl create namespace flux-system --dry-run=client -o yaml | kubectl --kubeconfig {{.KUBECONFIG_FILE}} apply --filename -
- sops --decrypt {{.GITHUB_DEPLOY_KEY_FILE}} | kubectl apply --kubeconfig {{.KUBECONFIG_FILE}} --server-side --filename -
preconditions:
- { msg: "Missing kubeconfig", sh: "test -f {{.KUBECONFIG_FILE}}" }
- { msg: "Missing Sops Age key file", sh: "test -f {{.AGE_FILE}}" }
- { msg: "Missing Github deploy key file", sh: "test -f {{.GITHUB_DEPLOY_KEY_FILE}}" }
57 changes: 0 additions & 57 deletions .taskfiles/FluxTasks.yaml

This file was deleted.

Loading

0 comments on commit fe25584

Please sign in to comment.