diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index ce264eb..23b1d7d 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -3,3 +3,4 @@ description : "Run Kubeconform on yaml files" entry: ./kubeconform.sh language: script + files: \.(yaml|yml)$ diff --git a/kubeconform.sh b/kubeconform.sh index 614f6e6..06b7f66 100755 --- a/kubeconform.sh +++ b/kubeconform.sh @@ -1,9 +1,17 @@ - - #!/bin/bash usage() { echo "Usage: ${0} [-p ]"; exit 1; } +check() { + which kubeconform + if [[ $? -gt 0 ]]; then + echo "kubeconform not found, please install it from https://github.com/yannh/kubeconform/releases/latest" + exit 255 + fi +} + +check + kpath="" while getopts "p:" arg; do case ${arg} in @@ -20,13 +28,12 @@ shift $((OPTIND-1)) for arg in "$@" do - if [[ $arg == *".yaml" ]]; then - if [[ $path != "" ]]; then - if [[ $arg != *"$path"* ]]; then + if [[ $kpath != "" ]]; then + echo ${arg} | grep -q ${kpath} + if [[ $? -gt 0 ]]; then continue fi fi echo "Running kubeconform on $arg" kubeconform -strict -ignore-missing-schemas -summary -schema-location default -schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' $arg - fi done \ No newline at end of file