Capture os signals to gracefully shutdown fission components (#2261)
- Currently, fission components don't handle shutdown signals. So we don't get any to do the required cleanup before the fission process exits. Adding signal capture process with cancelling context so that all dependent processes stop working when the process gets term signal. - Set log level to error in otel shutdown function Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
+4
-2
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package timer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
|
||||
@@ -24,7 +26,7 @@ import (
|
||||
"github.com/fission/fission/pkg/publisher"
|
||||
)
|
||||
|
||||
func Start(logger *zap.Logger, routerUrl string) error {
|
||||
func Start(ctx context.Context, logger *zap.Logger, routerUrl string) error {
|
||||
fissionClient, _, _, _, err := crd.MakeFissionClient()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get fission or kubernetes client")
|
||||
@@ -36,7 +38,7 @@ func Start(logger *zap.Logger, routerUrl string) error {
|
||||
}
|
||||
|
||||
poster := publisher.MakeWebhookPublisher(logger, routerUrl)
|
||||
MakeTimerSync(logger, fissionClient, MakeTimer(logger, poster))
|
||||
MakeTimerSync(ctx, logger, fissionClient, MakeTimer(logger, poster))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -35,19 +35,19 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func MakeTimerSync(logger *zap.Logger, fissionClient *crd.FissionClient, timer *Timer) *TimerSync {
|
||||
func MakeTimerSync(ctx context.Context, logger *zap.Logger, fissionClient *crd.FissionClient, timer *Timer) *TimerSync {
|
||||
ws := &TimerSync{
|
||||
logger: logger.Named("timer_sync"),
|
||||
fissionClient: fissionClient,
|
||||
timer: timer,
|
||||
}
|
||||
go ws.syncSvc()
|
||||
go ws.syncSvc(ctx)
|
||||
return ws
|
||||
}
|
||||
|
||||
func (ws *TimerSync) syncSvc() {
|
||||
func (ws *TimerSync) syncSvc(ctx context.Context) {
|
||||
for {
|
||||
triggers, err := ws.fissionClient.CoreV1().TimeTriggers(metav1.NamespaceAll).List(context.TODO(), metav1.ListOptions{})
|
||||
triggers, err := ws.fissionClient.CoreV1().TimeTriggers(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
||||
if err != nil {
|
||||
if utils.IsNetworkError(err) {
|
||||
ws.logger.Info("encountered a network error - will retry", zap.Error(err))
|
||||
|
||||
Reference in New Issue
Block a user