use controller-runtime signals (#2589)
This commit is contained in:
+2
-2
@@ -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 <shared volume path>
|
||||
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 {
|
||||
|
||||
+3
-2
@@ -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 <shared volume path>
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user