generated from onedr0p/cluster-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(github): add kubeconform workflow (#90)
- Loading branch information
1 parent
12f9073
commit a383fe4
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
set -o errexit | ||
|
||
KUBERNETES_DIR=$1 | ||
SCHEMA_DIR=$2 | ||
KUBE_VERSION="${3:-1.28.0}" | ||
|
||
[[ -z "${KUBERNETES_DIR}" ]] && echo "Kubernetes location not specified" && exit 1 | ||
[[ -z "${SCHEMA_DIR}" ]] && echo "Schema 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" | ||
"ReplicationSource,ReplicationDestination,Secret" | ||
"-schema-location" | ||
"default" | ||
"-schema-location" | ||
"${SCHEMA_DIR}/{{.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
name: "Kubeconform" | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: ["main"] | ||
paths: | ||
- "kubernetes/**" | ||
|
||
env: | ||
SCHEMA_DIR: /home/runner/crds | ||
|
||
jobs: | ||
kubeconform: | ||
name: Kubeconform | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
path: ["kubernetes"] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Setup Homebrew | ||
uses: Homebrew/actions/setup-homebrew@master | ||
|
||
- name: Setup Tools | ||
shell: bash | ||
run: brew install kubeconform kustomize | ||
|
||
- name: Setup QEMU | ||
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 | ||
|
||
- name: Setup Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 | ||
|
||
- name: Extract files from container image | ||
shell: bash | ||
run: | | ||
mkdir -p ${{ env.SCHEMA_DIR }} | ||
docker run --rm \ | ||
-v ${{ env.SCHEMA_DIR }}:/crds \ | ||
-u $(id -u) \ | ||
--entrypoint /bin/sh \ | ||
ghcr.io/martinohmann/kubernetes-schemas:latest \ | ||
-c "cp -r /usr/share/nginx/html/* /crds" | ||
- name: Run kubeconform | ||
shell: bash | ||
run: bash ./.github/scripts/kubeconform.sh ${{ matrix.path }} ${{ env.SCHEMA_DIR }} |