[dmt] Validate module.yaml consistency with package.yaml#366
Open
diyliv wants to merge 6 commits into
Open
Conversation
Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: diyliv <onlogn081@gmail.com>
Contributor
There was a problem hiding this comment.
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-consistencyrule that compares names, platform requirements (Deckhouse/Kubernetes), and module dependencies betweenmodule.yamlandpackage.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 therequirementssection 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) |
Comment on lines
+45
to
+47
| func (r *ModulePackageConsistencyRule) CheckModulePackageConsistency(modulePath string, errorList *errors.LintRuleErrorsList) { | ||
| errorList = errorList.WithRule(r.GetName()).WithFilePath(ModuleConfigFilename) | ||
|
|
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 |
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) | ||
| } |
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 | ||
| } |
…aths Signed-off-by: diyliv <onlogn081@gmail.com>
Signed-off-by: diyliv <onlogn081@gmail.com>
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.
Summary
Add cross-validation between module.yaml and package.yaml to ensure both files stay consistent during the migration period:
namemust match package.yamlname.requirements.deckhousemust match package.yamlrequirements.deckhouse.constraint.requirements.kubernetesmust match package.yamlrequirements.kubernetes.constraint.!optionalmust be in mandatory, entries with!optionalmust 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:
Inconsistent files — errors reported: