Skip to content

Ignore "" namespaces in collectHelmReleasesNamespaces #4568

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

Conversation

sarmad-abualkaz
Copy link
Contributor

@sarmad-abualkaz sarmad-abualkaz commented Jul 25, 2020

Fixes: #3311
Related: N/A
Merge before/after: N/A

Description

This fixes an issue specific to helm deployments , when the skaffold enduser is running with RBAC restriction scoped to a single namespace.

Behaviour on v1.12.1 - pod watcher logs this error starting logger: initializing pod watcher for "": unknown (get pods) and exits.

This also seems to, inadvertently 😄 , fix a new issue (potentially introduced as part of the fixes in this PR - #4460) whereby user with similar restrictions, single-ns scoped permissions, cannot list helm-released deployments anymore despite having SKAFFOLD_NAMESPACE env-variable or adding --namepsace/-n flag. This other issue logs the error below before exiting:

exiting dev mode because first deploy failed: could not fetch deployments: could not fetch deployments: deployments.apps is forbidden: User "<my-user>" cannot list resource "deployments" in API group "apps" at the cluster scope

The only work around for both these issue is to hardcode a namespace field in skaffold.yaml under deploy.helm.releases.

User facing changes (remove if N/A)

Before:
Running skaffold dev with a user permitted to only a single namespace would run into this error before exiting:
starting logger: initializing pod watcher for "": unknown (get pods).

The cause for this error appears related to the runner context that merges all namespaces into a single array (user RBAC, -n/--namespace SKAFFOLD_NAMESPACE and every helmRelease namespace specified). When the namespace field isn't included under deploy.helm.releases, this seems to add a blank (or "") namespace in the list of namespaces which may require cluster-scope permissions.

There's a work-around for this before this fix - adding the namespace under each helm-release will make this work:

    deploy:
      helm:
        releases:
        - name: <release-name>
          namespace: <release-namespace>

However we have users sharing the same repo/skaffold.yaml and attempt to deploy each to their own namespace, therefore hardcoding the namespace isn't ideal.

After:
Pod watcher and deployment status works without adding the namespace field under deploy.helm.releases. I've tested also using admin user (with cluster-wide rbac) and the behaviour works the same. Also tested multiple helmReleases with different namespaces, seems to work as well with this change.

Question to the contributors on this project: was there an intended reason to have this behaviour? (i.e. having an empty ns in namespaces list) The reason I ask is as you can see I had to change the test as well and remove "" from expected output.

Let me know.

Follow-up Work (remove if N/A)

@codecov
Copy link

codecov bot commented Jul 25, 2020

Codecov Report

Merging #4568 into master will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4568      +/-   ##
==========================================
+ Coverage   72.61%   72.69%   +0.08%     
==========================================
  Files         335      335              
  Lines       12963    12972       +9     
==========================================
+ Hits         9413     9430      +17     
+ Misses       2957     2949       -8     
  Partials      593      593              
Impacted Files Coverage Δ
pkg/skaffold/runner/util/util.go 92.59% <100.00%> (+0.28%) ⬆️
pkg/skaffold/docker/remote.go 53.44% <0.00%> (+23.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33b1d10...11b47a4. Read the comment docs.

@sarmad-abualkaz sarmad-abualkaz changed the title Fix/collect helm releases namespaces Ignore "" namespaces in collectHelmReleasesNamespaces Jul 26, 2020
@dgageot dgageot added the kokoro:run runs the kokoro jobs on a PR label Jul 27, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jul 27, 2020
@dgageot dgageot merged commit 4df4a4f into GoogleContainerTools:master Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skaffold (helm-deployment) should work within namespace RBAC restrictions
4 participants