-
Notifications
You must be signed in to change notification settings - Fork 290
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
Checked cluster name before executing kubectl command #243
Conversation
pkg/utils/utils_test.go
Outdated
result := GetClusterNameFromKubectlCmd(str) | ||
|
||
if result != "minikube" { | ||
t.Errorf("Expecte minikube but got %v ", result) |
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.
expected
instead of Expecte
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.
done
pkg/utils/utils.go
Outdated
|
||
//GetClusterNameFromKubectlCmd this will return cluster name from kubectl command | ||
func GetClusterNameFromKubectlCmd(cmd string) string { | ||
i := strings.Index(cmd, "--cluster-name") + 15 //15 indicates 15 letters in --cluster-name string with space or equal |
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.
Please see if we could use valid regex instead.
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.
Not as a part of this PR but we should use cli
parser (like github.com/urfave/cli) to parse BotKube commands.
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.
added regex
5121cea
to
0fc5eba
Compare
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.
LGTM
pkg/utils/utils.go
Outdated
r, _ := regexp.Compile(`--cluster-name[=|' ']([^\s]*)`) | ||
//this gives 2 match with cluster name and without | ||
matchedArray := r.FindStringSubmatch(cmd) | ||
var s string = "" |
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.
Minor:
var s string = "" | |
var s string |
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.
done
This commit fix the bug 230 which shows redundant error message
when deployed in miticluster, added check for cluster name and
created new function to get cluster name from kubectl command