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

+12 -1
View File
@@ -2,6 +2,9 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
vars:
KUBECONFORM_SCRIPT: "{{.TASKFILE_DIR}}/.taskfiles/Kubernetes/kubeconform.sh"
tasks:
mount:
@@ -47,7 +50,7 @@ tasks:
ns: '{{.ns | default "default"}}'
claim: '{{ or .claim (fail "Argument (claim) is required") }}'
preconditions:
- { msg: "PVC not found", sh: "kubectl -n {{.ns}} get persistentvolumeclaim {{.claim}}" }
- sh: kubectl -n {{.ns}} get persistentvolumeclaim {{.claim}}
resources:
desc: Gather common resources in your cluster, useful when asking for support
@@ -65,3 +68,11 @@ tasks:
certificaterequests
ingresses
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}}
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -o errexit
KUBERNETES_DIR=$1
KUBE_VERSION="${2:-1.29.0}"
[[ -z "${KUBERNETES_DIR}" ]] && echo "Kubernetes location not specified" && exit 1
kustomize_args=("--load-restrictor=LoadRestrictionsNone")
kustomize_config="kustomization.yaml"
kubeconform_args=(
"-strict"
"-ignore-missing-schemas"
"-kubernetes-version"
"${KUBE_VERSION}"
"-skip"
"Secret"
"-schema-location"
"default"
"-schema-location"
"https://kubernetes-schemas.pages.dev/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json"
"-verbose"
)
echo "=== Validating standalone manifests in ${KUBERNETES_DIR}/flux ==="
find "${KUBERNETES_DIR}/flux" -maxdepth 1 -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file;
do
kubeconform "${kubeconform_args[@]}" "${file}"
if [[ ${PIPESTATUS[0]} != 0 ]]; then
exit 1
fi
done
echo "=== Validating kustomizations in ${KUBERNETES_DIR}/flux ==="
find "${KUBERNETES_DIR}/flux" -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file;
do
echo "=== Validating kustomizations in ${file/%$kustomize_config} ==="
kustomize build "${file/%$kustomize_config}" "${kustomize_args[@]}" | \
kubeconform "${kubeconform_args[@]}"
if [[ ${PIPESTATUS[0]} != 0 ]]; then
exit 1
fi
done
echo "=== Validating kustomizations in ${KUBERNETES_DIR}/apps ==="
find "${KUBERNETES_DIR}/apps" -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file;
do
echo "=== Validating kustomizations in ${file/%$kustomize_config} ==="
kustomize build "${file/%$kustomize_config}" "${kustomize_args[@]}" | \
kubeconform "${kubeconform_args[@]}"
if [[ ${PIPESTATUS[0]} != 0 ]]; then
exit 1
fi
done