From e99f22cfaac6c8653d61196464749a88f364bc45 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Thu, 1 Aug 2024 10:06:11 +0200 Subject: [PATCH] remove cmd/consoleplugin contents Signed-off-by: Xavier Coulon --- cmd/consoleplugin/main.go | 112 -------------------------------------- 1 file changed, 112 deletions(-) delete mode 100644 cmd/consoleplugin/main.go diff --git a/cmd/consoleplugin/main.go b/cmd/consoleplugin/main.go deleted file mode 100644 index 4276e6a7..00000000 --- a/cmd/consoleplugin/main.go +++ /dev/null @@ -1,112 +0,0 @@ -package main - -import ( - "context" - "flag" - "os" - "os/signal" - "syscall" - "time" - - toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" - "github.com/codeready-toolchain/member-operator/pkg/klog" - - "go.uber.org/zap/zapcore" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" - klogv1 "k8s.io/klog" - klogv2 "k8s.io/klog/v2" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/log/zap" -) - -const gracefulTimeout = time.Second * 15 - -var setupLog = ctrl.Log.WithName("setup") - -type shutdown interface { - Shutdown(ctx context.Context) error -} - -func main() { - - opts := zap.Options{ - Development: true, - Encoder: zapcore.NewJSONEncoder(zapcore.EncoderConfig{ - TimeKey: "ts", - LevelKey: "level", - NameKey: "logger", - CallerKey: "caller", - FunctionKey: zapcore.OmitKey, - MessageKey: "msg", - StacktraceKey: "stacktrace", - LineEnding: zapcore.DefaultLineEnding, - EncodeLevel: zapcore.LowercaseLevelEncoder, - EncodeTime: zapcore.ISO8601TimeEncoder, - EncodeDuration: zapcore.SecondsDurationEncoder, - EncodeCaller: zapcore.ShortCallerEncoder, - }), - } - opts.BindFlags(flag.CommandLine) - flag.Parse() - - ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) - // also set the client-go logger so we get the same JSON output - klogv2.SetLogger(zap.New(zap.UseFlagOptions(&opts))) - - // see https://github.com/kubernetes/klog#coexisting-with-klogv2 - // BEGIN : hack to redirect klogv1 calls to klog v2 - // Tell klog NOT to log into STDERR. Otherwise, we risk - // certain kinds of API errors getting logged into a directory not - // available in a `FROM scratch` Docker container, causing us to abort - var klogv1Flags flag.FlagSet - klogv1.InitFlags(&klogv1Flags) - if err := klogv1Flags.Set("logtostderr", "false"); err != nil { // By default klog v1 logs to stderr, switch that off - setupLog.Error(err, "") - os.Exit(1) - } - if err := klogv1Flags.Set("stderrthreshold", "FATAL"); err != nil { // stderrthreshold defaults to ERROR, so we don't get anything in stderr - setupLog.Error(err, "") - os.Exit(1) - } - klogv1.SetOutputBySeverity("INFO", klog.Writer{}) // tell klog v1 to use the custom writer - // END : hack to redirect klogv1 calls to klog v2 - - setupLog.Info("Configuring web console plugin server ...") - - runtimeScheme := runtime.NewScheme() - - if err := toolchainv1alpha1.AddToScheme(runtimeScheme); err != nil { - setupLog.Error(err, "adding toolchain api to scheme failed") - os.Exit(1) - } - if err := corev1.AddToScheme(runtimeScheme); err != nil { - setupLog.Error(err, "adding core api to scheme failed") - os.Exit(1) - } - - gracefulShutdown(gracefulTimeout) -} - -func gracefulShutdown(timeout time.Duration, hs ...shutdown) { - // For a channel used for notification of just one signal value, a buffer of - // size 1 is sufficient. - stop := make(chan os.Signal, 1) - - // We'll accept graceful shutdowns when quit via SIGINT (Ctrl+C) or SIGTERM - // (Ctrl+/). SIGKILL, SIGQUIT will not be caught. - signal.Notify(stop, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) - sigReceived := <-stop - setupLog.Info("Signal received", "signal", sigReceived.String()) - - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - setupLog.Info("Shutdown with timeout", "timeout", timeout.String()) - for _, s := range hs { - if err := s.Shutdown(ctx); err != nil { - setupLog.Error(err, "Shutdown error") - } else { - setupLog.Info("Server stopped") - } - } -}