Repository navigation
feat(xrd): add an alpha xrd lint command (stacked on #449) - #465
Closed
GenerikUser wants to merge 7 commits into
Closed
GenerikUser wants to merge 7 commits into
GenerikUser wants to merge 7 commits into
Conversation
Signed-off-by: GenerikUser <[email protected]>
- Build the xrd-diff/ rules on sigs.k8s.io/crdify's validations package,
with one rule per crdify comparator plus xrd-diff/unhandled, and list
crdify as prior art.
- Evaluate xrd-diff/no-version-removal over the union of old and new
version names, so removed or unserved versions are caught.
- Add xrd/served-versions-compatible to compare the served versions of a
single XRD.
- Let --old read from files, git refs, the current cluster or an xpkg.
- Use the {severity, options} object form for rule options.
- Decode the config with yaml.v3 and KnownFields only.
- Build the CEL environment with the Kubernetes CEL libraries and a cost
limit, give lint/rule-error the failing rule's severity, add an optional
docsURL to custom rules, and state that diff rules see the schema root.
- Keep the Go rule API internal until the command reaches beta.
- Replace the diff examples that are now built-in rules, and wrap long
table rows to 100 columns.
Signed-off-by: GenerikUser <[email protected]>
- A rule that fails to evaluate, including on exceeding the CEL cost limit, now fails the whole run with a non-zero exit, whatever the rule's configured severity. lint/rule-error is always an error and cannot be disabled or suppressed. - Make xrd/served-versions-compatible an error by default, alongside the other rules that guard against real misbehaviour. - State the crdify dependency plainly: it is pre-1.0 and lint pins it. Signed-off-by: GenerikUser <[email protected]>
Name a kubeconfig context and a single XRD in kube:// sources, and allow a directory in git:// paths. Describe the served-version check as crdify runs it: every pair of served versions in Kubernetes version order, only new incompatibilities when --old is given, and its conversion option. Add xrd-diff/scope from crdify's scope check. Enforce the CEL cost limit at runtime with the API server's per-call limit, since an estimate cannot bound dynamic maps, and build the environment at the vendored compatibility version. Keep the rule test helper internal. Signed-off-by: GenerikUser <[email protected]>
A rule value is a bare severity or a {severity, options} object. Say
explicitly that ESLint's array form is not accepted and that a YAML
sequence as a rule value is a config error.
Signed-off-by: GenerikUser <[email protected]>
xrd/served-versions-compatible now reports every incompatible pair of served versions, with or without --old, and checks every XRD whether or not it configures a conversion webhook. Drop the conversion option and the subtraction of incompatibilities the old XRD already had. Signed-off-by: GenerikUser <[email protected]>
Add `crossplane xrd lint`, the first slice of the design in
design/one-pager-cli-xrd-lint.md. It checks XRDs against a registry of
rules and reports each finding with its rule, severity, location and
docs link.
- internal/xrdlint holds the rule interface, registry, config, loader,
schema walker, runner and renderers. It is internal while the command
is alpha.
- .crossplane-lint.yaml is found by searching upward from the working
directory, or set with --config. It is parsed with yaml.v3 and
KnownFields, so unknown and duplicate keys are errors. A rule value is
a severity or {severity, options}; the list form is rejected. Options
are validated against the schema a rule declares, and entries naming
no known rule are errors. customRules is rejected until CEL rules land.
- Each XRD first gets the structural check `xrd convert` applies. An XRD
that fails it is reported as lint/invalid-xrd and is not linted further.
- A rule that returns an error or panics is reported as lint/rule-error,
which always fails the run, whatever the rule's severity. The other
rules still run.
- Inline `# crossplane-lint-disable-next-line rule -- reason` comments
suppress findings on the next node and its children. A comment that
suppresses nothing is reported as lint/unused-disable.
- Output is text, json or yaml. The command fails on any error, on
warnings beyond --max-warnings, on an invalid config, on unreadable
input, or when the inputs hold no XRDs.
- Built-in rules: xrd/status-fields-optional,
xrd/status-no-value-validation and xrd/lists-need-list-type (error),
and xrd/no-bools (warn).
- xrdlinttest runs table-driven rule tests.
Signed-off-by: GenerikUser <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
This is the first slice of
crossplane xrd lint, as described indesign/one-pager-cli-xrd-lint.md. It lays down the foundation that later PRs build on:crossplane xrd lint [flags] <files-or-dirs|->...is added underxrdas alpha. It has--config,-o text|json|yamland--max-warnings.internal/xrdlint. This package holds the rule interface (SchemaRule,Meta,Context), the registry, the config, ayaml.v3loader that keeps line numbers and comments, a schema walker, the runner and the renderers. It is internal while the command is alpha, as the design says..crossplane-lint.yamlis found by searching upward from the working directory. It is decoded withyaml.v3andKnownFields(true), so unknown and duplicate keys are errors.rule: <severity>orrule: {severity, options}. The list form is a config error.customRulesis rejected with a "not supported yet" error.internal/crd.FromXRD. An XRD that fails it is reported aslint/invalid-xrd, and no other rule runs on it.lint/rule-error. That finding is always an error and cannot be suppressed, so it fails the run whatever the rule's severity. The other rules still run and report.# crossplane-lint-disable-next-line rule-a, rule-b -- reasoncomment covers the next node and everything beneath it. A named rule that suppresses nothing is reported aslint/unused-disable(warn).--max-warningsxrd/status-fields-optional(error)xrd/status-no-value-validation(error)xrd/lists-need-list-type(error)xrd/no-bools(warn)xrdlinttest.Run. A table-driven rule tester, which needs at least one passing and one failing case per rule.Deferred to follow-up PRs, in this order:
xrd/rules:array-of-objects-needs-key,no-floats,no-maps,no-preserve-unknown-fields,no-phase,require-description(ignoreStatus) andstring-max-length(max), plusversion-naming. They need nothing beyond this slice.xrd-diff/*on crdify'sCompareProperties, together withxrd/served-versions-compatible(error by default, every incompatible pair of served versions reported).xrd-diff/unhandleddefaults to error, andxrd-diff/no-version-removalandxrd-diff/scopeare included. This adds theDiffRuleinterface and the crdify dependency.--oldsources: a plain path orfile://,git://<ref>?path=,kube://[<name>][?context=]andxpkg://<ref>.customRules, withmatch: property | xrd | diff): an environment with the Kubernetes CEL libraries, and a runtime cost limit at the API server's per-call limit.For reviewers:
SchemaRule.Checkreturns anerror. The one-pager's sketch has no return value. An error return is how a rule that cannot run surfaces aslint/rule-error.additionalPropertiesget the path segment.*, and array items get[*].Refs #69
I have:
RunNot run locally. I ran./nix.sh flake checkto ensure this PR is ready for review.go test ./...andgolangci-lint run ./...with the repo's.golangci.ymlinstead; both pass (0 issues).Linked a PR or a docs tracking issue to document this change.The command is alpha and its help text documents it. Docs will follow once the rule set settles.AddedThis is a new feature.backport release-x.ylabels to auto-backport this PR.