From ffebcb1223ec88f2cb32df60b956e3a09e92bcf1 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Fri, 3 Mar 2023 09:19:22 +0800 Subject: [PATCH] cri: disable drain-exec-IO if it is empty timeout Signed-off-by: Wei Fu --- pkg/cri/sbserver/container_execsync.go | 15 +++++++++++---- pkg/cri/server/container_execsync.go | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pkg/cri/sbserver/container_execsync.go b/pkg/cri/sbserver/container_execsync.go index af0c15842..6edd96da7 100644 --- a/pkg/cri/sbserver/container_execsync.go +++ b/pkg/cri/sbserver/container_execsync.go @@ -117,9 +117,15 @@ func (c *criService) execInternal(ctx context.Context, container containerd.Cont ctx, cancel := context.WithCancel(ctx) defer cancel() - drainExecSyncIOTimeout, err := time.ParseDuration(c.config.DrainExecSyncIOTimeout) - if err != nil { - return nil, fmt.Errorf("failed to parse drain_exec_sync_io_timeout %q: %w", c.config.DrainExecSyncIOTimeout, err) + var drainExecSyncIOTimeout time.Duration + var err error + + if c.config.DrainExecSyncIOTimeout != "" { + drainExecSyncIOTimeout, err = time.ParseDuration(c.config.DrainExecSyncIOTimeout) + if err != nil { + return nil, fmt.Errorf("failed to parse drain_exec_sync_io_timeout %q: %w", + c.config.DrainExecSyncIOTimeout, err) + } } spec, err := container.Spec(ctx) @@ -298,5 +304,6 @@ func drainExecSyncIO(ctx context.Context, execProcess containerd.Process, drainE execProcess.ID(), err) } } - return fmt.Errorf("failed to drain exec process %q io because io is still held by other processes", execProcess.ID()) + return fmt.Errorf("failed to drain exec process %q io in %s because io is still held by other processes", + execProcess.ID(), drainExecIOTimeout) } diff --git a/pkg/cri/server/container_execsync.go b/pkg/cri/server/container_execsync.go index a5884a644..63ba72512 100644 --- a/pkg/cri/server/container_execsync.go +++ b/pkg/cri/server/container_execsync.go @@ -117,9 +117,15 @@ func (c *criService) execInternal(ctx context.Context, container containerd.Cont ctx, cancel := context.WithCancel(ctx) defer cancel() - drainExecSyncIOTimeout, err := time.ParseDuration(c.config.DrainExecSyncIOTimeout) - if err != nil { - return nil, fmt.Errorf("failed to parse drain_exec_sync_io_timeout %q: %w", c.config.DrainExecSyncIOTimeout, err) + var drainExecSyncIOTimeout time.Duration + var err error + + if c.config.DrainExecSyncIOTimeout != "" { + drainExecSyncIOTimeout, err = time.ParseDuration(c.config.DrainExecSyncIOTimeout) + if err != nil { + return nil, fmt.Errorf("failed to parse drain_exec_sync_io_timeout %q: %w", + c.config.DrainExecSyncIOTimeout, err) + } } spec, err := container.Spec(ctx) @@ -298,5 +304,6 @@ func drainExecSyncIO(ctx context.Context, execProcess containerd.Process, drainE execProcess.ID(), err) } } - return fmt.Errorf("failed to drain exec process %q io because io is still held by other processes", execProcess.ID()) + return fmt.Errorf("failed to drain exec process %q io in %s because io is still held by other processes", + execProcess.ID(), drainExecIOTimeout) }