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

Fix Helm Chart resource lookup key handling for objects in default namespace #2655

Merged
merged 4 commits into from
Dec 12, 2023

Conversation

rquitales
Copy link
Contributor

@rquitales rquitales commented Nov 7, 2023

Proposed changes

This pull request modifies the GetResource Go method for the Helm Chart resource. Previously, when a resource was deployed to the default namespace, the default namespace was always omitted from the resource lookup key. However, in cases where the namespace is explicitly defined in the Helm chart template, the default namespace was inadvertently excluded from the resource lookup key despite it being needed. This behavior in Helm is documented in the upstream issue: helm/helm#3553.

Changes Made:

  • Implemented a fallback mechanism to include the default namespace in the resource lookup key when necessary for the GetResource method.

Test Added:

  • Added a test (ChartGetResource) to verify the GetResource method for both types of Helm charts—those with the explicitly defined default namespace and those without.

Verification:

  • Verified that the modified GetResource method successfully handles scenarios where the namespace is explicitly defined in the Helm chart template.
  • Confirmed that the added test covers both types of Helm charts and fails when the fallback logic is reverted.

Related issues (optional)

Fixes: #2638

Copy link

github-actions bot commented Nov 7, 2023

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

Copy link

codecov bot commented Nov 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (66ea94d) 18.41% compared to head (d994349) 18.62%.
Report is 2 commits behind head on master.

❗ Current head d994349 differs from pull request most recent head ba90e35. Consider uploading reports for the commit ba90e35 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2655      +/-   ##
==========================================
+ Coverage   18.41%   18.62%   +0.20%     
==========================================
  Files          47       47              
  Lines        9589     9589              
==========================================
+ Hits         1766     1786      +20     
+ Misses       7724     7699      -25     
- Partials       99      104       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rquitales rquitales force-pushed the rquitales/fix-helm-chart-getresource branch 2 times, most recently from a479487 to d994349 Compare December 10, 2023 01:23
@rquitales rquitales force-pushed the rquitales/fix-helm-chart-getresource branch from d994349 to 4229cf4 Compare December 12, 2023 00:45
@rquitales rquitales changed the title Fix helm chart GetResource Fix Helm Chart resource lookup key handling for objects in default namespace Dec 12, 2023
@rquitales rquitales requested review from EronWright and a team December 12, 2023 00:58
@rquitales rquitales marked this pull request as ready for review December 12, 2023 01:01
// to searching for the resource by namespace and name. This occurs when the Helm template manifest explicitly
// sets the namespace field on the resource.
if namespace == "default" || namespace == "" {
return resources[fmt.Sprintf("%s::default/%s", gvk, name)]
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 fallback logic to also explicitly specify default namespace.

kind: Deployment
metadata:
name: {{ include "local-test-chart.fullname" . }}-new
namespace: {{ .Release.Namespace }} # This is what causes the difference when needing to specify a namespace or not during templating.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the helm template format that requires explicit specification of default in our resource lookup key.

@rquitales rquitales merged commit 037bde8 into master Dec 12, 2023
18 checks passed
@rquitales rquitales deleted the rquitales/fix-helm-chart-getresource branch December 12, 2023 17:10
rquitales added a commit that referenced this pull request Dec 15, 2023
…mespace (#2655)

This pull request modifies the `GetResource` Go method for the Helm
Chart resource. Previously, when a resource was deployed to the default
namespace, the `default` namespace was always omitted from the resource
lookup key. However, in cases where the namespace is explicitly defined
in the Helm chart template, the `default` namespace was inadvertently
excluded from the resource lookup key despite it being needed. This
behavior in Helm is documented in the upstream issue:
helm/helm#3553.

**Changes Made:**
- Implemented a fallback mechanism to include the `default` namespace in
the resource lookup key when necessary for the `GetResource` method.

**Test Added:**
- Added a test (`ChartGetResource`) to verify the `GetResource` method
for both types of Helm charts—those with the explicitly defined default
namespace and those without.

**Verification:**
- Verified that the modified `GetResource` method successfully handles
scenarios where the namespace is explicitly defined in the Helm chart
template.
- Confirmed that the added test covers both types of Helm charts and
fails when the fallback logic is reverted.

Fixes: #2638
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.

Installing Helm v3 Chart resource causes errors
2 participants