Skip to content

[Tracking Umbrella] Integrate Kube API Linter for Declarative Validation Linting #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 9 tasks
yongruilin opened this issue May 7, 2025 · 1 comment
Open
1 of 9 tasks

Comments

@yongruilin
Copy link
Contributor

The Declarative Validation (KEP-5073) requires a linter for its IDL tags (e.g., +k8s:minimum). While validation-gen has some initial linting logic (e.g., for optional/required conflicts), kube-api-linter is a robust, existing tool for linting Kubernetes API types. This issue tracks leveraging kube-api-linter as the core linter for declarative validation IDL tags, aiming to replace or augment custom logic in validation-gen.

What you expected to happen:

Use kube-api-linter to:

  1. Validate correct usage of declarative validation IDL tags based on defined rules.
  2. Provide clear errors and potential auto-fixes for IDL tag mistakes.
  3. Replace/augment validation-gen's current linting capabilities for these specific rules.
  4. Ensure these linting rules are maintainable and extensible if new, similar interaction rules are defined.

To integrate, contributors need to address:

  1. Parsing/AST Interoperability & Data Model Definition

    • Define and document the structured data model for IDL tags and their Go code context (field, type, source location) required by linter rules. This model must be consistent with and leverage existing Kubernetes API Conventions, including any necessary extensions or specific interpretations for IDL tag linting.
    • Document the mechanism for kube-api-linter to reliably access or receive this structured data, ensuring accuracy despite potential interpretation differences between gengo (used by validation-gen) and go/ast (used by kube-api-linter).
  2. Linter Rules for Declarative Validation Tag Interactions (Additional rules may be identified as work progresses or KEP-5073 evolves.)

    • Conflicting Tags Rule: Implement rules to detect fields marked with mutually exclusive tags.
    • Dependent Tags Rule: Implement rules to ensure that if a primary tag is present, its dependent tag(s) must also be present.
      • +k8s:unionMember requires the field to also be marked with +k8s:optional.
    • Fields requirement Rule: Implement rules to ensure some tags must be present in specific fields
      • All pointer fields must have the +k8s:optional tag.
  3. Configuration and Integration

    • Specify the configuration mechanism for enabling, disabling, and parameterizing declarative validation lint rules within kube-api-linter.
    • Detail the planned invocation methods (e.g., via validation-gen --lint, direct kube-api-linter CLI, golangci-lint plugin) and how lint results (errors, warnings, fixes) will be processed and reported.
    • Develop a strategy for integrating these linters into the Kubernetes CI/presubmit checks.
@yongruilin
Copy link
Contributor Author

/cc @thockin @JoelSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant