Skip to content
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

duplicate detection for add commands #564

Merged
merged 2 commits into from
Nov 8, 2023

Conversation

mandelsoft
Copy link
Contributor

@mandelsoft mandelsoft commented Nov 5, 2023

Description

The add commands now check for duplicate ids for resources, sources and references in specs and report
appropriate problems with the location in the source yaml files.
The same check is done for adding multiple components to avoid overwrite of components from the same action.

The CD validation now reports the identity of the validated component version, if the validation fails.

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

  • Related Issue # (issue)
  • Closes # (issue)
  • Fixes # (issue)

Remove if not applicable

Screenshots

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Added to documentation?

  • 📜 README.md
  • 🙅 no documentation needed

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

return list.Result()
}

func ValdateElementSpecIdentities(kind string, src string, elems []ElementSpec) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Suggested change
func ValdateElementSpecIdentities(kind string, src string, elems []ElementSpec) error {
func ValidateElementSpecIdentities(kind string, src string, elems []ElementSpec) error {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -279,6 +283,39 @@ func Validate(r *ResourceInput, ctx inputs.Context, inputFilePath string) error
return allErrs.ToAggregate()
}

func ValdateElementIdentities(kind string, elems []Element) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Suggested change
func ValdateElementIdentities(kind string, elems []Element) error {
func ValidateElementIdentities(kind string, elems []Element) error {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

return list.Result()
}

func ValdateElementSpecIdentities(kind string, src string, elems []ElementSpec) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the src string supposed to be?

Please choose a more tangible parameter name or add helpful comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added doc to various types and functions

Comment on lines 26 to 28
list.Add(addhdlrs.ValdateElementSpecIdentities("resource", elem.Source().String(), generics.ConvertSliceTo[addhdlrs.ElementSpec](r.Resources)))
list.Add(addhdlrs.ValdateElementSpecIdentities("source", elem.Source().String(), generics.ConvertSliceTo[addhdlrs.ElementSpec](r.Sources)))
list.Add(addhdlrs.ValdateElementSpecIdentities("reference", elem.Source().String(), generics.ConvertSliceTo[addhdlrs.ElementSpec](r.References)))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is an elements source (elem.Source())? Confusing name (especially since "Sources" actually are a core model element - is the core model element related to this function? If so, how?)

The package addhdlrs (where this function is from) contains generally quite generic coding with non-tangible namings and no comments to support the understanding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added docu

@@ -155,6 +155,10 @@ type ResourceSpec struct {

var _ addhdlrs.ElementSpec = (*ResourceSpec)(nil)

func (r *ResourceSpec) GetRawIdentity() metav1.Identity {
return metav1.NewIdentity(r.Name, metav1.SystemIdentityVersion, r.Version)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this constant called SystemIdentityVersion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SystemIdentityVersion and SystemIdentityName are the two predefined identity properties use to identify elements (resources, sources, referebces) in CDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added docu to their const definitions.

@mandelsoft mandelsoft merged commit 3c49136 into open-component-model:main Nov 8, 2023
10 checks passed
@mandelsoft mandelsoft deleted the dup branch November 8, 2023 09:59
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

Successfully merging this pull request may close these issues.

2 participants