mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-29 21:01:02 +00:00
In-cluster configs must take flag overrides into account
This commit is contained in:
@@ -564,6 +564,48 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
|
||||
framework.Failf("Container port output missing expected value. Wanted:'%s', got: %s", nginxDefaultOutput, body)
|
||||
}
|
||||
})
|
||||
|
||||
It("should handle in-cluster config", func() {
|
||||
By("overriding icc with values provided by flags")
|
||||
kubectlPath := framework.TestContext.KubectlPath
|
||||
|
||||
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+":/")
|
||||
|
||||
By("getting pods with in-cluster configs")
|
||||
execOutput := framework.RunHostCmdOrDie(ns, simplePodName, "/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")
|
||||
framework.Logf("got err %v", err)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err).To(ContainSubstring("User \"system:anonymous\" cannot list pods in the namespace"))
|
||||
Expect(err).To(ContainSubstring("Using in-cluster namespace"))
|
||||
Expect(err).To(ContainSubstring("Using in-cluster configuration"))
|
||||
Expect(err).To(ContainSubstring("Authorization: Bearer invalid"))
|
||||
Expect(err).To(ContainSubstring("Response Status: 403 Forbidden"))
|
||||
|
||||
By("trying to use kubectl with invalid server")
|
||||
_, err = framework.RunHostCmd(ns, simplePodName, "/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")
|
||||
Expect(output).To(ContainSubstring("No resources found"))
|
||||
Expect(output).ToNot(ContainSubstring("Using in-cluster namespace"))
|
||||
Expect(output).To(ContainSubstring("Using in-cluster configuration"))
|
||||
if matched, _ := regexp.MatchString(fmt.Sprintf("GET http[s]?://%s:%s/api/v1/namespaces/invalid/pods", inClusterHost, inClusterPort), output); !matched {
|
||||
framework.Failf("Unexpected kubectl exec output: ", output)
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
framework.KubeDescribe("Kubectl api-versions", func() {
|
||||
|
||||
Reference in New Issue
Block a user