From a64fcc3faf91216e61aced00b4ac2656057be78a Mon Sep 17 00:00:00 2001 From: neha_gupta Date: Mon, 31 Oct 2022 12:03:06 +0530 Subject: [PATCH] use controller-runtime signals (#2589) --- cmd/builder/main.go | 4 ++-- cmd/fetcher/main.go | 5 ++-- cmd/fission-bundle/main.go | 4 ++-- cmd/preupgradechecks/main.go | 4 ++-- pkg/utils/signals/signals.go | 46 ------------------------------------ 5 files changed, 9 insertions(+), 54 deletions(-) delete mode 100644 pkg/utils/signals/signals.go diff --git a/cmd/builder/main.go b/cmd/builder/main.go index cc927323..fd15ee49 100644 --- a/cmd/builder/main.go +++ b/cmd/builder/main.go @@ -20,18 +20,18 @@ import ( "os" "go.uber.org/zap" + "sigs.k8s.io/controller-runtime/pkg/manager/signals" "github.com/fission/fission/cmd/builder/app" "github.com/fission/fission/pkg/utils/loggerfactory" "github.com/fission/fission/pkg/utils/profile" - "github.com/fission/fission/pkg/utils/signals" ) // Usage: builder func main() { logger := loggerfactory.GetLogger() defer logger.Sync() - ctx := signals.SetupSignalHandlerWithContext(logger) + ctx := signals.SetupSignalHandler() profile.ProfileIfEnabled(ctx, logger) shareVolume := os.Args[1] if _, err := os.Stat(shareVolume); err != nil { diff --git a/cmd/fetcher/main.go b/cmd/fetcher/main.go index 6fc2cc0b..979c4d30 100644 --- a/cmd/fetcher/main.go +++ b/cmd/fetcher/main.go @@ -17,10 +17,11 @@ limitations under the License. package main import ( + "sigs.k8s.io/controller-runtime/pkg/manager/signals" + "github.com/fission/fission/cmd/fetcher/app" "github.com/fission/fission/pkg/utils/loggerfactory" "github.com/fission/fission/pkg/utils/profile" - "github.com/fission/fission/pkg/utils/signals" ) // Usage: fetcher @@ -28,7 +29,7 @@ func main() { logger := loggerfactory.GetLogger() defer logger.Sync() - ctx := signals.SetupSignalHandlerWithContext(logger) + ctx := signals.SetupSignalHandler() profile.ProfileIfEnabled(ctx, logger) app.Run(ctx, logger) } diff --git a/cmd/fission-bundle/main.go b/cmd/fission-bundle/main.go index 0a49ceff..8a0b5257 100644 --- a/cmd/fission-bundle/main.go +++ b/cmd/fission-bundle/main.go @@ -24,6 +24,7 @@ import ( "strconv" docopt "github.com/docopt/docopt-go" + "sigs.k8s.io/controller-runtime/pkg/manager/signals" "go.uber.org/zap" @@ -41,7 +42,6 @@ import ( "github.com/fission/fission/pkg/utils/loggerfactory" "github.com/fission/fission/pkg/utils/otel" "github.com/fission/fission/pkg/utils/profile" - "github.com/fission/fission/pkg/utils/signals" ) func runController(ctx context.Context, logger *zap.Logger, port int) { @@ -199,7 +199,7 @@ Options: logger := loggerfactory.GetLogger() defer exitWithSync(logger) - ctx := signals.SetupSignalHandlerWithContext(logger) + ctx := signals.SetupSignalHandler() profile.ProfileIfEnabled(ctx, logger) version := fmt.Sprintf("Fission Bundle Version: %v", info.BuildInfo().String()) diff --git a/cmd/preupgradechecks/main.go b/cmd/preupgradechecks/main.go index 0a94f067..39115378 100644 --- a/cmd/preupgradechecks/main.go +++ b/cmd/preupgradechecks/main.go @@ -19,10 +19,10 @@ package main import ( "github.com/docopt/docopt-go" "go.uber.org/zap" + "sigs.k8s.io/controller-runtime/pkg/manager/signals" "github.com/fission/fission/pkg/info" "github.com/fission/fission/pkg/utils/loggerfactory" - "github.com/fission/fission/pkg/utils/signals" ) func getStringArgWithDefault(arg interface{}, defaultValue string) string { @@ -58,7 +58,7 @@ Options: zap.Error(err)) } - ctx := signals.SetupSignalHandlerWithContext(logger) + ctx := signals.SetupSignalHandler() crd := crdBackedClient.GetFunctionCRD(ctx) if crd == nil { logger.Info("nothing to do since CRDs are not present on the cluster") diff --git a/pkg/utils/signals/signals.go b/pkg/utils/signals/signals.go deleted file mode 100644 index 63181355..00000000 --- a/pkg/utils/signals/signals.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2021 The Fission Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package signals - -import ( - "context" - "os" - "os/signal" - "syscall" - - "go.uber.org/zap" -) - -var onlyOneSignalHandler = make(chan struct{}) - -func SetupSignalHandlerWithContext(logger *zap.Logger) context.Context { - var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM} - - close(onlyOneSignalHandler) // panics when called twice - - ctx, cancel := context.WithCancel(context.Background()) - c := make(chan os.Signal, 2) - signal.Notify(c, shutdownSignals...) - go func() { - signal := <-c - logger.Info("Received signal", zap.String("signal", signal.String())) - cancel() - <-c - panic("multiple signals received") - }() - - return ctx -}