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

Query for resources that do not exist in all clusters fail hard when using json output #25

Open
robert-heinzmann-logmein opened this issue Jun 1, 2022 · 0 comments

Comments

@robert-heinzmann-logmein
Copy link
Contributor

When querying clusters using json output, where some explicit k8s resource does not exist, the kubectl mc command failes hard.

It would be cool if the command would reflect the issue with a non zero return code (possibly with a documented, dedicated error code if not all contexts could be queried successfully (endpoint down)e.g. to use this in scripts that ) but still reports the resorces found in json (so that it can be used for discovery jobs like "does ingress myingress exist in all clusters?" ).

Situation

  • 3 contexts configured in kubeconfig
  • resource myingress does exist in context1 and context2 but not in context3
shell$ kubectl mc -o json -- get ingress -n mynamespace myingress
Error: couldn't parse this output. Are you sure your kubectl command allows for json output? Run command with -d to see debug output

Same is true if I target the context3 explicitly

shell$ kubectl mc -r context3 -o json -- get ingress -n mynamespace myingress
Error: couldn't parse this output. Are you sure your kubectl command allows for json output? Run command with -d to see debug output

Debug output:

# myingress does not exist on cluster3
shell$ kubectl mc -o json -r context3 -d -- get ingress -n namespace myingress
2022-06-01T13:57:44.368+0200    DEBUG   mc/mc.go:153    preparing wait group    {"max-processes": 5}
2022-06-01T13:57:44.372+0200    DEBUG   mc/mc.go:165    start wait group
2022-06-01T13:57:44.373+0200    DEBUG   mc/mc.go:178    waiting for next free spot      {"context": "context3", "namespace": ""}
2022-06-01T13:57:44.373+0200    DEBUG   mc/mc.go:180    executing       {"context": "context3", "namespace": ""}
2022-06-01T13:57:50.982+0200    DEBUG   mc/mc.go:171    wait group finished
2022-06-01T13:57:50.983+0200    DEBUG   mc/mc.go:186    parsing output...
2022-06-01T13:57:50.983+0200    DEBUG   mc/mc.go:189    failed to parse output  {"retrieved": "map[context3:]"}
Error: couldn't parse this output. Are you sure your kubectl command allows for json output? Run command with -d to see debug output
  • Doing the same without a resource selector does work
# works
shell$ kubectl mc -o json -r context3 -d -- get ingress -n namespace
  • Doing the same with default output (non json) works too
# works
shell$ kubectl mc -o json -r context3 -d -- get ingress -n nonexistingnamespace 
  • Doing the same without a resource and with a namespace that does not exist does not fail.
shell$ kubectl mc -o json -- get ingress -n nonexistingnamespace myingress
...
  "context1": {
    "apiVersion": "v1",
    "items": [],
    "kind": "List",
    "metadata": {
      "resourceVersion": "",
      "selfLink": ""
    }
  },
  "context2": {
    "apiVersion": "v1",
    "items": [],
    "kind": "List",
    "metadata": {
      "resourceVersion": "",
      "selfLink": ""
    }
  }
  ....
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

1 participant