diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 470816bd5..ed46d1599 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -8,7 +8,7 @@ on: env: GO_VERSION: '1.24' GOLANGCI_LINT_VERSION: v2.0.2 - MISSPELL_VERSION: v0.6.0 + MISSPELL_VERSION: v0.7.0 jobs: diff --git a/docs/check.Dockerfile b/docs/check.Dockerfile index d9593e5ed..d89f9efa9 100644 --- a/docs/check.Dockerfile +++ b/docs/check.Dockerfile @@ -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"] diff --git a/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml b/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml index ef7c35ea0..e374f71b0 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml @@ -1,4 +1,3 @@ ---- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: diff --git a/docs/content/reference/dynamic-configuration/kubernetes-gateway-rbac.yml b/docs/content/reference/dynamic-configuration/kubernetes-gateway-rbac.yml index c03dc0147..b2ab1e5db 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-gateway-rbac.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-gateway-rbac.yml @@ -1,4 +1,3 @@ ---- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: diff --git a/docs/content/reference/dynamic-configuration/kubernetes-gateway-resource.yml b/docs/content/reference/dynamic-configuration/kubernetes-gateway-resource.yml index d3b1bef20..4b860c4c5 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-gateway-resource.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-gateway-resource.yml @@ -1,4 +1,3 @@ ---- apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: diff --git a/docs/content/reference/dynamic-configuration/kubernetes-gateway-simple-https.yml b/docs/content/reference/dynamic-configuration/kubernetes-gateway-simple-https.yml index 1f15ae429..886010b0b 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-gateway-simple-https.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-gateway-simple-https.yml @@ -1,4 +1,3 @@ ---- apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: diff --git a/docs/content/reference/dynamic-configuration/kubernetes-gateway-traefik-lb-svc.yml b/docs/content/reference/dynamic-configuration/kubernetes-gateway-traefik-lb-svc.yml index 7907daadc..ee5394387 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-gateway-traefik-lb-svc.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-gateway-traefik-lb-svc.yml @@ -1,4 +1,3 @@ ---- apiVersion: v1 kind: ServiceAccount metadata: diff --git a/docs/content/reference/dynamic-configuration/kubernetes-ingress-nginx-rbac.yml b/docs/content/reference/dynamic-configuration/kubernetes-ingress-nginx-rbac.yml index 57bd4afb6..ca36e2f41 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-ingress-nginx-rbac.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-ingress-nginx-rbac.yml @@ -1,4 +1,3 @@ ---- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: diff --git a/docs/content/reference/dynamic-configuration/kubernetes-knative-rbac.yml b/docs/content/reference/dynamic-configuration/kubernetes-knative-rbac.yml index 00276e7ef..ea721ec12 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-knative-rbac.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-knative-rbac.yml @@ -1,4 +1,3 @@ ---- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: diff --git a/docs/content/reference/dynamic-configuration/kubernetes-whoami-svc.yml b/docs/content/reference/dynamic-configuration/kubernetes-whoami-svc.yml index 32471e4c7..2a1b33be4 100644 --- a/docs/content/reference/dynamic-configuration/kubernetes-whoami-svc.yml +++ b/docs/content/reference/dynamic-configuration/kubernetes-whoami-svc.yml @@ -1,4 +1,3 @@ ---- apiVersion: apps/v1 kind: Deployment metadata: diff --git a/docs/scripts/lint-yaml.sh b/docs/scripts/lint-yaml.sh new file mode 100755 index 000000000..d48e8b1a9 --- /dev/null +++ b/docs/scripts/lint-yaml.sh @@ -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 diff --git a/docs/scripts/lint.sh b/docs/scripts/lint.sh index a46066df8..28f7716ed 100755 --- a/docs/scripts/lint.sh +++ b/docs/scripts/lint.sh @@ -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 diff --git a/script/code-gen.sh b/script/code-gen.sh index 529930801..59985a018 100755 --- a/script/code-gen.sh +++ b/script/code-gen.sh @@ -34,3 +34,6 @@ controller-gen crd:crdVersions=v1 \ 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 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