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

fix(executor): Correct usage of time.Duration. Fixes #5046 #5049

Merged
merged 5 commits into from
Feb 10, 2021
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
4 changes: 2 additions & 2 deletions workflow/executor/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func KillGracefully(ctx context.Context, c KubernetesClientInterface, containerI
if err != nil {
return err
}
err = WaitForTermination(ctx, c, containerID, terminationGracePeriodDuration*time.Second)
err = WaitForTermination(ctx, c, containerID, terminationGracePeriodDuration)
if err == nil {
log.Infof("ContainerID %q successfully killed", containerID)
return nil
Expand All @@ -106,7 +106,7 @@ func KillGracefully(ctx context.Context, c KubernetesClientInterface, containerI
if err != nil {
return err
}
err = WaitForTermination(ctx, c, containerID, terminationGracePeriodDuration*time.Second)
err = WaitForTermination(ctx, c, containerID, terminationGracePeriodDuration)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/executor/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ func TestKillGracefully(t *testing.T) {
}
ctx := context.Background()
err := KillGracefully(ctx, mock, "container-id", 1)
assert.EqualError(t, err, "timeout after 1s")
assert.EqualError(t, err, "timeout after 1ns")
}
2 changes: 1 addition & 1 deletion workflow/executor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (d *DockerExecutor) Kill(ctx context.Context, containerIDs []string, termin
select {
case err = <-waitCh:
// waitCmd completed
case <-time.After(terminationGracePeriodDuration * time.Second):
case <-time.After(terminationGracePeriodDuration):
log.Infof("Timed out (%ds) for containers to terminate gracefully. Killing forcefully", terminationGracePeriodDuration)
forceKillArgs := append([]string{"kill", "--signal", "KILL"}, containerIDs...)
forceKillCmd := exec.Command("docker", forceKillArgs...)
Expand Down
4 changes: 2 additions & 2 deletions workflow/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,10 @@ func (we *WorkflowExecutor) GetSecrets(ctx context.Context, namespace, name, key
// GetTerminationGracePeriodDuration returns the terminationGracePeriodSeconds of podSpec in Time.Duration format
func (we *WorkflowExecutor) GetTerminationGracePeriodDuration(ctx context.Context) (time.Duration, error) {
pod, err := we.getPod(ctx)
if err != nil {
if err != nil || pod.Spec.TerminationGracePeriodSeconds == nil {
return time.Duration(0), err
}
terminationGracePeriodDuration := time.Duration(*pod.Spec.TerminationGracePeriodSeconds)
terminationGracePeriodDuration := time.Second * time.Duration(*pod.Spec.TerminationGracePeriodSeconds)
return terminationGracePeriodDuration, nil
}

Expand Down
2 changes: 1 addition & 1 deletion workflow/executor/pns/pns.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (p *PNSExecutor) killContainer(containerID string, terminationGracePeriodDu
if err != nil {
log.Warnf("Failed to SIGTERM pid %d: %v", pid, err)
}
waitPIDOpts := executil.WaitPIDOpts{Timeout: terminationGracePeriodDuration * time.Second}
waitPIDOpts := executil.WaitPIDOpts{Timeout: terminationGracePeriodDuration}
err = executil.WaitPID(pid, waitPIDOpts)
if err == nil {
log.Infof("PID %d completed", pid)
Expand Down