Fix Kubernetes reference yml file
This commit is contained in:
parent
c7487c4a69
commit
2b710f05b3
13 changed files with 56 additions and 9 deletions
|
|
@ -34,6 +34,7 @@ RUN apk --no-cache --no-progress add \
|
|||
|
||||
COPY ./scripts/verify.sh /verify.sh
|
||||
COPY ./scripts/lint.sh /lint.sh
|
||||
COPY ./scripts/lint-yaml.sh /lint-yaml.sh
|
||||
|
||||
WORKDIR /app
|
||||
VOLUME ["/tmp","/app"]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
kind: GatewayClass
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
kind: GatewayClass
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
|
|
|
|||
48
docs/scripts/lint-yaml.sh
Executable file
48
docs/scripts/lint-yaml.sh
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/bin/sh
|
||||
# This script checks that YAML files with multiple Kubernetes resources
|
||||
# do not start with '---'
|
||||
#
|
||||
# Rule: If a YAML file contains more than one Kubernetes resource
|
||||
# (indicated by '---' separator in the middle of the file),
|
||||
# it should NOT start with '---'
|
||||
|
||||
set -eu
|
||||
|
||||
BASE_DIR="${1:-/app}"
|
||||
|
||||
echo "== Linting YAML files (Kubernetes multi-resource format)"
|
||||
|
||||
# Find all YAML files in the content directory
|
||||
find "${BASE_DIR}/content" -type f \( -name "*.yml" -o -name "*.yaml" \) | while read -r file; do
|
||||
# Count the number of '---' lines in the file
|
||||
separator_count=$(grep -c "^---" "$file" || true)
|
||||
|
||||
# Check if file starts with '---'
|
||||
starts_with_separator=false
|
||||
if head -1 "$file" | grep -q "^---"; then
|
||||
starts_with_separator=true
|
||||
fi
|
||||
|
||||
# If file has multiple resources (separator_count >= 1 when starting with ---, or >= 2 otherwise)
|
||||
# and starts with '---', it's an error
|
||||
#
|
||||
# Logic:
|
||||
# - If starts with '---' and has more than 1 separator -> multiple resources, error
|
||||
# - If doesn't start with '---' and has 1+ separators -> multiple resources, ok
|
||||
if [ "$starts_with_separator" = true ] && [ "$separator_count" -gt 1 ]; then
|
||||
echo "ERROR: $file starts with '---' but contains multiple Kubernetes resources"
|
||||
echo " Files with multiple resources should not start with '---'"
|
||||
# We need to signal error but can't use EXIT_CODE in subshell
|
||||
# So we output to a temp file
|
||||
echo "1" > /tmp/yaml_lint_error
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if any errors were found
|
||||
if [ -f /tmp/yaml_lint_error ]; then
|
||||
rm -f /tmp/yaml_lint_error
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "YAML lint passed"
|
||||
exit 0
|
||||
|
|
@ -8,6 +8,9 @@ set -eu
|
|||
EXIT_CODE=0
|
||||
readonly BASE_DIR=/app
|
||||
|
||||
# Run YAML linter for Kubernetes multi-resource files
|
||||
/lint-yaml.sh "${BASE_DIR}" || EXIT_CODE=1
|
||||
|
||||
echo "== Linting Markdown"
|
||||
# Uses the file ".markdownlint.json" for setup
|
||||
cd "${BASE_DIR}" || exit 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue