fix: prevent long startup time#8376
Conversation
Caches RunContext's kubernetes namespace so subsequent calls do not invoke kubectl.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Hi @nickdapper , thanks for your contribution. skaffold/pkg/skaffold/kubectl/version.go Lines 96 to 116 in 88e1c17
If you check the commit history around this part of code, the initial implementation was just simply return namespace passed from command line, using this method was fine at that time, but when we migrated to v2, there was some knowledge gap, that caused GetNamespace() discrepancy in a lot of places, the code added was meant to fix stuff, agree we should revisit that. At this moment, I think we can cache the result to fix the start slow issue. |
|
Thanks for the fast review @ericzzzzzzz ! I updated to use the same pattern. Let me know how this looks |
|
@ericzzzzzzz I just tested this and while the command doesn't take two minutes however there is still a slight delay around 20 seconds before the first log. It's still calling |
Codecov Report
@@ Coverage Diff @@
## main #8376 +/- ##
==========================================
- Coverage 70.48% 65.91% -4.57%
==========================================
Files 515 605 +90
Lines 23150 29834 +6684
==========================================
+ Hits 16317 19665 +3348
- Misses 5776 8697 +2921
- Partials 1057 1472 +415
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
@nickdapper yeah.. there is another place calls skaffold/pkg/skaffold/deploy/kubectl/kubectl.go Lines 87 to 89 in bcb5945 We can create a syncstore in this package skaffold/pkg/skaffold/util/cmd.go Lines 1 to 106 in 88e1c17 syncstore implementation is here skaffold/pkg/skaffold/util/store.go Lines 1 to 121 in aa0bf34 And create a method like runOutOnce with wraps the runout command and use command args as key for caching purpose, something like func RunCmdOutOnce(ctx context.Context, cmd *exec.Cmd) ([]byte, error) {
return store.Exec(cmd.String(), func() ([]byte, error) {
return RunCmdOut(ctx, cmd)
})
}and call this method when creating kubectl deployer |
|
@ericzzzzzzz Excellent suggestion! This results in just a single call now. 🚀 Let me know if there are other changes needed. |
|
Will commits be squashed on merge? Not seeing that. |
It will |
|
Hi @nickdapper , we need to fix the test to make the ci build succeed. :) |
Going to work on this today. Thanks! |
|
@ericzzzzzzz Is there a way to force a re-run of the checks? |
|
@nickdapper Maintainers can re-run specific parts of the Github Actions but I don't think the PR contributor necessarily can. I think the easiest way to re-run the checks would be to re-push your commit and that will kick the CI jobs off. Also you can ping the thread here and we can kick things off again as needed (specific Github Actions, etc.) The unit tests that are currently failing can be run locally via |
|
Ok all tests are passing now locally |
|
it's running now. |
Caches RunContext's kubernetes namespace so subsequent calls do not invoke kubectl.
Fixes: #8367
Description
Use my example project found here: https://github.com/nickdapper/skaffold-slow
This caches the output of the
kubectl config viewcommand which only fetches the namespace.Please verify the location of returning the cached value is correct.
Follow-up Work (remove if N/A)
This might not be the best approach - Why is
GetNamespace()called so many times?