8000 bugfix: unexpected behavior when using "dependencies.condition" by wujunwei · Pull Request #11396 · helm/helm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

bugfix: unexpected behavior when using "dependencies.condition" #11396

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wujunwei
Copy link
Contributor
@wujunwei wujunwei commented Sep 29, 2022

Signed-off-by: wujunwei wjw3323@live.com

What this PR does / why we need it:
fixes #11338
Special notes for your reviewer:

If applicable:

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

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 29, 2022
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from d108c78 to 623f4c6 Compare October 6, 2022 03:37
@joejulian joejulian modified the milestones: 3.11.0, 3.10.2 Oct 12, 2022
@joejulian joejulian added the bug Categorizes issue or PR as related to a bug. label Oct 12, 2022
for _, r := range c.Metadata.Dependencies {
if !r.Enabled {
// remove disabled chart
rm[r.Name] = struct{}{}
rm[r.Name] = append(rm[r.Name], r.Version)
Copy link
@kszpakowski kszpakowski Oct 28, 2022

Choose a reason for hiding this comment

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

Hi @wujunwei, would you please take into consideration using chart alias from the dependencies as well? When I have a helm chart with two dependencies for chart X, version 0.0.1, but with different aliases, it will still break conditionals.

Chart.yaml

apiVersion: v2
name: my-app-configuration
version: 0.0.1
dependencies:
- name: my-service-chart
   alias: firstService
   version: 0.3.0
   repository: "@stable"
   condition: firstService.enabled
  
- name: my-service-chart
   alias: secondService
   version: 0.3.0
   repository: "@stable"
   condition: secondService.enabled
  

Copy link
Contributor Author
@wujunwei wujunwei Oct 28, 2022

Choose a reason for hiding this comment

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

In fact, I have considered this situation.
As the code below shows, when deal with package's name ,it have considered the alias name.

out.Metadata = &md
if dep.Alias != "" {
md.Name = dep.Alias
}
return &out
}
return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kszpakowski I added some test cases To prove my point. PTAL :)

Copy link
@kszpakowski kszpakowski Oct 28, 2022

Choose a reason for hiding this comment

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

Thanks, your change looks good to me. Unfortunately it looks like I'm facing another issue and it still does not work on your version. Basically, I have a chart with two dependencies to another chart, which then have its own conditional dependencies disabled by default in its values.yaml. When I render it, all resources are created ignoring conditions. In another words, condition in dependency of my chart dependencies is being ignored. I'll create example repo and open new issue.

Choose a reason for hiding this comment

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

I've just found the solution in the docs: "Tags and conditions values must be set in the top parent's values." :)

Copy link
@SaeidAshian SaeidAshian Nov 21, 2022

Choose a reason for hiding this comment

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

top parent's values

Could you send an example

Choose a reason for hiding this comment

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

It looks like I was too optimistic. Today I had more time to investigate the issue and it looks like there is some bug after all. I have charts structure like this:

ChartA

ChartB
dependencies:

  • name: ChartA
    alias: chartA
    condition: chartA.enabled

ChartC
dependencies:

  • name: ChartB
    alias: firstApp
  • name: ChartB
    alias: secondApp

Top most chart (ChartC) has two dependencies to the same lib chart (ChartB), same version, different aliases.
ChartB has single dependency (which is conditional) to ChartA with an alias.

I do not know go good enough to propose a fix, but it looks like, the first time getAliasDependency is called and it modifies dep name to the alias (md.Name = dep.Alias). When it is called again, dep name is already set to an alias, and it doesn't match c.Name (Line 98) - the metadata name is not being changed to an alias. Then there is a mismatch between rm content and it cannot get the right value from rm in line 173, so the disabled by condition dependency is being kept.

My temporary solution was to remove alias from dependency of chart B and now it works fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the first time getAliasDependency is called and it modifies dep name to the alias (md.Name = dep.Alias). When it is called again, dep name is already set to an alias, and it doesn't match c.Name (Line 98)

why does it not match c.Name? when called again, it's another dep.

the metadata name is not being changed to an alias. Then there is a mismatch between rm content and it cannot get the right value from rm in line 173

n.Metadata.Name in line 173 comes from c.Dependencies(0 which reset by line 147, it has already changed to alias from the code point of view.

Have you test it? could you provide a test case that can reproduct it ? thanks a lot !

Choose a reason for hiding this comment

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

I made this sample to reproduce the error: https://github.com/kszpakowski/helm-alias-condition-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.

I made this sample to reproduce the error: https://github.com/kszpakowski/helm-alias-condition-error

Thanks for this demo, It can be produced at the latest main branch
phenomenon : when I run helm template chartC output contained sa.yaml which is disabled at chartC's values.yaml .

> helm  template ./helm-alias-condition-error/chartC/
---
# Source: chartC/charts/firstApp/templates/ns.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: test
---
# Source: chartC/charts/secondApp/templates/ns.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: test
---
# Source: chartC/charts/secondApp/charts/chartA/templates/sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: test

After Looking into the code ,I found , It's cause by code below. it tried to copy a chart, but the medata.dependencies is a array of chart point,it will copy reference not truly struct. as a result they will share same address, when change the name of firstApp.chartA to firstApp.chartAalias secondApp.chartA will be set to secondApp.chartAalias at the same time.

out := *c
md := *c.Metadata
out.Metadata = &md
if dep.Alias != "" {
md.Name = dep.Alias
}
return &out

bug

It's a new bug(although the phenomenon is same as this issue), you can submit a new issue to trace it .

@wujunwei wujunwei force-pushed the fix-dependency-condition branch from 623f4c6 to a382ecb Compare October 28, 2022 15:47
@mattfarina mattfarina modified the milestones: 3.10.2, 3.10.3 Nov 10, 2022
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from a382ecb to 02df0c2 Compare December 1, 2022 02:56
@hickeyma hickeyma modified the milestones: 3.10.3, 3.11.0 Dec 14, 2022
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from 02df0c2 to d73100c Compare January 3, 2023 01:50
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from d73100c to 210a651 Compare January 13, 2023 09:05
@mattfarina mattfarina modified the milestones: 3.11.0, 3.12.0 Jan 18, 2023
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from 210a651 to b7596b7 Compare January 30, 2023 01:48
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from b7596b7 to 18e3050 Compare February 9, 2023 07:28
@wujunwei wujunwei force-pushed the fix-dependency-condition branch 2 times, most recently from a265a65 to 30f422f Compare March 31, 2023 06:04
@joejulian joejulian modified the milestones: 3.12.0, 3.13.0 May 5, 2023
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from 30f422f to 62fb87e Compare June 15, 2023 03:52
@mattfarina mattfarina modified the milestones: 3.13.0, 3.14.0 Sep 25, 2023
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from 62fb87e to 219857c Compare December 15, 2023 08:42
@wujunwei
Copy link
Contributor Author
wujunwei commented Dec 15, 2023

@mattfarina @joejulian could anyone take a look ? Another new user has encountered the same bug again!

#11338 (comment)

@mattfarina mattfarina removed this from the 3.14.0 milestone Mar 13, 2024
@mattfarina mattfarina added this to the 3.15.0 milestone 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, 3.17.1 Jan 15, 2025
@mattfarina mattfarina modified the milestones: 3.17.1, 3.17.2 Feb 12, 2025
@scottrigby scottrigby modified the milestones: 3.17.2, 3.17.3 Mar 13, 2025
adam.wu and others added 2 commits April 27, 2025 21:57
Signed-off-by: wujunwei <wjw3323@live.com>
Signed-off-by: adam.wu <adamwu@shein.com>

# Conflicts:
#	pkg/chart/v2/util/dependencies_test.go
Signed-off-by: wujunwei <wjw3323@live.com>
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from 219857c to 9514321 Compare April 27, 2025 14:01
Signed-off-by: wujunwei <wjw3323@live.com>
Signed-off-by: adam.wu <adamwu@shein.com>
@wujunwei wujunwei force-pushed the fix-dependency-condition branch from e7efaa4 to 7e5f575 Compare April 27, 2025 14:25
@mattfarina mattfarina modified the milestones: 3.17.3, 3.18.1 May 19, 2025
@mattfarina mattfarina modified the milestones: 3.18.1, 3.18.3 May 28, 2025
@mattfarina mattfarina modified the milestones: 3.18.3, 3.18.4 Jun 16, 2025
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. 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.

Unexpected behavior when using "dependencies.condition"
7 participants
0