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

Ensure file sync works in multi-namespace environments #5464

Conversation

omninonsense
Copy link

Fixes: #4246

Description
Some kubernetes contexts set a default namespace. This breaks the file sync feature in a way that it prevented files being synced to any other namespace (Helm was probably working, but the heuristic didn't work for deploy.kustomize and deploy.kubectl deployment methods).

I am not sure if this causes some unexpected behaviour. The tests seem happy with this, so I'm somewhat confident nothing broke. I've only added the "empty" namespace when no --namespace is passed (ie the default value is "").

I'm not fully convinced the heuristic of parsing kubeconfig to get the default namespace is needed at all, though. Everything seems content with just "". So, I'm happy to remove the heuristic altogether, but since I'm not familiar with why it was added, I didn't want to do it prematurely.

@omninonsense omninonsense requested a review from a team as a code owner February 26, 2021 10:45
@google-cla google-cla bot added the cla: yes label Feb 26, 2021
@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #5464 (5bf0323) into master (90829a6) will decrease coverage by 0.38%.
The diff coverage is 60.28%.

❗ Current head 5bf0323 differs from pull request most recent head 03c6613. Consider uploading reports for the commit 03c6613 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5464      +/-   ##
==========================================
- Coverage   71.45%   71.07%   -0.39%     
==========================================
  Files         397      402       +5     
  Lines       14569    15055     +486     
==========================================
+ Hits        10411    10700     +289     
- Misses       3388     3563     +175     
- Partials      770      792      +22     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/deploy.go 56.52% <0.00%> (ø)
cmd/skaffold/app/cmd/diagnose.go 33.33% <0.00%> (-1.45%) ⬇️
cmd/skaffold/app/cmd/test.go 46.66% <0.00%> (ø)
pkg/skaffold/build/build.go 85.71% <ø> (ø)
pkg/skaffold/build/builder_mux.go 34.37% <ø> (ø)
pkg/skaffold/build/cache/lookup.go 80.00% <ø> (ø)
pkg/skaffold/build/cache/retrieve.go 65.62% <ø> (ø)
pkg/skaffold/build/cache/types.go 100.00% <ø> (ø)
pkg/skaffold/build/scheduler.go 94.33% <ø> (ø)
pkg/skaffold/config/options.go 100.00% <ø> (ø)
... and 74 more

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 90829a6...03c6613. Read the comment docs.

@omninonsense
Copy link
Author

I'm not sure if I need to do something about the "kokoro" thing. 👀

@omninonsense omninonsense changed the title fix: ensure file sync works in multi-ns environments Ensure file sync works in multi-namespace environments Mar 1, 2021
@MarlonGamez
Copy link
Contributor

hey @omninonsense , thanks for opening this, and sorry for the delayed response! It looks good to me, however I'm asking the other skaffold team members to take a look as well as I'm not completely sure if there are potential issues that could come from this. I'll try to have an update soon :)

@@ -38,11 +38,13 @@ func GetAllPodNamespaces(configNamespace string, pipelines []latest.Pipeline) ([
return nil, fmt.Errorf("getting k8s configuration: %w", err)
}

// The empty string is here to ensure that the File Sync feature
// works with multi-namespace environments
nsMap[""] = true
Copy link
Contributor

Choose a reason for hiding this comment

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

the reason why we we are against "" in nsMap is because not everyone has permissions to fetch pods and objects in all namespaces.
With empty namespace, k8s api will try to fetch pods, monitors etc in all namespaces.
To avoid getting a permission issue, we only add "" when no namespace is present.

Copy link
Author

@omninonsense omninonsense Mar 9, 2021

Choose a reason for hiding this comment

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

Ah right, I see. My assumption was that skaffold is only used with local clusters (minikube and similar), but now your comment implies people use it with shared clusters too. So, in that case I see how this would cause problems.

This is mostly an issue for kustomize and kubectl deployments, since they're simply "glide-through" skaffold without any processing. (Edit: assuming I remember the code correctly).

Could I instead peek at .metadata.namespace of the kustomize-compiled resources? I know could be made possible, but I'm not sure if that's desirable? In that case it would work in a similar fashion to the Helm namespace heuristic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking more into this, we provide an UpdateNamespace method which updates the namespaces with deployed resources.

func (rc *RunContext) UpdateNamespaces(ns []string) {

I submitted a PR recently where PodWatcher.Start() uses updated namespace.
I am wondering if that fixed this issue.
#5487

Can you verify this on the latest version of skaffold?

@omninonsense omninonsense marked this pull request as draft March 12, 2021 23:28
@nkubala
Copy link
Contributor

nkubala commented Apr 28, 2021

@omninonsense this PR has gotten stale, but I believe this issue may have been fixed through #5487. going to close this out for now, but will reopen if we get reports that the issue still exists and we can discuss alternative approaches for inferring the namespace.

@nkubala nkubala closed this Apr 28, 2021
@omninonsense
Copy link
Author

omninonsense commented Apr 29, 2021

Hi! @nkubala!

The workaround mentioned in #4246 (comment) works, so this wasn't a priority for us at the company any longer.And... I'll be honest: I forgot about this PR. Sorry about that! 😅

I realise creating a repro of this is a chore, so I'll check if #5487 fixes it for us (at a glance it seems like it should).

@omninonsense omninonsense deleted the nino--issue-4246 branch April 29, 2021 12:22
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.

Skipping deploy due to sync error: copying files: didn't sync any files
4 participants