diff --git a/cmd/tetra/common/client.go b/cmd/tetra/common/client.go index 3472f919ab8..bbbd31f68a1 100644 --- a/cmd/tetra/common/client.go +++ b/cmd/tetra/common/client.go @@ -41,7 +41,7 @@ func getActiveServAddr(fname string) (string, error) { } func connect(ctx context.Context) (*grpc.ClientConn, string, error) { - connCtx, connCancel := context.WithTimeout(ctx, viper.GetDuration(KeyTimeout)) + connCtx, connCancel := context.WithTimeout(ctx, Timeout) defer connCancel() var conn *grpc.ClientConn @@ -73,7 +73,7 @@ func connect(ctx context.Context) (*grpc.ClientConn, string, error) { } if conn == nil { // Try the server-address prameter - serverAddr = viper.GetString(KeyServerAddress) + serverAddr = ServerAddress conn, err = grpc.DialContext(connCtx, serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) } @@ -93,7 +93,7 @@ func CliRunErr(fn func(ctx context.Context, cli tetragon.FineGuidanceSensorsClie for { conn, serverAddr, err = connect(ctx) if err != nil { - if attempts < viper.GetInt(KeyRetries) { + if attempts < Retries { // Exponential backoff attempts++ logger.GetLogger().WithField("server-address", serverAddr).WithField("attempts", attempts).WithError(err).Error("Connection attempt failed, retrying...") @@ -144,7 +144,7 @@ func NewConnectedClient() ConnectedClient { for { c.conn, serverAddr, err = connect(c.Ctx) if err != nil { - if attempts < viper.GetInt(KeyRetries) { + if attempts < Retries { // Exponential backoff attempts++ logger.GetLogger().WithField("server-address", serverAddr).WithField("attempts", attempts).WithError(err).Error("Connection attempt failed, retrying...") diff --git a/cmd/tetra/common/flags.go b/cmd/tetra/common/flags.go index 3935515e79f..e7ac1dfac40 100644 --- a/cmd/tetra/common/flags.go +++ b/cmd/tetra/common/flags.go @@ -3,6 +3,8 @@ package common +import "time" + const ( KeyColor = "color" // string KeyDebug = "debug" // bool @@ -12,3 +14,13 @@ const ( KeyTimeout = "timeout" // duration KeyRetries = "retries" // int ) + +var ( + Color string + Debug bool + Output string + Tty string + ServerAddress string + Timeout time.Duration + Retries int +) diff --git a/cmd/tetra/getevents/getevents.go b/cmd/tetra/getevents/getevents.go index bcd06e4153a..540505facbb 100644 --- a/cmd/tetra/getevents/getevents.go +++ b/cmd/tetra/getevents/getevents.go @@ -16,7 +16,6 @@ import ( "github.com/cilium/tetragon/pkg/encoder" "github.com/cilium/tetragon/pkg/logger" "github.com/spf13/cobra" - "github.com/spf13/viper" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/fieldmaskpb" @@ -184,7 +183,7 @@ func New() *cobra.Command { fi, _ := os.Stdin.Stat() if fi.Mode()&os.ModeNamedPipe != 0 { // read events from stdin - getEvents(context.Background(), newIOReaderClient(os.Stdin, viper.GetBool("debug"))) + getEvents(context.Background(), newIOReaderClient(os.Stdin, common.Debug)) return } // connect to server diff --git a/cmd/tetra/main.go b/cmd/tetra/main.go index 90044933ac7..d6513d59d81 100644 --- a/cmd/tetra/main.go +++ b/cmd/tetra/main.go @@ -10,7 +10,6 @@ import ( "github.com/cilium/tetragon/pkg/logger" "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/spf13/viper" ) var ( @@ -32,7 +31,7 @@ func New() *cobra.Command { cmd.Help() }, PersistentPreRun: func(cmd *cobra.Command, args []string) { - if viper.GetBool(common.KeyDebug) { + if common.Debug { logger.DefaultLogger.SetLevel(logrus.DebugLevel) } }, @@ -42,10 +41,9 @@ func New() *cobra.Command { addCommands(rootCmd) flags := rootCmd.PersistentFlags() - flags.BoolP(common.KeyDebug, "d", false, "Enable debug messages") - flags.String(common.KeyServerAddress, "localhost:54321", "gRPC server address") - flags.Duration(common.KeyTimeout, 10*time.Second, "Connection timeout") - flags.Int(common.KeyRetries, 0, "Connection retries with exponential backoff") - viper.BindPFlags(flags) + flags.BoolVarP(&common.Debug, common.KeyDebug, "d", false, "Enable debug messages") + flags.StringVar(&common.ServerAddress, common.KeyServerAddress, "localhost:54321", "gRPC server address") + flags.DurationVar(&common.Timeout, common.KeyTimeout, 10*time.Second, "Connection timeout") + flags.IntVar(&common.Retries, common.KeyRetries, 0, "Connection retries with exponential backoff") return rootCmd }