Skip to content

[dmt] Validate module.yaml consistency with package.yaml#366

Open
diyliv wants to merge 6 commits into
feature/package-yaml-requirements-validationfrom
feature/module-package-consistency
Open

[dmt] Validate module.yaml consistency with package.yaml#366
diyliv wants to merge 6 commits into
feature/package-yaml-requirements-validationfrom
feature/module-package-consistency

Conversation

@diyliv
Copy link
Copy Markdown
Contributor

@diyliv diyliv commented May 19, 2026

Summary

Add cross-validation between module.yaml and package.yaml to ensure both files stay consistent during the migration period:

  • Cross-validate name field: module.yaml name must match package.yaml name.
  • Cross-validate deckhouse requirement: module.yaml requirements.deckhouse must match package.yaml requirements.deckhouse.constraint.
  • Cross-validate kubernetes requirement: module.yaml requirements.kubernetes must match package.yaml requirements.kubernetes.constraint.
  • Cross-validate module dependencies: module.yaml flat module map is compared against package.yaml structured mandatory/conditional lists — entries without !optional must be in mandatory, entries with !optional must be in conditional. Both directions are checked.

If developers no longer want to maintain both files, they should delete module.yaml.

Example

Consistent files — no errors:

# module.yaml
name: stronghold
namespace: test
requirements:
  deckhouse: ">= 1.77"
  kubernetes: ">= 1.27"
  modules:
    mandatory-mod: ">= 1.0.0"
    optional-mod: ">= 1.0.0 !optional"

# package.yaml
name: stronghold
apiVersion: v2
requirements:
  deckhouse:
    constraint: ">= 1.77"
  kubernetes:
    constraint: ">= 1.27"
  modules:
    mandatory:
      - name: mandatory-mod
        constraint: ">= 1.0.0"
    conditional:
      - name: optional-mod
        constraint: ">= 1.0.0"

Inconsistent files — errors reported:

# module.yaml
name: stronghold
requirements:
  modules:
    some-module: ">= 1.0.0"         # mandatory here

# package.yaml
name: stronghold
requirements:
  modules:
    conditional:                     # but conditional here
      - name: some-module
        constraint: ">= 1.0.0"

Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv diyliv self-assigned this May 19, 2026
@diyliv diyliv added enhancement New feature or request go Pull requests that update go code labels May 19, 2026
diyliv added 2 commits May 19, 2026 15:21
Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv diyliv requested a review from ipaqsa May 19, 2026 18:31
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

Adds a new module linter rule to cross-validate module.yaml against package.yaml during the migration period, helping detect divergence across shared fields and dependency declarations.

Changes:

  • Introduce module-package-consistency rule that compares names, platform requirements (Deckhouse/Kubernetes), and module dependencies between module.yaml and package.yaml.
  • Add comprehensive unit/integration-style tests for the new consistency rule.
  • Wire the rule into the module linter execution path and linter configuration (global + runtime config structs).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/linters/module/rules/module_package_consistency.go Implements the cross-validation logic between module.yaml and package.yaml.
pkg/linters/module/rules/module_package_consistency_test.go Adds test coverage for matching/mismatching cases and parse-error behavior.
pkg/linters/module/module.go Runs the new rule as part of the module linter.
pkg/config/global/global.go Exposes the new rule in global config mapping (mapstructure).
pkg/config.go Exposes the new rule in runtime configuration structs.
Comments suppressed due to low confidence (1)

pkg/linters/module/rules/module_package_consistency.go:106

  • Same as Deckhouse: if pkg.Requirements == nil, reporting "...constraint is empty" is misleading because the requirements section is missing entirely. Consider a dedicated message for the missing requirements section.
	if pkg.Requirements == nil || pkg.Requirements.Kubernetes.Constraint == "" {
		errorList.Errorf("module.yaml requirements.kubernetes is %q but package.yaml requirements.kubernetes.constraint is empty", module.Requirements.Kubernetes)
		return

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

Comment on lines +56 to +68
pkg, err := getModulePackage(modulePath, pkgErrorList)
if err != nil {
return
}

if module == nil || pkg == nil {
return
}

compareNames(module, pkg, errorList)
compareDeckhouse(module, pkg, errorList)
compareKubernetes(module, pkg, errorList)
compareModules(module, pkg, errorList)
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 +45 to +47
func (r *ModulePackageConsistencyRule) CheckModulePackageConsistency(modulePath string, errorList *errors.LintRuleErrorsList) {
errorList = errorList.WithRule(r.GetName()).WithFilePath(ModuleConfigFilename)

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 +88 to +90
if pkg.Requirements == nil || pkg.Requirements.Deckhouse.Constraint == "" {
errorList.Errorf("module.yaml requirements.deckhouse is %q but package.yaml requirements.deckhouse.constraint is empty", module.Requirements.Deckhouse)
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 +93 to +95
if module.Requirements.Deckhouse != pkg.Requirements.Deckhouse.Constraint {
errorList.Errorf("module.yaml requirements.deckhouse %q does not match package.yaml requirements.deckhouse.constraint %q", module.Requirements.Deckhouse, pkg.Requirements.Deckhouse.Constraint)
}
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 +137 to +142
for name, constraint := range module.Requirements.ParentModules {
if strings.Contains(constraint, "!optional") {
moduleConditional[name] = strings.TrimSpace(strings.ReplaceAll(constraint, "!optional", ""))
} else {
moduleMandatory[name] = constraint
}
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

@diyliv diyliv marked this pull request as draft May 21, 2026 09:04
diyliv added 2 commits May 21, 2026 15:57
…aths

Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: diyliv <onlogn081@gmail.com>
@diyliv diyliv marked this pull request as ready for review May 22, 2026 12:10
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