Fix Kubernetes reference yml file
This commit is contained in:
parent
c7487c4a69
commit
2b710f05b3
13 changed files with 56 additions and 9 deletions
2
.github/workflows/validate.yaml
vendored
2
.github/workflows/validate.yaml
vendored
|
|
@ -8,7 +8,7 @@ on:
|
||||||
env:
|
env:
|
||||||
GO_VERSION: '1.24'
|
GO_VERSION: '1.24'
|
||||||
GOLANGCI_LINT_VERSION: v2.0.2
|
GOLANGCI_LINT_VERSION: v2.0.2
|
||||||
MISSPELL_VERSION: v0.6.0
|
MISSPELL_VERSION: v0.7.0
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ RUN apk --no-cache --no-progress add \
|
||||||
|
|
||||||
COPY ./scripts/verify.sh /verify.sh
|
COPY ./scripts/verify.sh /verify.sh
|
||||||
COPY ./scripts/lint.sh /lint.sh
|
COPY ./scripts/lint.sh /lint.sh
|
||||||
|
COPY ./scripts/lint-yaml.sh /lint-yaml.sh
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
VOLUME ["/tmp","/app"]
|
VOLUME ["/tmp","/app"]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: apiextensions.k8s.io/v1
|
apiVersion: apiextensions.k8s.io/v1
|
||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: gateway.networking.k8s.io/v1
|
apiVersion: gateway.networking.k8s.io/v1
|
||||||
kind: GatewayClass
|
kind: GatewayClass
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: gateway.networking.k8s.io/v1
|
apiVersion: gateway.networking.k8s.io/v1
|
||||||
kind: GatewayClass
|
kind: GatewayClass
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: ServiceAccount
|
kind: ServiceAccount
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
---
|
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
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
|
EXIT_CODE=0
|
||||||
readonly BASE_DIR=/app
|
readonly BASE_DIR=/app
|
||||||
|
|
||||||
|
# Run YAML linter for Kubernetes multi-resource files
|
||||||
|
/lint-yaml.sh "${BASE_DIR}" || EXIT_CODE=1
|
||||||
|
|
||||||
echo "== Linting Markdown"
|
echo "== Linting Markdown"
|
||||||
# Uses the file ".markdownlint.json" for setup
|
# Uses the file ".markdownlint.json" for setup
|
||||||
cd "${BASE_DIR}" || exit 1
|
cd "${BASE_DIR}" || exit 1
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,6 @@ controller-gen crd:crdVersions=v1 \
|
||||||
echo "# Concatenate the CRD definitions for publication and integration tests ..."
|
echo "# Concatenate the CRD definitions for publication and integration tests ..."
|
||||||
cat "${CURRENT_DIR}"/docs/content/reference/dynamic-configuration/traefik.io_*.yaml > "${CURRENT_DIR}"/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml
|
cat "${CURRENT_DIR}"/docs/content/reference/dynamic-configuration/traefik.io_*.yaml > "${CURRENT_DIR}"/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml
|
||||||
cp -f "${CURRENT_DIR}"/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml "${CURRENT_DIR}"/integration/fixtures/k8s/01-traefik-crd.yml
|
cp -f "${CURRENT_DIR}"/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml "${CURRENT_DIR}"/integration/fixtures/k8s/01-traefik-crd.yml
|
||||||
|
|
||||||
|
# Remove leading '---' from the concatenated file (files with multiple resources should not start with ---)
|
||||||
|
sed -i '1{/^---$/d;}' "${CURRENT_DIR}"/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue