-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add filtering contexts #432
Conversation
@@ -40,6 +40,16 @@ func parseArgs(argv []string) Op { | |||
return ListOp{} | |||
} | |||
|
|||
if argv[0] == "--list" || argv[0] == "-l" { |
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.
The call will be kubectx --list cluster=c1
so it does not collide with any existing functionality
@@ -44,7 +44,7 @@ func (k *Kubeconfig) contextNode(name string) (*yaml.Node, error) { | |||
return nil, errors.Errorf("context with name \"%s\" not found", name) | |||
} | |||
|
|||
func (k *Kubeconfig) ContextNames() []string { | |||
func (k *Kubeconfig) ContextNames(filters map[string]string) []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.
I'm open to suggestions how you want to handle optional parameters, be it a struct, separate function, or anything else
@@ -54,8 +54,19 @@ func (k *Kubeconfig) ContextNames() []string { | |||
} | |||
|
|||
var ctxNames []string | |||
ctxLoop: |
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 believe this could be refactored to avoid syntax that feels like a goto
to me, maybe having the filtering as a separate function instead of a nested loop. I'm open to suggestions
@ahmetb is this functionality something you'd even consider merging? We'll work on something on our end if it's not a good fit |
Have you tried the fzf integration in kubectx? I think it does a lot of what you're trying to achieve here without us having to maintain extra code. |
If I understand correctly,
I'm not sure how to utilize |
Sorry but kubectx isn't meant to be scripted around. This is explained in the README. :) We dont provide a guaranteed output format. Use kubectl directly for that. |
All right, thank you for your time! |
In our work we're using separate contexts for each shop we're running. We have a custom tool that automates running same commands across multiple apps, it boils down to being a fancy
for
loop overkubectx
's contexts :) Lately we've found ourselves in a situation we need to be able to run things across all shops but only within one cluster. To keep shop vs cluster configuration in one place we thought it'd be nice ifkubectx
could filter contexts for us, thus this PR.Disclaimer: this is very first time I've written in Go so I could have misplaced/misnamed/missed some obvious stuff. I'll be updating this PR with all suggestions you may have