Skip to content

fix: copy dependencies on aliasing to avoid sharing chart references on multiply aliased dependencies#9175

Merged
scottrigby merged 2 commits intohelm:mainfrom
dastrobu:copy-dependencies-on-aliasing
Apr 23, 2025
Merged

fix: copy dependencies on aliasing to avoid sharing chart references on multiply aliased dependencies#9175
scottrigby merged 2 commits intohelm:mainfrom
dastrobu:copy-dependencies-on-aliasing

Conversation

@dastrobu
Copy link
Copy Markdown
Contributor

@dastrobu dastrobu commented Dec 28, 2020

Dependencies keep a reference on their parent chart, which breaks if a chart reference is shared among multiple aliases.
By copying the dependencies, parent information can be set correctly to render the templates as expected later on.

Note that this change will make ChartFullPath return a different path for sub-subcharts. It will contain the alias names instead of the path to the chart files which makes it consistent with paths to templates on the subchart level.

Closes #9150

Signed-off-by: Daniel Strobusch 1847260+dastrobu@users.noreply.github.com

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@helm-bot helm-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 28, 2020
@itscaro
Copy link
Copy Markdown

itscaro commented Jan 25, 2021

@dastrobu Thank you for the PR, this is exactly what I need 👍

@dastrobu
Copy link
Copy Markdown
Contributor Author

@itscaro thanks for the feedback. Just need to get the maintainers attention to get someone reviewing this PR.

@whirm
Copy link
Copy Markdown

whirm commented Mar 31, 2021

Bump! I'm also very interested on getting it merged.

@thefang12
Copy link
Copy Markdown

Bump! this would greatly simplify my charts 🙏

@Crow-Control
Copy link
Copy Markdown

@bacongobbler you might have someone at least... well... look at this?

@bacongobbler bacongobbler added this to the 3.8.0 milestone Sep 7, 2021
@tavlima
Copy link
Copy Markdown

tavlima commented Sep 23, 2021

Beg your pardon, @bacongobbler, but is there any chance this can be released as a patch version in the 3.7.x train, instead of waiting for 3.8.0? This bug makes it really hard for one to create reusable/composable charts...

@scottrigby
Copy link
Copy Markdown
Member

This sounds like a bugfix. We'll investigate soon but for now labeling as such and moving to next patch release milestone.

@scottrigby scottrigby added the bug Categorizes issue or PR as related to a bug. label Jan 13, 2022
@scottrigby scottrigby modified the milestones: 3.8.0, 3.8.1 Jan 13, 2022
@mattfarina mattfarina modified the milestones: 3.8.1, 3.8.2 Mar 9, 2022
@trigger305
Copy link
Copy Markdown

would also like this one please as part of 3.8.2

@mattfarina mattfarina modified the milestones: 3.8.2, 3.9.0 Apr 13, 2022

// empty dependencies and shallow copy all dependencies, otherwise parent info may be corrupted if
// there is more than one dependency aliasing this chart
out.SetDependencies()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I seems from my local testing and the usecase I have (attached in zip) this is not enough while the following changes from this other PR is working:

		if md.Dependencies != nil {
			dependencies := make([]*chart.Dependency, len(md.Dependencies))
			for i := range md.Dependencies {
				d := *md.Dependencies[i]
				dependencies[i] = &d
			}
			md.Dependencies = dependencies
		}

reproducer-common-dep-import-value.zip

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.

I am happy to look into this, when there is feedback from the maintainers what milestone is realistic for this PR. If there is a case I overlooked, I guess there should be another test case as well.

Copy link
Copy Markdown
Contributor Author

@dastrobu dastrobu Dec 8, 2022

Choose a reason for hiding this comment

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

@mederel since I had some spare time and these issues are relly quite annoying, I took a look at the issue you
mentioned.

The example from your zip boils down to the following graph:

graph TD;
    umbrella-->child1;
    umbrella-->child2;
    umbrella-->child2-bis;
    child2-bis-. alias .->child2;
    child1-->common;
    child2-->common;
    child2-bis-->common;
Loading

The example can be a bit simplified by removing child1, while still showing the issue

graph TD;
    umbrella-->child2;
    umbrella-->child2-bis;
    child2-bis-. alias .->child2;
    child2-->common;
    child2-bis-->common;
Loading

So we are essentially back to the test case from #9150, which is

graph TD;
    parent-->foo;
    parent-->bar;
    foo-. alias .->child;
    bar-. alias .->child;
    foo-->grandchild;
    bar-->grandchild;
Loading

The only notably difference is the use of import-values in the two child charts and this is where it gets interesting.

The issue reported in #9150 was related to information stored in

parent *Chart

which is why I copied the Chart objects.

The issue you found is similar but in a different place:

ImportValues []interface{} `json:"import-values,omitempty"`

which is why you copied the Dependency objects in the metadata.

So in the end we need both. I updated this PR with a fix and a test case for the issue you mentioned.
I have to say that I don't like the solution. There seems to be a conceptual issue with aliases in Helm's dependency
management implementation from my point of view.

Some parts of the implementation seem to assume to reflect alias with the following graph in memory:

graph TD;
    parent-->child;
    parent-- aliased -->child;
Loading

while others assume

graph TD;
    parent-->child;
    parent-- aliased --> child-copy;
Loading

Depending on which path to follow information such as "imported values" or "parent" must be stored on the edges of the graph (first diagram) or can be stored on the nodes (second diagram).

Anyway, there is no easy and nice way to fix this, but I would like to see a refactoring of the logic for Helm 4.

@prune998
Copy link
Copy Markdown

are Helm maintainers dead ? How many follower does it take to get on the top of the stack to be reviewed ?
As far as I have tested, I think the example in the doc would not work

@mattfarina mattfarina removed this from the 3.9.0 milestone May 18, 2022
@taliastocks
Copy link
Copy Markdown

Your commitment is impressive, would love to see this merged :)

@dastrobu
Copy link
Copy Markdown
Contributor Author

joejulian added the Has One Approval label on Aug 1

What would be the next step?

@mattfarina mattfarina modified the milestones: 3.14.0, 3.15.0 Mar 13, 2024
@mattfarina mattfarina modified the milestones: 3.15.0, 3.16.0 Jun 12, 2024
@scottrigby scottrigby modified the milestones: 3.16.0, 3.17.0 Sep 11, 2024
@scottrigby scottrigby modified the milestones: 3.17.0, 3.18.0 Jan 15, 2025
@scottrigby
Copy link
Copy Markdown
Member

joejulian added the Has One Approval label on Aug 1

What would be the next step?

Hi @dastrobu are you able to resolve the conflicts in this PR so we can get this merged? I also pinged you in k8s slack #helm-dev channel here. Thanks!

…ltiply aliased dependencies

Dependencies keep a reference on their parent chart, which breaks if a chart reference is shared among multiple aliases.
By copying the dependencies, parent information can be set correctly to render the templates as expected later on.

Note that this change will make ChartFullPath return a different path for sub-subcharts. It will contain the alias names instead of the path to the chart files which makes it consistent with paths to templates on the subchart level.

Closes helm#9150

Signed-off-by: Daniel Strobusch <1847260+dastrobu@users.noreply.github.com>
@dastrobu dastrobu force-pushed the copy-dependencies-on-aliasing branch 2 times, most recently from 7342072 to 26d73c5 Compare April 23, 2025 09:26
imported values are stored in dependency objects, which breaks if a chart dependency is shared among multiple aliases.
By copying the dependency objects in the metadata values can be imported correctly.

Supersedes helm#10174

Signed-off-by: Daniel Strobusch <1847260+dastrobu@users.noreply.github.com>
@dastrobu dastrobu force-pushed the copy-dependencies-on-aliasing branch from 26d73c5 to b183ecc Compare April 23, 2025 09:32
@dastrobu
Copy link
Copy Markdown
Contributor Author

@scottrigby thanks for coming back to this. I rebased and updated the PR and resolved the issues. It should be ready for review now.

Copy link
Copy Markdown
Member

@scottrigby scottrigby left a comment

Choose a reason for hiding this comment

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

@dastrobu thanks for your contribution and persistence.
manually tested, has unit tests, and code review LGTM 👍

@scottrigby scottrigby removed the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Apr 23, 2025
@scottrigby scottrigby removed this from the 3.18.0 milestone Apr 23, 2025
@scottrigby scottrigby added the Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR label Apr 23, 2025
@scottrigby
Copy link
Copy Markdown
Member

Removed 3.18.0 milestone, because the main branch is now for Helm 4.

@dastrobu are you able to make a v3 backport PR with dev-v3 as the base branch? That PR will be assigned the appropriate milestone. See Maintaining Helm 3 section of the Helm 4 Development Process HIP for more info on this.

@scottrigby scottrigby changed the title copy dependencies on aliasing to avoid sharing chart references on mu… fix: copy dependencies on aliasing to avoid sharing chart references on multiply aliased dependencies Apr 23, 2025
@scottrigby scottrigby merged commit a911aa2 into helm:main Apr 23, 2025
5 checks passed
@dastrobu
Copy link
Copy Markdown
Contributor Author

@scottrigby thanks for the explanation, I did miss that helm 4 is already under development. Find the back port for helm 3 in #30802.

@pepesenaris
Copy link
Copy Markdown

Thanks everyone... We've been tracking this PR for 2 years. Great see it merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sub-sub-charts of aliased sub-charts not evaluated correctly