Skip to content
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

[Idea] Being able to find clusters/contexts that have a matching k8s resource #15

Open
sunny-b opened this issue Jan 17, 2023 · 3 comments

Comments

@sunny-b
Copy link

sunny-b commented Jan 17, 2023

So I forked this and added a feature that my team has been wanting, which is a command that allows you to find a context that contains a K8s resource we're looking for. This often comes up during oncall issues where a service or deployment is acting strange but we don't know where it's located.

Ex. kubectl foreach -- find svc foo -n bar

This would return any and all contexts that contain this resource. Not sure if this is something you'd be interested in for upstream or find useful, but figured I'll bring it up.

@ahmetb
Copy link
Owner

ahmetb commented Jan 17, 2023

I don't understand how it works. Aren’t you shelling out to a "find" plugin?

@sunny-b
Copy link
Author

sunny-b commented Feb 14, 2023

No, I changed the code so that if it detected the find command after the --, it converts it to a get. So find svc foo -n bar would turn into get svc foo -n bar, but it would also go down a different find workflow where it would only output the kube contexts where the get query returned something.

I.E.

$ kubectl foreach -- find svc foo -n bar
stage-cluster
production-cluster

kubectl-foreach/main.go

Lines 223 to 226 in 87284f2

if args[1] == "find" || kubeContextsOnly {
args[1] = "get"
return runFind(ctx, args, kctx)
}

func runFind(ctx context.Context, args []string, kubeContext string) (err error) {

@ahmetb
Copy link
Owner

ahmetb commented Feb 14, 2023

Interesting, so it's like | awk '{print $1}'|sort |uniq in this case? What would the use case for this be other than passing it to some other tool?

I didn't design foreach to have parseable output (though, it is possible) and I think find would be a case that's specific to get? If there's a more generalizable pattern here, I'd be happy to give it a shot.

But right now I think just seeing foreach -- get output gives me a good sense of which clusters is something is running on, along with their STATUS, AGE etc (from kubectl default print columns).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants