gruntwork-io / terratest

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
https://terratest.gruntwork.io/
Apache License 2.0
7.46k stars 1.32k forks source link

k8s: flags cannot be placed before plugin name: --kubeconfig #809

Open niedbalski opened 3 years ago

niedbalski commented 3 years ago

Due to https://github.com/kubernetes/kubernetes/commit/7a2e5af11d6ca1cd9f66f5a1e65fe4773b755fb2

When trying to run:

output, err := k8s.RunKubectlAndGetOutputE(suite.T(), suite.k8sOptions, "exec -ti elasticsearch-master-0 curl -I http://localhost:9200/fluentbit/_search/")

I get the following error:

Running command kubectl with args [--kubeconfig /tmp/client.config --namespace cs8vyi exec -ti elasticsearch-master-0 curl -I http://localhost:9200/fluentbit/_search/] 2021-03-15T13:27:03-03:00 logger.go:66: Error: flags cannot be placed before plugin name: --kubeconfig Error: flags cannot be placed before plugin name: --kubeconfig error while running command: exit status 1; Error: flags cannot be placed before plugin name: --kubeconfig

cbuto commented 3 years ago

@niedbalski Not a maintainer but I think you might be able to get this working by doing:

output, err := k8s.RunKubectlAndGetOutputE(suite.T(), suite.k8sOptions, "exec", "elasticsearch-master-0", "--", "curl", "-I", "http://localhost:9200/fluentbit/_search/")

kubectl exec isn't a plugin but I think the way the arguments were being passed to kubectl, it was interpreting this entire string as the subcommand exec -ti elasticsearch-master-0 curl -I http://localhost:9200/fluentbit/_search/.

However, I was testing running kubectl plugins with k8s.RunKubectlAndGetOutputE and I saw the error you mentioned with v1.21.0-beta.1... so it will still need to be fixed.