feat: add kubeconform workflow and make kubeconform/kustomize required (#1159)

This commit is contained in:
Devin Buhl authored and GitHub committed 2024-01-15 09:42:50 -05:00
1 parent e6fbc6e128
commit ea31a49817
7 files changed
+43 -5

No files matched your search

+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
+1 -1
View File
@@ -114,7 +114,7 @@ jobs:
- name: Run kubeconform
shell: bash
run: ./scripts/kubeconform.sh ./kubernetes
run: ./.github/scripts/kubeconform.sh ./kubernetes
- name: List Hosts with Ansible
if: ${{ steps.config-env.outputs.distribution == 'k3s' || steps.config-env.outputs.distribution == 'k0s' }}
+28
View File
@@ -0,0 +1,28 @@
---
name: "Kubeconform"
on:
pull_request:
branches: ["main"]
paths: ["kubernetes/**"]
env:
KUBERNETES_DIR: ./kubernetes
jobs:
kubeconform:
name: Kubeconform
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Setup Workflow Tools
run: brew install fluxcd/tap/flux kubeconform kustomize
- name: Run kubeconform
shell: bash
run: ./.github/scripts/kubeconform.sh ${{ env.KUBERNETES_DIR }}