-
Notifications
You must be signed in to change notification settings - Fork 8
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
Added auto detection for kubelet client config #19
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83cbcbd
feat:Added auto detection for kubelet client config by using --auto_c…
cristianciutea 0390bf4
close request body
cristianciutea 315e439
check if command line args were provided
cristianciutea 0d05673
loeg err message
cristianciutea 80d0fa6
update linter version
cristianciutea b226a2f
trigger pipeline
cristianciutea 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,22 +10,31 @@ import ( | |
const ( | ||
namespaces = "namespaces" | ||
port = "port" | ||
Host = "host" | ||
insecure = "insecure" | ||
timeout = "timeout" | ||
tls = "tls" | ||
envPrefix = "NRIA" | ||
|
||
DefaultHost = "localhost" | ||
DefaultPort = 10255 | ||
) | ||
|
||
var _ = flag.String(namespaces, "", "(optional, default '') Comma separated list of namespaces to discover pods on") | ||
var _ = flag.Bool(insecure, false, `(optional, default false, deprecated) Use insecure (non-ssl) connection. | ||
For backwards compatibility this flag takes precedence over 'tls')`) | ||
var _ = flag.Int(timeout, 5000, "(optional, default 5000) timeout in ms") | ||
var _ = flag.Bool(tls, false, "(optional, default false) Use secure (tls) connection") | ||
var _ = flag.Int(port, 10255, "(optional, default 10255) Port used to connect to the kubelet") | ||
var _ = flag.Int(port, DefaultPort, "(optional, default 10255) Port used to connect to the kubelet") | ||
var _ = flag.String(Host, DefaultHost, "(optional, default "+DefaultHost+") Host used to connect to the kubelet") | ||
|
||
// Config defined the currently accepted configuration parameters of the Discoverer | ||
type Config struct { | ||
Namespaces []string | ||
Port int | ||
Host string | ||
TLS bool | ||
Timeout int | ||
} | ||
|
||
func splitStrings(str string) []string { | ||
|
@@ -35,14 +44,32 @@ func splitStrings(str string) []string { | |
return []string{} | ||
} | ||
|
||
// IsFlagPassed checks if a particular command line argument was provided or not. | ||
func IsFlagPassed(name string) bool { | ||
found := false | ||
flag.Visit(func(f *flag.Flag) { | ||
if f.Name == name { | ||
found = true | ||
} | ||
}) | ||
return found | ||
} | ||
|
||
// IsAutoConfig returns true if no config parameter was provided as cmd line arg. | ||
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. Cool 👍 |
||
func (c *Config) IsAutoConfig() bool { | ||
return !IsFlagPassed(Host) && !IsFlagPassed(port) && !IsFlagPassed(tls) | ||
} | ||
|
||
func NewConfig(version string) Config { | ||
flag.Parse() | ||
|
||
v := viper.New() | ||
_ = v.BindPFlag(namespaces, flag.Lookup(namespaces)) | ||
_ = v.BindPFlag(port, flag.Lookup(port)) | ||
_ = v.BindPFlag(Host, flag.Lookup(Host)) | ||
_ = v.BindPFlag(tls, flag.Lookup(tls)) | ||
_ = v.BindPFlag(insecure, flag.Lookup(insecure)) | ||
_ = v.BindPFlag(timeout, flag.Lookup(timeout)) | ||
|
||
v.SetEnvPrefix(envPrefix) | ||
v.AutomaticEnv() | ||
|
@@ -56,6 +83,8 @@ func NewConfig(version string) Config { | |
return Config{ | ||
Namespaces: splitStrings(v.GetString(namespaces)), | ||
Port: v.GetInt(port), | ||
Host: v.GetString(Host), | ||
TLS: useTLS, | ||
Timeout: v.GetInt(timeout), | ||
} | ||
} |
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
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.
do we need to mention this new flag in PR description + release notes?