Merge pull request #42737 from fabianofranz/issues_42697

Automatic merge from submit-queue (batch tested with PRs 42211, 38691, 42737, 42757, 42754)

Fix failing kubectl skew tests

Fixes https://github.com/kubernetes/kubernetes/issues/42697

Skew kubectl tests [are broken](https://k8s-testgrid.appspot.com/release-1.6-upgrade-skew#gce-1.6-master-cvm-kubectl-skew&width=80) in "Simple pod should handle in-cluster config" for trying to copy the `kubectl.sh` script instead of the actual `kubectl` binary.


**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-03-08 18:52:28 -08:00 committed by GitHub
commit 6b36b3aa20
2 changed files with 21 additions and 5 deletions

View File

@ -68,4 +68,10 @@ if false; then
echo "Running:" "${kubectl}" "${config[@]:+${config[@]}}" "${@+$@}" >&2
fi
if [[ "${1:-}" =~ ^(path)$ ]]; then
echo "${kubectl}"
exit 0
fi
"${kubectl}" "${config[@]:+${config[@]}}" "${@+$@}"

View File

@ -590,19 +590,29 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
By("overriding icc with values provided by flags")
kubectlPath := framework.TestContext.KubectlPath
// we need the actual kubectl binary, not the script wrapper
kubectlPathNormalizer := exec.Command("which", kubectlPath)
if strings.HasSuffix(kubectlPath, "kubectl.sh") {
kubectlPathNormalizer = exec.Command("sh", "-c", kubectlPath, "path")
}
kubectlPathNormalized, err := kubectlPathNormalizer.Output()
framework.ExpectNoError(err)
kubectlPath = strings.TrimSpace(string(kubectlPathNormalized))
inClusterHost := strings.TrimSpace(framework.RunHostCmdOrDie(ns, simplePodName, "printenv KUBERNETES_SERVICE_HOST"))
inClusterPort := strings.TrimSpace(framework.RunHostCmdOrDie(ns, simplePodName, "printenv KUBERNETES_SERVICE_PORT"))
framework.RunKubectlOrDie("cp", kubectlPath, ns+"/"+simplePodName+":/")
framework.Logf("copying %s to the %s pod", kubectlPath, simplePodName)
framework.RunKubectlOrDie("cp", kubectlPath, ns+"/"+simplePodName+":/tmp/")
By("getting pods with in-cluster configs")
execOutput := framework.RunHostCmdOrDie(ns, simplePodName, "/kubectl get pods")
execOutput := framework.RunHostCmdOrDie(ns, simplePodName, "/tmp/kubectl get pods")
if matched, err := regexp.MatchString("nginx +1/1 +Running", execOutput); err != nil || !matched {
framework.Failf("Unexpected kubectl exec output: ", execOutput)
}
By("trying to use kubectl with invalid token")
_, err = framework.RunHostCmd(ns, simplePodName, "/kubectl get pods --token=invalid --v=7 2>&1")
_, err = framework.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --token=invalid --v=7 2>&1")
framework.Logf("got err %v", err)
Expect(err).To(HaveOccurred())
Expect(err).To(ContainSubstring("Using in-cluster namespace"))
@ -611,14 +621,14 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
Expect(err).To(ContainSubstring("Response Status: 401 Unauthorized"))
By("trying to use kubectl with invalid server")
_, err = framework.RunHostCmd(ns, simplePodName, "/kubectl get pods --server=invalid --v=6 2>&1")
_, err = framework.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --server=invalid --v=6 2>&1")
framework.Logf("got err %v", err)
Expect(err).To(HaveOccurred())
Expect(err).To(ContainSubstring("Unable to connect to the server"))
Expect(err).To(ContainSubstring("GET http://invalid/api"))
By("trying to use kubectl with invalid namespace")
output, _ := framework.RunHostCmd(ns, simplePodName, "/kubectl get pods --namespace=invalid --v=6 2>&1")
output, _ := framework.RunHostCmd(ns, simplePodName, "/tmp/kubectl get pods --namespace=invalid --v=6 2>&1")
Expect(output).To(ContainSubstring("No resources found"))
Expect(output).ToNot(ContainSubstring("Using in-cluster namespace"))
Expect(output).To(ContainSubstring("Using in-cluster configuration"))