github.com/cilium/cilium@v1.16.2/clustermesh-apiserver/kvstoremesh/root.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package kvstoremesh 5 6 import ( 7 "log/slog" 8 9 "github.com/cilium/hive/cell" 10 "github.com/sirupsen/logrus" 11 "github.com/spf13/cobra" 12 13 "github.com/cilium/cilium/pkg/clustermesh/types" 14 "github.com/cilium/cilium/pkg/hive" 15 "github.com/cilium/cilium/pkg/logging" 16 "github.com/cilium/cilium/pkg/logging/logfields" 17 "github.com/cilium/cilium/pkg/metrics" 18 "github.com/cilium/cilium/pkg/option" 19 "github.com/cilium/cilium/pkg/version" 20 ) 21 22 var ( 23 log = logging.DefaultLogger.WithField(logfields.LogSubsys, "kvstoremesh") 24 ) 25 26 func NewCmd(h *hive.Hive) *cobra.Command { 27 rootCmd := &cobra.Command{ 28 Use: "kvstoremesh", 29 Short: "Run KVStoreMesh", 30 Run: func(cmd *cobra.Command, args []string) { 31 if err := h.Run(slog.Default()); err != nil { 32 log.Fatal(err) 33 } 34 }, 35 PreRun: func(cmd *cobra.Command, args []string) { 36 // Overwrite the metrics namespace with the one specific for KVStoreMesh 37 metrics.Namespace = metrics.CiliumKVStoreMeshNamespace 38 option.Config.Populate(h.Viper()) 39 if option.Config.Debug { 40 log.Logger.SetLevel(logrus.DebugLevel) 41 } 42 option.LogRegisteredOptions(h.Viper(), log) 43 log.Infof("Cilium KVStoreMesh %s", version.Version) 44 }, 45 } 46 47 h.RegisterFlags(rootCmd.Flags()) 48 rootCmd.AddCommand(h.Command()) 49 50 return rootCmd 51 } 52 53 func registerClusterInfoValidator(lc cell.Lifecycle, cinfo types.ClusterInfo, log logrus.FieldLogger) { 54 lc.Append(cell.Hook{ 55 OnStart: func(cell.HookContext) error { 56 if err := cinfo.InitClusterIDMax(); err != nil { 57 return err 58 } 59 if err := cinfo.ValidateStrict(log); err != nil { 60 return err 61 } 62 return nil 63 }, 64 }) 65 }