This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 3068da6d8 fix: Use SIGTERM and SIGINT aware context for bootstrap
operations
3068da6d8 is described below
commit 3068da6d8c66d572b1d85d043fe217c355b18b77
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Thu Sep 29 09:44:59 2022 +0200
fix: Use SIGTERM and SIGINT aware context for bootstrap operations
---
pkg/cmd/operator/operator.go | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/pkg/cmd/operator/operator.go b/pkg/cmd/operator/operator.go
index c1e57ada2..71817cf8c 100644
--- a/pkg/cmd/operator/operator.go
+++ b/pkg/cmd/operator/operator.go
@@ -134,6 +134,8 @@ func Run(healthPort, monitoringPort int32, leaderElection
bool, leaderElectionID
watchNamespace, err := getWatchNamespace()
exitOnError(err, "failed to get watch namespace")
+ ctx := signals.SetupSignalHandler()
+
cfg, err := config.GetConfig()
exitOnError(err, "cannot get client config")
// Increase maximum burst that is used by client-side throttling,
@@ -151,7 +153,7 @@ func Run(healthPort, monitoringPort int32, leaderElection
bool, leaderElectionID
broadcaster := record.NewBroadcaster()
defer broadcaster.Shutdown()
- if ok, err := kubernetes.CheckPermission(context.TODO(),
bootstrapClient, corev1.GroupName, "events", watchNamespace, "", "create"); err
!= nil || !ok {
+ if ok, err := kubernetes.CheckPermission(ctx, bootstrapClient,
corev1.GroupName, "events", watchNamespace, "", "create"); err != nil || !ok {
// Do not sink Events to the server as they'll be rejected
broadcaster = event.NewSinkLessBroadcaster(broadcaster)
exitOnError(err, "cannot check permissions for creating Events")
@@ -171,10 +173,10 @@ func Run(healthPort, monitoringPort int32, leaderElection
bool, leaderElectionID
}
// Set the operator container image if it runs in-container
- platform.OperatorImage, err = getOperatorImage(context.TODO(),
bootstrapClient)
+ platform.OperatorImage, err = getOperatorImage(ctx, bootstrapClient)
exitOnError(err, "cannot get operator container image")
- if ok, err := kubernetes.CheckPermission(context.TODO(),
bootstrapClient, coordination.GroupName, "leases", operatorNamespace, "",
"create"); err != nil || !ok {
+ if ok, err := kubernetes.CheckPermission(ctx, bootstrapClient,
coordination.GroupName, "leases", operatorNamespace, "", "create"); err != nil
|| !ok {
leaderElection = false
exitOnError(err, "cannot check permissions for creating Leases")
log.Info("The operator is not granted permissions to create
Leases")
@@ -223,7 +225,7 @@ func Run(healthPort, monitoringPort int32, leaderElection
bool, leaderElectionID
exitOnError(err, "")
exitOnError(
- mgr.GetFieldIndexer().IndexField(context.Background(),
&corev1.Pod{}, "status.phase",
+ mgr.GetFieldIndexer().IndexField(ctx, &corev1.Pod{},
"status.phase",
func(obj ctrl.Object) []string {
pod, _ := obj.(*corev1.Pod)
return []string{string(pod.Status.Phase)}
@@ -239,13 +241,13 @@ func Run(healthPort, monitoringPort int32, leaderElection
bool, leaderElectionID
exitOnError(controller.AddToManager(mgr, ctrlClient), "")
log.Info("Installing operator resources")
- installCtx, installCancel := context.WithTimeout(context.Background(),
1*time.Minute)
+ installCtx, installCancel := context.WithTimeout(ctx, 1*time.Minute)
defer installCancel()
install.OperatorStartupOptionalTools(installCtx, bootstrapClient,
watchNamespace, operatorNamespace, log)
exitOnError(findOrCreateIntegrationPlatform(installCtx,
bootstrapClient, operatorNamespace), "failed to create integration platform")
log.Info("Starting the manager")
- exitOnError(mgr.Start(signals.SetupSignalHandler()), "manager exited
non-zero")
+ exitOnError(mgr.Start(ctx), "manager exited non-zero")
}
// findOrCreateIntegrationPlatform create default integration platform in
operator namespace if not already exists.