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 wait entrypoint cancellation error log output. #7272

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func main() {
log.Print(err.Error())
os.Exit(1)
case entrypoint.ContextError:
if errors.Is(err, entrypoint.ErrContextCanceled) {
if entrypoint.IsContextCanceledError(err) {
log.Print("Step was cancelled")
// use the SIGKILL signal to distinguish normal exit programs, just like kill -9 PID
os.Exit(int(syscall.SIGKILL))
Expand Down
12 changes: 11 additions & 1 deletion pkg/entrypoint/entrypointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ var (
ErrContextCanceled = ContextError(context.Canceled.Error())
)

// IsContextDeadlineError determine whether the error is context deadline
func IsContextDeadlineError(err error) bool {
return errors.Is(err, ErrContextDeadlineExceeded)
}

// IsContextCanceledError determine whether the error is context canceled
func IsContextCanceledError(err error) bool {
return errors.Is(err, ErrContextCanceled)
}

// Entrypointer holds fields for running commands with redirected
// entrypoints.
type Entrypointer struct {
Expand Down Expand Up @@ -174,7 +184,7 @@ func (e Entrypointer) Go() error {
defer cancel()
// start a goroutine to listen for cancellation file
go func() {
if err := e.waitingCancellation(ctx, cancel); err != nil {
if err := e.waitingCancellation(ctx, cancel); err != nil && (!IsContextCanceledError(err) && !IsContextDeadlineError(err)) {
logger.Error("Error while waiting for cancellation", zap.Error(err))
}
}()
Expand Down
22 changes: 22 additions & 0 deletions pkg/entrypoint/entrypointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,28 @@ func TestEntrypointerStopOnCancel(t *testing.T) {
}
}

func TestIsContextDeadlineError(t *testing.T) {
ctxErr := ContextError(context.DeadlineExceeded.Error())
if !IsContextDeadlineError(ctxErr) {
t.Errorf("expected context deadline error, got %v", ctxErr)
}
normalErr := ContextError("normal error")
if IsContextDeadlineError(normalErr) {
t.Errorf("expected normal error, got %v", normalErr)
}
}

func TestIsContextCanceledError(t *testing.T) {
ctxErr := ContextError(context.Canceled.Error())
if !IsContextCanceledError(ctxErr) {
t.Errorf("expected context canceled error, got %v", ctxErr)
}
normalErr := ContextError("normal error")
if IsContextCanceledError(normalErr) {
t.Errorf("expected normal error, got %v", normalErr)
}
}

type fakeWaiter struct {
sync.Mutex
waited []string
Expand Down
Loading