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

Reduce default status check deadline to 2 mins #3687

Merged
merged 4 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pkg/skaffold/deploy/status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
)

var (
defaultStatusCheckDeadline = time.Duration(10) * time.Minute
defaultStatusCheckDeadline = time.Duration(2) * time.Minute
tejal29 marked this conversation as resolved.
Show resolved Hide resolved

// Poll period for checking set to 100 milliseconds
defaultPollPeriodInMilliseconds = 100
Expand Down Expand Up @@ -69,8 +69,11 @@ func StatusCheck(ctx context.Context, defaultLabeller *DefaultLabeller, runCtx *
return errors.Wrap(err, "getting Kubernetes client")
}

deadline := getDeadline(runCtx.Cfg.Deploy.StatusCheckDeadlineSeconds)
deployments, err := getDeployments(client, runCtx.Opts.Namespace, defaultLabeller, deadline)
deployments, err := getDeployments(client, runCtx.Opts.Namespace, defaultLabeller,
getDeadline(runCtx.Cfg.Deploy.StatusCheckDeadlineSeconds))

deadline := statusCheckDeadline(runCtx.Cfg.Deploy.StatusCheckDeadlineSeconds, deployments)

if err != nil {
return errors.Wrap(err, "could not fetch deployments")
}
Expand Down Expand Up @@ -110,7 +113,7 @@ func getDeployments(client kubernetes.Interface, ns string, l *DefaultLabeller,
deployments := make([]Resource, 0, len(deps.Items))
for _, d := range deps.Items {
var deadline time.Duration
if d.Spec.ProgressDeadlineSeconds == nil || *d.Spec.ProgressDeadlineSeconds > int32(deadlineDuration.Seconds()) {
if d.Spec.ProgressDeadlineSeconds == nil {
deadline = deadlineDuration
} else {
deadline = time.Duration(*d.Spec.ProgressDeadlineSeconds) * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here?

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 dont understand what you mean?
Do you meant *d.Spec.ProgressDeadline * time.Second?
i see an IDE error

cannot use type int as type Duration in an assignment

and also a make error

pkg/skaffold/deploy/status_check.go:119:47: invalid operation: *d.Spec.ProgressDeadlineSeconds * time.Second (mismatched types int32 and time.Duration)

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad. Only works with constants

Expand Down Expand Up @@ -257,3 +260,16 @@ func (c *resourceCounter) markProcessed(err error) resourceCounter {
pods: &podCp,
}
}

func statusCheckDeadline(value int, deployments []Resource) time.Duration {
if value > 0 {
return time.Duration(value) * time.Second
tejal29 marked this conversation as resolved.
Show resolved Hide resolved
}
d := time.Duration(0)
for _, r := range deployments {
if r.Deadline() > d {
d = r.Deadline()
tejal29 marked this conversation as resolved.
Show resolved Hide resolved
}
}
return d
tejal29 marked this conversation as resolved.
Show resolved Hide resolved
}
34 changes: 33 additions & 1 deletion pkg/skaffold/deploy/status_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestGetDeployments(t *testing.T) {
},
},
expected: []Resource{
resource.NewDeployment("dep1", "test", time.Duration(200)*time.Second),
resource.NewDeployment("dep1", "test", time.Duration(300)*time.Second),
},
},
{
Expand Down Expand Up @@ -483,3 +483,35 @@ func TestResourceMarkProcessed(t *testing.T) {
})
}
}

func TestGetStatusCheckDeadline(t *testing.T) {
tests := []struct {
description string
value int
deps []Resource
expected time.Duration
}{
{
description: "no value specified",
deps: []Resource{
resource.NewDeployment("dep1", "test", time.Duration(10)*time.Second),
resource.NewDeployment("dep2", "test", time.Duration(20)*time.Second),
},
expected: time.Duration(20) * time.Second,
},
{
description: "value specified less than all other resources",
value: 5,
deps: []Resource{
resource.NewDeployment("dep1", "test", time.Duration(10)*time.Second),
resource.NewDeployment("dep2", "test", time.Duration(20)*time.Second),
},
expected: time.Duration(5) * time.Second,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
t.CheckDeepEqual(test.expected, statusCheckDeadline(test.value, test.deps))
})
}
}