-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace the use of viper.bind flags with variables binding #1119
Merged
mtardy
merged 1 commit into
cilium:main
from
Jack-R-lantern:ISSUE-1108/Replace-the-use-of-viper.BindFlags-with-variables-binding
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, "", "gRPC server address") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah sorry we will need a last fix, I just noticed by reading carefully that the default value |
||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aaaah maybe you removed the default value because of this. I think @tixxdz worked on this, what do you think? Should we remove the default value
localhost:54321
from the flag, see this https://github.com/cilium/tetragon/pull/1119/files#r1379864446.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry to delay this PR again @Jack-R-lantern, will just need a look from Djalal because he worked on the default gRPC address to put so let him just ack this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as far as I understand it would not be okay to remove the default since for most
tetra
users, tetragon might not run locally and the file (tetragon-info.json) it's trying to read will not be available. But with the default value, this part of the code will never be triggered. Maybe we could try to read the file containing the server address and fall back to the defaultlocalhost:54321
value on file read error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it but I think
viper.IsSet
returned false for the default value. So we would need to test this and to get the same behavior as before we should change some stuff here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do some more thinking about that code as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tixxdz could you take a look at this one :)?