From 10a3f2e2a8711827a2339855411a2bb7979026d0 Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Wed, 29 Jul 2020 11:48:58 +1000 Subject: [PATCH 1/7] Running internal kubectl command when minikube is called as 'kubectl' Fixes issue #8857 Signed-off-by: Pablo Caderno --- cmd/minikube/cmd/root.go | 5 +++++ site/content/en/docs/faq/_index.md | 5 +++++ site/content/en/docs/handbook/kubectl.md | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 0128b1a8fdbd..5fcfeafb6709 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -20,6 +20,7 @@ import ( goflag "flag" "fmt" "os" + "path/filepath" "runtime" "strings" @@ -73,6 +74,10 @@ 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{"minikube", callingCmd}, os.Args[1:]...) + } for _, c := range RootCmd.Commands() { c.Short = translate.T(c.Short) c.Long = translate.T(c.Long) diff --git a/site/content/en/docs/faq/_index.md b/site/content/en/docs/faq/_index.md index 0eb2a1b28837..7e3219b98f01 100644 --- a/site/content/en/docs/faq/_index.md +++ b/site/content/en/docs/faq/_index.md @@ -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"}}). + diff --git a/site/content/en/docs/handbook/kubectl.md b/site/content/en/docs/handbook/kubectl.md index 5f21ff4f206a..21532287d37c 100644 --- a/site/content/en/docs/handbook/kubectl.md +++ b/site/content/en/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` From cef213962957c9eca7b66faf3586cfbd249237cd Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Mon, 17 Aug 2020 12:52:21 +1000 Subject: [PATCH 2/7] Added integration test Signed-off-by: Pablo Caderno --- test/integration/functional_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index e2a82a726a0a..487585bfe1b5 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -24,6 +24,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + // "io" "net/http" "net/url" "os" @@ -86,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 @@ -307,6 +309,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{"-p", profile, "--", "--context", profile, "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) From 9708036592f9cc5732b0fd530bb67f7d2bcf8669 Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Mon, 17 Aug 2020 21:20:50 +1000 Subject: [PATCH 3/7] Updated default cmd string when minikube is run as kubectl Signed-off-by: Pablo Caderno --- cmd/minikube/cmd/root.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 5fcfeafb6709..695b5ccf89eb 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -75,8 +75,9 @@ var RootCmd = &cobra.Command{ // 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{"minikube", callingCmd}, os.Args[1:]...) + os.Args = append([]string{RootCmd.Use, callingCmd}, os.Args[1:]...) } for _, c := range RootCmd.Commands() { c.Short = translate.T(c.Short) From 30b4f202c61776177bcdef0079466682ee98ef07 Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Mon, 17 Aug 2020 21:26:26 +1000 Subject: [PATCH 4/7] Go fmtd imports Signed-off-by: Pablo Caderno --- test/integration/functional_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 487585bfe1b5..21ecc2f15eb8 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -87,7 +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}, + {"MinikubeKubectlCmdDirectly", validateMinikubeKubectlDirectCall}, } for _, tc := range tests { tc := tc From 07daab51e3ff8feeebf1a278b65726bde102d191 Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Mon, 17 Aug 2020 21:34:17 +1000 Subject: [PATCH 5/7] Go fmtd functional tests file Signed-off-by: Pablo Caderno --- test/integration/functional_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 21ecc2f15eb8..3dda8c143b34 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -24,7 +24,6 @@ import ( "encoding/json" "fmt" "io/ioutil" - // "io" "net/http" "net/url" "os" From 7f7fd8d57cdbb888c8c6bd1f6b3f134d66229d1f Mon Sep 17 00:00:00 2001 From: Pablo Caderno Date: Mon, 17 Aug 2020 22:18:50 +1000 Subject: [PATCH 6/7] Updated kubectl args Signed-off-by: Pablo Caderno --- test/integration/functional_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 3dda8c143b34..a85e1b4e1b0f 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -320,7 +320,7 @@ func validateMinikubeKubectlDirectCall(ctx context.Context, t *testing.T, profil } defer os.Remove(dstfn) // clean up - kubectlArgs := []string{"-p", profile, "--", "--context", profile, "get", "pods"} + 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) From 951241801806caa1ce8bcb67e480fccf0b804984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Str=C3=B6mberg?= Date: Tue, 1 Sep 2020 16:28:41 -0700 Subject: [PATCH 7/7] Fix broken }}).