crossplane icon indicating copy to clipboard operation
crossplane copied to clipboard

Add a `crossplane lint xrd.yaml` command

Open negz opened this issue 1 year ago • 6 comments

What problem are you facing?

https://github.com/crossplane/docs/issues/564 tracks documenting best practices for API design. Put otherwise, best practices for writing XRDs. It occurred to me today that we could probably write a linter for a lot of these.

It could make sense for this to be part of crossplane beta validate too, but I think validation and linting are slightly different things. An XRD could have a valid OpenAPI schema, but one that we wouldn't recommend.

How could Crossplane help solve your problem?

Add a linter for XRDs. Some things to look for:

  • Overly restrictive status fields. Status fields aren't written by users, so they typically shouldn't be required, or generally validated beyond their type (e.g maximum integers, etc).
  • Arrays of objects missing a name field.
  • Boolean fields, which Kubernetes API conventions would typically recommend be enums.
  • Missing server-side apply merge OpenAPI extensions where we'd expect them.
  • General OpenAPI hygiene - fields missing descriptions etc

negz avatar Feb 15 '24 02:02 negz

crossplane lint --old=old-xrd.yaml new-xrd.yaml

If we supported linting XRD changes we could also look for breaking changes, e.g:

  • Introducing new required fields.
  • Making required fields optional.
  • Renaming fields without introducing a new version.

negz avatar Feb 15 '24 02:02 negz

Prior art: https://github.com/openshift/crd-schema-checker/

negz avatar Feb 15 '24 17:02 negz

Would love to have something like this

Cliftonz avatar Apr 06 '24 14:04 Cliftonz

@Cliftonz add a 👍 to help us prioritize issues. Thanks!

bobh66 avatar Apr 06 '24 14:04 bobh66

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

github-actions[bot] avatar Jul 06 '24 01:07 github-actions[bot]

/fresh

bobh66 avatar Jul 06 '24 15:07 bobh66