Skip to content

Commit

Permalink
Add Taskfile for Kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
nidr0x committed Oct 20, 2024
1 parent 8c618e6 commit e3a2ed9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .taskfiles/kubernetes/Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"

tasks:
delete-failed-pods:
desc: Deletes pods with Failed phase
cmds:
- task: _delete_pods_in_phase
vars:
PHASE: Failed

delete-succeeded-pods:
desc: Deletes pods with Succeeded phase
cmds:
- task: _delete_pods_in_phase
vars:
PHASE: Succeeded

delete-pending-pods:
desc: Deletes pods with Pending phase
cmds:
- task: _delete_pods_in_phase
vars:
PHASE: Pending

_delete_pods_in_phase:
desc: Deletes pods with a specific phase
internal: true
requires:
vars:
- PHASE
cmds:
- for:
var: PHASE
split: ","
cmd: kubectl delete pods --field-selector status.phase={{.ITEM}} -A --ignore-not-found=true

sync-externalsecret:
desc: Sync ExternalSecret resource
summary: |
Args:
NS: Namespace the PVC is in (default: default)
NAME: ExternalSecret to sync (default: all secrets)
silent: true
vars:
NS: '{{.NS | default "default"}}'
NAME: '{{ .NAME | default "" }}'
cmds:
- |
{{if eq .NAME ""}}
kubectl get externalsecret.external-secrets.io --all-namespaces --no-headers -A | awk '{print $1, $2}' \
| xargs --max-procs=2 -n 2 bash -c 'echo "Namespace: $0, Name: $1"; kubectl --namespace $0 annotate externalsecret.external-secrets.io $1 force-sync=$(date +%s) --overwrite'
{{else}}
kubectl --namespace {{.NS}} annotate externalsecret.external-secrets.io {{.NAME}} force-sync=$(date +%s) --overwrite
{{end}}
preconditions:
- sh: '{{if ne .NAME ""}}kubectl --namespace {{.NS}} get externalsecret {{.NAME}}{{end}}'
msg: "ExternalSecret {{.NAME}} not found in namespace {{.NS}}"
23 changes: 23 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
version: "3"

vars:
KUBERNETES_DIR: "{{.ROOT_DIR}}/terraform/talos"
K8S_CLUSTER: '{{.K8S_CLUSTER | default "main"}}'

includes:
pre-commit:
taskfile: .taskfiles/pre-commit
dir: .taskfiles/pre-commit
talos:
taskfile: .taskfiles/talos
dir: .taskfiles/talos
kubernetes:
taskfile: .taskfiles/kubernetes
dir: .taskfiles/kubernetes

tasks:
default:
silent: true
cmds:
- task -l

0 comments on commit e3a2ed9

Please sign in to comment.