Skip to content

Latest commit

 

History

History
131 lines (105 loc) · 5.9 KB

README.md

File metadata and controls

131 lines (105 loc) · 5.9 KB

Validate manifest naming

Enforce shared naming conventions for Kubernetes resources and machine configuration patches. Repository-specific roots and exceptions live in a versioned YAML file. Validation reads files without modifying them or contacting a cluster.

Inputs

Name Description Required Default
config-file Configuration path, relative to working-directory or absolute. No .github/manifest-naming.yaml
working-directory Repository directory, relative to GITHUB_WORKSPACE or absolute. No .

Outputs

Name Description
validated true after successful validation; empty when unsuccessful.

Usage

permissions:
  contents: read

steps:
  - uses: actions/checkout@<full-commit-sha> # vX.Y.Z
    with:
      persist-credentials: false
  - uses: devantler-tech/.github/actions/validate-naming@<full-commit-sha> # vX.Y.Z

Every call performs validation and requires the repository's own configuration.

Calls install the Go version declared in this action's go.mod, download its checksum-pinned YAML dependency with bounded retries, and build from the action's own module. The caller's Go module and workspace files are not used. The build needs network access to the Go distribution/module services; subsequent validation is offline. Linux and macOS runners are supported.

Configuration

Create .github/manifest-naming.yaml in the repository being checked:

version: 1
resource-roots: [k8s]
patch-roots: ["talos*"]
cr-directories:
  - k8s/infrastructure/cluster-policies
multi-resource-files:
  - k8s/controllers/example/operator.yaml
kind-prefix-exempt-files:
  - k8s/clusters/*/bootstrap/variables-secret.enc.yaml
filename-exempt-directories:
  - k8s/controllers/example/custom-resource-definitions

version must be 1. At least one scan root is required. Root patterns must match existing, non-overlapping directories and collectively contain at least one .yaml or .yml file. Paths use /, are relative to the repository root, and cannot contain .., absolute paths, or symlinks. Unknown configuration fields, malformed YAML, and multiple configuration documents fail validation.

Field Scope
resource-roots Directory paths or patterns recursively checked as Kubernetes manifests.
patch-roots Directory paths or patterns recursively checked as machine configuration patches; talos* includes new environments automatically.
cr-directories Directories whose resource files use instance/purpose names; descendants inherit this exception.
multi-resource-files Exact files exempt only from the one-resource rule, for upstream bundles.
kind-prefix-exempt-files Files exempt only from the ordinary resource kind prefix. Supports Go path.Match patterns: * stays within one path segment; ** has no special meaning.
filename-exempt-directories Directories whose YAML filename stems may retain upstream names. Other checks still apply.

All lists are optional except that resource-roots and patch-roots cannot both be empty. Exception paths may be absent, allowing configurations to retain an exception when a provider component is not present. Patterns in scan roots and kind-prefix-exempt-files use Go path matching: * does not cross /, and ** has no recursive meaning. The other lists contain exact paths. An unmatched root pattern is an error, so a misspelled directory cannot silently disable the gate.

The Platform and platform-template configurations illustrate the two original consumers. Copy and maintain the applicable configuration in the consumer; these examples are not live defaults.

Rules

  1. Directory names and YAML filename stems use lowercase kebab-case. Kubernetes .enc.yaml and .enc.yml files keep their encryption suffix.
  2. Kubernetes files contain at most one kind-bearing resource, except declared upstream bundles. Empty and comment-only documents do not count.
  3. Flux Kustomization resources use flux-kustomization.yaml or flux-kustomization-<purpose>.yaml.
  4. Kustomize build Kustomization and Component files use kustomization.yaml.
  5. Ordinary resource filenames lead with their kebab-cased kind, optionally followed by -<purpose>. CR directories and configured files are exempt.
  6. A directory with two or more files of one non-workload kind uses the kind's kebab-case plural. Organizational descendants of configured CR directories are exempt. Component/workload kinds follow the original gates' conventions. Already-plural Endpoints and SecurityContextConstraints names stay unchanged.
  7. Kindless Kubernetes patch fragments belong in patches/; kindless kustomization.yaml build files are allowed.
  8. Patches use intent names without a kind prefix or redundant -patch suffix. Flux patches retain the Flux filename convention.
  9. Machine configuration patches use intent names and contain at most one nonempty YAML document, including documents without a kind.

The parser handles document streams with or without a leading ---, quoted metadata, CRLF endings, and separators inside block scalars. Invalid YAML and duplicate mapping keys fail instead of being silently skipped. Diagnostics print paths and rule guidance, never whole manifests or parser excerpts.

Local validation

With an Actions checkout at the revision used by CI and Go installed:

GOWORK=off go -C /path/to/actions/validate-naming run -mod=readonly . \
  --root /path/to/consumer --config .github/manifest-naming.yaml

The action and CLI always validate. Exit codes are 0 for success, 1 for naming violations, and 2 for invalid configuration, YAML, arguments, or filesystem errors.

Run the validator's tests with:

go -C actions/validate-naming test -race -cover ./...
go -C actions/validate-naming vet ./...