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

Change all Start() to Start([]namespaces) to consume updated namespaces where resources get deployed. #5487

Merged
merged 4 commits into from
Mar 16, 2021

Conversation

tejal29
Copy link
Contributor

@tejal29 tejal29 commented Mar 4, 2021

Fixes #5480

Change all below Objects

  1. pod watcher
  2. logger
  3. container Manager

Problem:

  1. Watchers, Loggers are not loggings or watching resources configured in the k8 manifest config namespace if it is different than --namespace skaffold command line flag.

Reason:
Skaffold is unaware of namespaces in the k8 manifests until after we deploy. During deploy, we read manifests, and collect all namespaces.
In #2640, we updated Deploy to return a list of namespaces so all watchers, deployment fetcher can query namespaces where resources get deployed and update the runner.runCtx.Namespaces. This was used in deploy.StatusCheck however not in Logger, containerManager etc.
Associated bug #2495

In this approach, we are passing the namespace after deploy.Deploy to all Start methods to watch pods, containers in deployed namespaces.

  1. change the signature of logger.Start and container_manager.Start and use updated namespace in runner.runCtx.Namespaces.

Pros:

  1. The signature makes it clear we need to pass namespace
type PodWatcher interface {
	Register(receiver chan<- PodEvent)
-	Start() (func(), error)
+	Start(ns []string) (func(), error)
}
  1. Remove namespaces from constructors for all above objects.

Alternate method

  1. capturing the deploy time to pass on to the logger.

Pros:

  1. small change

Cons:

  1. Developers have to remember to capture deploy time before deploy is called and start logger after.

@google-cla google-cla bot added the cla: yes label Mar 4, 2021
@pull-request-size pull-request-size bot added size/S and removed size/M labels Mar 4, 2021
@tejal29 tejal29 changed the title Add namespace to all Start() interfaces Create logger and container manager interfaces after deploy.Deploy Mar 4, 2021
@tejal29 tejal29 marked this pull request as ready for review March 4, 2021 00:49
@tejal29 tejal29 requested a review from a team as a code owner March 4, 2021 00:49
@codecov
Copy link

codecov bot commented Mar 4, 2021

Codecov Report

Merging #5487 (03d1f8c) into master (31cf2f1) will decrease coverage by 0.19%.
The diff coverage is 42.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5487      +/-   ##
==========================================
- Coverage   71.46%   71.26%   -0.20%     
==========================================
  Files         397      400       +3     
  Lines       14577    14971     +394     
==========================================
+ Hits        10417    10669     +252     
- Misses       3389     3513     +124     
- Partials      771      789      +18     
Impacted Files Coverage Δ
...skaffold/kubernetes/debugging/container_manager.go 50.00% <0.00%> (ø)
...affold/kubernetes/portforward/forwarder_manager.go 26.66% <0.00%> (ø)
pkg/skaffold/kubernetes/watcher.go 84.37% <ø> (-0.48%) ⬇️
pkg/skaffold/runner/build_deploy.go 69.23% <ø> (+0.34%) ⬆️
pkg/skaffold/runner/debugging.go 66.66% <0.00%> (ø)
pkg/skaffold/runner/dev.go 71.52% <0.00%> (ø)
pkg/skaffold/runner/logger.go 40.00% <0.00%> (ø)
pkg/skaffold/kubernetes/log.go 47.41% <50.00%> (ø)
...g/skaffold/kubernetes/portforward/pod_forwarder.go 82.00% <100.00%> (ø)
...ffold/kubernetes/portforward/resource_forwarder.go 85.71% <100.00%> (-0.29%) ⬇️
... and 35 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 31cf2f1...03d1f8c. Read the comment docs.

PriyaModali
PriyaModali previously approved these changes Mar 4, 2021
@PriyaModali
Copy link
Contributor

LGTM.

Copy link
Member

@briandealwis briandealwis left a comment

Choose a reason for hiding this comment

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

I prefer option 2 and enhance PodWatcher.Start(namespaces). It would mean that when namespaces change (e.g., on a redeploy), we'd just .Stop() and then .Start(newNamespaces).

pkg/skaffold/runner/build_deploy.go Outdated Show resolved Hide resolved
@tejal29 tejal29 changed the title Create logger and container manager interfaces after deploy.Deploy Change all Start() to Start([]namespaces) to consume updated namespaces where resources get deployed. Mar 10, 2021
@tejal29 tejal29 dismissed PriyaModali’s stale review March 10, 2021 23:15

another approach.

@tejal29
Copy link
Contributor Author

tejal29 commented Mar 11, 2021

Testing notes

  1. add a namespace in any sample project
--- a/examples/getting-started/k8s-pod.yaml
+++ b/examples/getting-started/k8s-pod.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
 kind: Pod
 metadata:
   name: getting-started
+  namespace: test
 spec:
   containers:
   - name: getting-started
(END)
  1. run skaffold dev
 getting-started git:(fix_log_agg) ✗ ../../out/skaffold dev 
Listing files to watch...
 - skaffold-example
Generating tags...
 - skaffold-example -> skaffold-example:v1.20.0-31-g6b6ca7806-dirty
....
Deployments stabilized in 48.643116ms
Press Ctrl+C to exit
Watching for changes...
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!
[getting-started] Hello world!

VS On released skaffold version ,

➜  getting-started git:(fix_log_agg) ✗ skaffold dev 
Listing files to watch...
 - skaffold-example
Generating tags...
 - skaffold-example -> skaffold-example:v1.20.0-31-g6b6ca7806-dirty
Checking cache...
 - skaffold-example: Found Locally
Tags used in deployment:
 - skaffold-example -> skaffold-example:489f1f895b4d81eb23021e673a305a87a3b6ab2e24679771c6c8255774ba0e28
Starting deploy...
 - pod/getting-started created
Waiting for deployments to stabilize...
Deployments stabilized in 19.952347ms
Press Ctrl+C to exit
Watching for changes...
^CCleaning up...
 - pod "getting-started" deleted

@tejal29 tejal29 added this to the v1.21.0 milestone Mar 12, 2021
logrus.Warnln("Error starting port forwarding:", err)
}

// Start printing the logs after deploy is finished
if err := logger.Start(ctx); err != nil {
if err := logger.Start(ctx, r.runCtx.Namespaces); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

GetNamespaces()

(we should un-export these fields… someday)

@tejal29
Copy link
Contributor Author

tejal29 commented Mar 16, 2021

the CI failure is due to "Docker too many request"

@tejal29 tejal29 merged commit 116201a into GoogleContainerTools:master Mar 16, 2021
@tejal29 tejal29 deleted the fix_log_agg branch July 21, 2021 17:38
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.

Logs not tailing from spring boot & buildpack
3 participants