Skip to content

fix: use release namespace in render when specified#8259

Merged
aaron-prindle merged 4 commits into
mainfrom
issue-8185
Jan 11, 2023
Merged

fix: use release namespace in render when specified#8259
aaron-prindle merged 4 commits into
mainfrom
issue-8185

Conversation

@renzodavid9

@renzodavid9 renzodavid9 commented Dec 19, 2022

Copy link
Copy Markdown
Contributor

Fixes: #8185

Description
This PR changes the method called to get the namespace that is used during rendering, from GetNamespace to GetKubeNamespace; in skaffold v1 is read from this last one.

Context:

  • GetNamespace returns the namespace set in the detected cluster (even if it is the "default" namespace) when no namespace is passed with the --namespace flag and no namespace is set in a Kubectl deployer.
  • GetKubeNamespace returns the namespace set with the --namespace flag

Changing the logic to use GetKubeNamespace instead of GetNamespace (as it was in v1) makes the helm renderer to use the value set in the release when no value is detected in the --namespace flag, and don't care about what value is set as default in the active cluster.

Difference between manifests.helm.releases.namespace and deploy.helm.releases.namespace

Both values do not interfere between each other. In the followin scenario:

apiVersion: skaffold/v4beta1
kind: Config
...
manifests:
  helm:
    releases:
    - name: skaffold-helm
      chartPath: charts
      namespace: helm-test-1
      setValues:
        image: skaffold-helm

deploy:
  helm:
    releases:
    - name: skaffold-helm
      chartPath: charts
      namespace: helm-test-2
      setValues:
        image: skaffold-helm

The output from skaffold render will produce two different sets of manifests:

  • one for the release defined in the manifests.helm.releases config with namespace: helm-test-1 namespace set
  • other for the release defined in deploy.helm.releases.namespace config with namespace: helm-test-2 namespace set

Behind the scene, skaffold is creating two different renderers: one for the manifests and other for the deploy, each with its corresponding configuration

@codecov

codecov Bot commented Dec 19, 2022

Copy link
Copy Markdown

Codecov Report

Merging #8259 (6dd4999) into main (290280e) will decrease coverage by 4.38%.
The diff coverage is 54.68%.

@@            Coverage Diff             @@
##             main    #8259      +/-   ##
==========================================
- Coverage   70.48%   66.09%   -4.39%     
==========================================
  Files         515      601      +86     
  Lines       23150    29507    +6357     
==========================================
+ Hits        16317    19503    +3186     
- Misses       5776     8542    +2766     
- Partials     1057     1462     +405     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/completion.go 13.04% <0.00%> (-1.25%) ⬇️
cmd/skaffold/app/cmd/config/list.go 65.21% <ø> (ø)
cmd/skaffold/app/cmd/config/set.go 88.72% <ø> (ø)
cmd/skaffold/app/cmd/config/util.go 54.28% <ø> (ø)
cmd/skaffold/app/cmd/credits.go 100.00% <ø> (ø)
cmd/skaffold/app/cmd/credits/export.go 0.00% <0.00%> (ø)
cmd/skaffold/app/cmd/deploy.go 40.90% <0.00%> (-12.94%) ⬇️
cmd/skaffold/app/cmd/generate_pipeline.go 60.00% <ø> (ø)
cmd/skaffold/app/cmd/inspect_modules.go 65.00% <ø> (ø)
cmd/skaffold/app/cmd/inspect_profiles.go 66.66% <ø> (ø)
... and 405 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@renzodavid9 renzodavid9 marked this pull request as ready for review December 21, 2022 15:07
@@ -0,0 +1 @@
{} No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should you delete this file?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1, it seems builds.out.json isn't used in the integration test -> might make sense to delete

@renzodavid9 renzodavid9 Jan 3, 2023

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.

Done! I changed the test logic to add the --build-artifacts=builds.out.json flag conditionally and not for all the cases, and removed the builds.out.json file that I added for the new case

@aaron-prindle

aaron-prindle commented Dec 29, 2022

Copy link
Copy Markdown
Contributor

Can you add some more context in the PR description on GetNamespace vs GetKubeNamespace as well as what namespace config values are looked at currently when rendering helm templates (perhaps a tree of the priority?) as we have 2 locations that releases.namespaces can be set:

  • in manifests.helm.releases.namespace
  • in deploy.helm.releases.namespace

The original issue mentioned that deploy.* config wasn't respected in a render command. If someone sets both values, what is the resultant namespace currently? (which one has priority?)

@aaron-prindle aaron-prindle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@aaron-prindle aaron-prindle merged commit 8b82382 into main Jan 11, 2023
@aaron-prindle aaron-prindle deleted the issue-8185 branch January 11, 2023 00:43
aaron-prindle pushed a commit to aaron-prindle/skaffold that referenced this pull request Mar 1, 2023
…ools#8259)

* fix: use release namespace in render when specified

* fix: add new method to MockConfig to comply with render.Config interface

* test: integration test to validate namespace is replace in helm template

* fix: address PR comments, delete build.out.json

(cherry picked from commit 8b82382)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants