未验证 提交 dc595145 编写于 作者: T Thomas Strömberg 提交者: GitHub

Merge pull request #8872 from kadern0/issue-8857

Running internal kubectl command when minikube is called as 'kubectl'
......@@ -20,6 +20,7 @@ import (
goflag "flag"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
......@@ -74,6 +75,11 @@ var RootCmd = &cobra.Command{
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
_, callingCmd := filepath.Split(os.Args[0])
if callingCmd == "kubectl" {
os.Args = append([]string{RootCmd.Use, callingCmd}, os.Args[1:]...)
}
for _, c := range RootCmd.Commands() {
c.Short = translate.T(c.Short)
c.Long = translate.T(c.Long)
......
......@@ -29,3 +29,8 @@ minikube's bootstrapper, [Kubeadm](https://github.com/kubernetes/kubeadm) verifi
Please allocate sufficient resources for Knative setup using minikube, especially when you run a minikube cluster on your local machine. We recommend allocating at least 6 CPUs and 8G memory.
`minikube start --cpus 6 --memory 8000`
## Do I need to install kubectl locally?
No, minikube comes with built-in kubectl [see minikube's kubectl documentation]({{< ref "docs/handbook/kubectl.md" >}}).
......@@ -17,6 +17,10 @@ as well.
You can also `alias kubectl="minikube kubectl --"` for easier usage.
Alternatively, you can create a symbolic link to minikube's binary named 'kubectl'.
`ln -s $(which minikube) /usr/local/bin/kubectl`
Get pods
`minikube kubectl -- get pods`
......
......@@ -87,6 +87,7 @@ func TestFunctional(t *testing.T) {
{"KubectlGetPods", validateKubectlGetPods}, // Make sure apiserver is up
{"CacheCmd", validateCacheCmd}, // Caches images needed for subsequent tests because of proxy
{"MinikubeKubectlCmd", validateMinikubeKubectl}, // Make sure `minikube kubectl` works
{"MinikubeKubectlCmdDirectly", validateMinikubeKubectlDirectCall},
}
for _, tc := range tests {
tc := tc
......@@ -315,6 +316,26 @@ func validateMinikubeKubectl(ctx context.Context, t *testing.T, profile string)
}
}
// validateMinikubeKubectlDirectCall validates that calling minikube's kubectl
func validateMinikubeKubectlDirectCall(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)
dir := filepath.Dir(Target())
dstfn := filepath.Join(dir, "kubectl")
err := os.Link(Target(), dstfn)
if err != nil {
t.Fatal(err)
}
defer os.Remove(dstfn) // clean up
kubectlArgs := []string{"get", "pods"}
rr, err := Run(t, exec.CommandContext(ctx, dstfn, kubectlArgs...))
if err != nil {
t.Fatalf("failed to run kubectl directl. args %q: %v", rr.Command(), err)
}
}
// validateComponentHealth asserts that all Kubernetes components are healthy
func validateComponentHealth(ctx context.Context, t *testing.T, profile string) {
defer PostMortemLogs(t, profile)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册