Skip to content

[dmt] Validate subscribe.apis in package.yaml#370

Open
diyliv wants to merge 5 commits into
feature/package-yaml-requirements-validationfrom
feature/validate-subscribe-package-yaml
Open

[dmt] Validate subscribe.apis in package.yaml#370
diyliv wants to merge 5 commits into
feature/package-yaml-requirements-validationfrom
feature/validate-subscribe-package-yaml

Conversation

@diyliv
Copy link
Copy Markdown
Contributor

@diyliv diyliv commented May 21, 2026

Summary

  • Validate subscribe.apis format: require entries to use <group>/<version>/<Kind> with a non-empty API group.
  • Reject invalid kinds: report malformed Kind values such as lowercase names in package.yaml.
  • Cover the rule with tests: add unit and rule-level cases for valid and invalid subscribe.apis entries.
  • Update documentation: document the new package.yaml validation in the module linter README.

Example

# valid
subscribe:
  apis:
    - autoscaling.k8s.io/v1/VerticalPodAutoscaler

# invalid
subscribe:
  apis:
    - v1/Pod
    - apps/v1/pod

diyliv added 2 commits May 21, 2026 18:27
Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv diyliv marked this pull request as draft May 21, 2026 15:34
@diyliv diyliv self-assigned this May 21, 2026
@diyliv diyliv added enhancement New feature or request go Pull requests that update go code labels May 21, 2026
Signed-off-by: diyliv <onlogn081@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the module package.yaml linter rule to validate subscribe.apis entries so that subscribed Kubernetes API references are consistently specified as <group>/<version>/<Kind>, rejecting malformed groups/versions and non-conforming Kind strings. This fits into the module linter’s role of enforcing package metadata correctness early (at lint time) to avoid publishing invalid module packages.

Changes:

  • Added subscribe.apis validation to the package.yaml rule, including Kubernetes-like validation for API group and version plus a Kind format check.
  • Added unit tests and rule-level tests covering valid/invalid subscribe.apis values.
  • Updated the module linter README to document the new validation and error examples.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/linters/module/rules/package_yaml.go Adds subscribe.apis validation logic and helpers (group/version/kind checks).
pkg/linters/module/rules/package_yaml_test.go Adds targeted unit tests for subscribe.apis and integrates cases into rule-level tests.
pkg/linters/module/README.md Documents the new subscribe.apis validation behavior and example errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +289 to +300
func validatePackageSubscribeAPI(fieldPath, value string, errorList *errors.LintRuleErrorsList) {
parts := strings.Split(value, "/")
if len(parts) != 3 {
errorList.Errorf("package.yaml %s must use %q format with a non-empty API group", fieldPath, "<group>/<version>/<Kind>")
return
}

group, version, kind := parts[0], parts[1], parts[2]
if group == "" || version == "" || kind == "" {
errorList.Errorf("package.yaml %s must use %q format with a non-empty API group", fieldPath, "<group>/<version>/<Kind>")
return
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +312 to +314
if !isValidSubscribeAPIKind(kind) {
errorList.Errorf("package.yaml %s kind must be UpperCamelCase and start with an uppercase letter", fieldPath)
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv diyliv marked this pull request as ready for review May 22, 2026 10:01
@diyliv diyliv marked this pull request as draft May 24, 2026 11:00
Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv diyliv marked this pull request as ready for review May 25, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants