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

Remove global single instance of skaffoldOpts in skaffold error package and use runContext Config #5537

Merged
merged 6 commits into from
Apr 15, 2021

Conversation

tejal29
Copy link
Contributor

@tejal29 tejal29 commented Mar 11, 2021

Review Order:

  1. Refactoring events to use Config interface for init #5532 - event refactor to use Config instead of variables from config

When fixing #5485 , @briandealwis suggested removing the global skaffoldOpts in error package here

In this PR

  1. Move initErrors, buildErrors and deployErrors to individual packages.
  2. Create Problem and allow packages to register problems. The suggestions, will switch the interface to respective Config and suggest suggestions.
- type suggestionFunc func(runCtx *runcontext.RunContext) []*proto.Suggestion
+ type suggestionFunc func(cfg interface{}) []*proto.Suggestion
  1. Change definition of Suggestions function to run on any interface and remove singleton use of runCtx or skaffoldOpt as mentioned by @briandealwis in his review feedback.
    So the following methods have changed
-func ShowAIError(err error) error {
+ func ShowAIError(cfg interface{}, err error) error {

and

-func ActionableErr(phase Phase, err error) *proto.ActionableErr {
+func ActionableErr(cfg interface{}, phase Phase, err error) *proto.ActionableErr {
  1. ShowAIError is now called in cmd.withRunner flow where runCtx is available and handleWellknownErrors is deleted.
    creatNewRunner also returns a RunContext to pass to error handling.
- func createNewRunner(out io.Writer, opts config.SkaffoldOptions) 
-    (runner.Runner, []*latest.SkaffoldConfig, error) {
+func createNewRunner(out io.Writer, opts config.SkaffoldOptions) 
   (runner.Runner, *runcontext.RunContext, []*latest.SkaffoldConfig, error) {
  1. ActionableErr was called in event packages which used global singelton skaffoldOpts. We know pass runCtx during event.InitializeState
-func InitializeState(c []latest.Pipeline, kc string, autoBuild, autoDeploy, autoSync bool) {
+func InitializeState(cfg Config)

which is stored in eventHandler

type eventHandler struct {
	eventLog []proto.LogEntry
	logLock  sync.Mutex
+	cfg       Config
	state     proto.State
	stateLock sync.Mutex
	eventChan chan firedEvent
	listeners []*listener
}

Mutliple goroutines accessing handler.cfg should not cause a data race because this value is not only written once in InitializeState.

See https://notes.shichao.io/gopl/ch9/#avoid-writing-the-variable

  1. The calls to ActionableErr now use this to pass the event.Config.

@codecov
Copy link

codecov bot commented Mar 11, 2021

Codecov Report

Merging #5537 (4f16b18) into master (f280aa8) will increase coverage by 0.14%.
The diff coverage is 84.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5537      +/-   ##
==========================================
+ Coverage   70.54%   70.69%   +0.14%     
==========================================
  Files         410      411       +1     
  Lines       15640    15863     +223     
==========================================
+ Hits        11034    11214     +180     
- Misses       3793     3823      +30     
- Partials      813      826      +13     
Impacted Files Coverage Δ
pkg/skaffold/build/builder_mux.go 44.73% <ø> (+10.36%) ⬆️
pkg/skaffold/errors/problem.go 47.61% <47.61%> (ø)
cmd/skaffold/app/cmd/cmd.go 63.58% <66.66%> (+0.28%) ⬆️
cmd/skaffold/app/cmd/commands.go 80.00% <66.66%> (-1.25%) ⬇️
pkg/skaffold/deploy/deploy_problems.go 73.07% <73.07%> (ø)
pkg/skaffold/docker/parse.go 86.19% <85.18%> (+1.86%) ⬆️
pkg/skaffold/event/event.go 91.12% <87.50%> (+0.01%) ⬆️
pkg/skaffold/errors/errors.go 90.32% <90.62%> (-2.41%) ⬇️
pkg/skaffold/build/build_problems.go 94.82% <94.82%> (ø)
cmd/skaffold/app/cmd/runner.go 60.00% <100.00%> (-0.72%) ⬇️
... and 28 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 f280aa8...4f16b18. Read the comment docs.

@tejal29 tejal29 changed the base branch from master to refactor_event_init March 11, 2021 21:29
@tejal29 tejal29 changed the base branch from refactor_event_init to master March 11, 2021 21:54
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.

The commandcmd is odd?

func suggestDeployFailedAction(runCtx runcontext.RunContext) []*proto.Suggestion {
if isMinikube(runCtx.KubeContext) {
func suggestDeployFailedAction(cfg Config) []*proto.Suggestion {
if isMinikube(cfg.GetKubeContext()) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with keeping this for now, but IMHO the config should have the cluster, which we can query if it's local, or specifically minikube or kind, etc.

And then we can have the clusters provide a status-check command. The generic one is kubectl describe nodes and kubectl get events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think config.ClusterType() could be a good addition so we don't have to repeat the logic many times.

Copy link
Member

Choose a reason for hiding this comment

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

+1 and we can cache the result too.

if err != nil {
return err
}

err = action(runner, config)

return alwaysSucceedWhenCancelled(ctx, err)
return alwaysSucceedWhenCancelled(ctx, runCtx, err)
Copy link
Member

Choose a reason for hiding this comment

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

It's odd, but I don't see this change here?

@tejal29
Copy link
Contributor Author

tejal29 commented Mar 11, 2021

The commandcmd is odd?

yeah maybe a search replace did. i just noticed it.

@tejal29 tejal29 force-pushed the only_runCtx branch 2 times, most recently from 2b47821 to 7847eb2 Compare March 11, 2021 23:51
@tejal29 tejal29 added this to the v1.21.0 milestone Mar 12, 2021
func suggestDeployFailedAction(runCtx runcontext.RunContext) []*proto.Suggestion {
if isMinikube(runCtx.KubeContext) {
func suggestDeployFailedAction(cfg Config) []*proto.Suggestion {
if isMinikube(cfg.GetKubeContext()) {
Copy link
Member

Choose a reason for hiding this comment

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

+1 and we can cache the result too.

@tejal29
Copy link
Contributor Author

tejal29 commented Mar 15, 2021

@briandealwis hold off until i try again removing the error config bleeding into every packages.

@tejal29 tejal29 changed the title Remove global single instance of skaffoldOpts in skaffold error package and use runContext Config [Paused] Remove global single instance of skaffoldOpts in skaffold error package and use runContext Config Mar 16, 2021
@tejal29 tejal29 modified the milestones: v1.21.0, v1.22.0 Mar 18, 2021
@tejal29 tejal29 changed the title [Paused] Remove global single instance of skaffoldOpts in skaffold error package and use runContext Config Remove global single instance of skaffoldOpts in skaffold error package and use runContext Config Apr 7, 2021
@tejal29 tejal29 force-pushed the only_runCtx branch 2 times, most recently from f07f367 to 9290bf3 Compare April 7, 2021 04:27
@tejal29
Copy link
Contributor Author

tejal29 commented Apr 7, 2021

@briandealwis This is ready for review again!

@tejal29 tejal29 force-pushed the only_runCtx branch 2 times, most recently from ad09c9c to 2e833c5 Compare April 7, 2021 05:42
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.

A bunch of suggestions below, but this is a great improvement.

tejal29 and others added 2 commits April 14, 2021 11:41
@tejal29 tejal29 merged commit 788275e into GoogleContainerTools:master Apr 15, 2021
@tejal29 tejal29 deleted the only_runCtx branch April 15, 2021 07:32
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.

2 participants