-
Notifications
You must be signed in to change notification settings - Fork 157
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
Implement rollback stage for kubernetes plugin #5390
Conversation
…text cancellation handling Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5390 +/- ##
==========================================
- Coverage 25.82% 25.81% -0.01%
==========================================
Files 448 450 +2
Lines 48281 48337 +56
==========================================
+ Hits 12468 12480 +12
- Misses 34841 34885 +44
Partials 972 972 ☔ View full report in Codecov by Sentry. |
if !response.GetStatus().IsCompleted() && errors.Is(ctx.Err(), context.Canceled) { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Warashi
[Ask]
I thought that we should not mark the log persisted as completed when stage is still running regardless of context cancel.
Also, we should not mark the log persister as completed when the context is canceled.
WDYT?
it means we should !response.GetStatus().IsCompleted() || errors.Is(ctx.Err(), context.Canceled)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that we have to handle two cancellations, but we cannot determine the cause because the cancel is propagated beyond the gRPC layer.
- cancellation occurred by graceful shutdown.
- in this case, we should not mark the log persister as completed.
- cancellation occurred by the user via the web UI.
- in this case, we should return the status as canceled and mark the log persister as completed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized the plugin receives SIGTERM or SIGINT when the graceful shutdown is going, so I implemented the handling of them.
When the cancellation occurs without receiving such signals, the log persister should be completed.
…tion Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
…ister as completed Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
I realized that the plugin should return the StageStatus and should not return an error even if the error has occurred. 👉🏻 DONE |
…eStageResponse Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with small nits
Co-authored-by: Khanh Tran <[email protected]> Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
// SignalHandlingInterceptor is a gRPC interceptor that cancels the context when a termination signal is received. | ||
func SignalHandlingInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) { | ||
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM) | ||
defer cancel() | ||
|
||
return handler(ctx, req) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Warashi Sorry, I noticed that we can't distinguish Graceful Shutdown and context cancel for now. piped still treats both as context canceled.
We might use signal.Notify
like this.
// SignalHandlingInterceptor is a gRPC interceptor that cancels the context when a termination signal is received. | |
func SignalHandlingInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) { | |
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM) | |
defer cancel() | |
return handler(ctx, req) | |
} | |
// SignalHandlingInterceptor is a gRPC interceptor that cancels the context when a termination signal is received. | |
var terminated atomic.Bool | |
// SignalHandlingInterceptor is a gRPC interceptor that cancels the context when a termination signal is received. | |
func SignalHandlingInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) { | |
sigCh := make(chan os.Signal, 1) | |
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) | |
ctx, cancel := context.WithCancel(ctx) | |
defer cancel() | |
go func() { | |
select { | |
case <-sigCh: | |
// received a termination signal | |
terminated.Store(true) | |
cancel() | |
} | |
}() | |
return handler(ctx, req) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ffjlabo
I implemented the determination of the Graceful Shutdown in this file. Is it not enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Warashi I got it. Sorry, I missed it. 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix! left a nit comment.
pkg/plugin/signalhandler/handler.go
Outdated
func init() { | ||
ctx, cancel := signal.NotifyContext(context.Background(), signals...) | ||
go func() { | ||
defer cancel() | ||
<-ctx.Done() | ||
terminated.Store(true) | ||
}() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] We should add a comment to describe that this distinguishes context.Cancel and Graceful shutdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the comments. Please check whether the comments are enough.
02a4df2
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
What this PR does:
Why we need it:
We have to support rollback of k8s stages
Which issue(s) this PR fixes:
Part of #4980
Does this PR introduce a user-facing change?: No