From 73bfdf949eba3ecb79c8b9a0066ae2336acd1222 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 10 Feb 2016 12:26:46 -0800 Subject: [PATCH 1/2] fix(dm-install): do not require a namespace on kubectl create When trying to create a new namespace, specifying a namespace will error --- dm/install.go | 2 +- dm/uninstall.go | 2 +- kubectl/create.go | 12 ++---------- kubectl/create_test.go | 4 ++-- kubectl/delete.go | 11 ++--------- kubectl/kubectl.go | 6 +++--- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/dm/install.go b/dm/install.go index f2a70163d..e1290b29d 100644 --- a/dm/install.go +++ b/dm/install.go @@ -10,7 +10,7 @@ import ( // Returns the string output received from the operation, and an error if the // command failed. func Install(runner kubectl.Runner) (string, error) { - o, err := runner.Create([]byte(InstallYAML), "dm") + o, err := runner.Create([]byte(InstallYAML)) return string(o), err } diff --git a/dm/uninstall.go b/dm/uninstall.go index 675ebdb73..4bd6b8c71 100644 --- a/dm/uninstall.go +++ b/dm/uninstall.go @@ -9,6 +9,6 @@ import ( // Returns the string output received from the operation, and an error if the // command failed. func Uninstall(runner kubectl.Runner) (string, error) { - o, err := runner.Delete("dm", "Namespace", "dm") + o, err := runner.Delete("dm", "Namespace") return string(o), err } diff --git a/kubectl/create.go b/kubectl/create.go index bd903b740..af9297aa9 100644 --- a/kubectl/create.go +++ b/kubectl/create.go @@ -1,13 +1,9 @@ package kubectl // Create uploads a chart to Kubernetes -func (r RealRunner) Create(stdin []byte, ns string) ([]byte, error) { +func (r RealRunner) Create(stdin []byte) ([]byte, error) { args := []string{"create", "-f", "-"} - if ns != "" { - args = append([]string{"--namespace=" + ns}, args...) - } - cmd := command(args...) assignStdin(cmd, stdin) @@ -15,13 +11,9 @@ func (r RealRunner) Create(stdin []byte, ns string) ([]byte, error) { } // Create returns the commands to kubectl -func (r PrintRunner) Create(stdin []byte, ns string) ([]byte, error) { +func (r PrintRunner) Create(stdin []byte) ([]byte, error) { args := []string{"create", "-f", "-"} - if ns != "" { - args = append([]string{"--namespace=" + ns}, args...) - } - cmd := command(args...) assignStdin(cmd, stdin) diff --git a/kubectl/create_test.go b/kubectl/create_test.go index 0623769d7..bca94f6e5 100644 --- a/kubectl/create_test.go +++ b/kubectl/create_test.go @@ -7,9 +7,9 @@ import ( func TestPrintCreate(t *testing.T) { var client Runner = PrintRunner{} - expected := `[CMD] kubectl --namespace=default-namespace create -f - < some stdin data` + expected := `[CMD] kubectl create -f - < some stdin data` - out, err := client.Create([]byte("some stdin data"), "default-namespace") + out, err := client.Create([]byte("some stdin data")) if err != nil { t.Error(err) } diff --git a/kubectl/delete.go b/kubectl/delete.go index 903442585..52874cfbb 100644 --- a/kubectl/delete.go +++ b/kubectl/delete.go @@ -1,25 +1,18 @@ package kubectl // Delete removes a chart from Kubernetes. -func (r RealRunner) Delete(name, ktype, ns string) ([]byte, error) { +func (r RealRunner) Delete(name, ktype string) ([]byte, error) { args := []string{"delete", ktype, name} - if ns != "" { - args = append([]string{"--namespace=" + ns}, args...) - } return command(args...).CombinedOutput() } // Delete returns the commands to kubectl -func (r PrintRunner) Delete(name, ktype, ns string) ([]byte, error) { +func (r PrintRunner) Delete(name, ktype string) ([]byte, error) { args := []string{"delete", ktype, name} - if ns != "" { - args = append([]string{"--namespace=" + ns}, args...) - } - cmd := command(args...) return []byte(cmd.String()), nil } diff --git a/kubectl/kubectl.go b/kubectl/kubectl.go index 0e51169a4..a85ca6128 100644 --- a/kubectl/kubectl.go +++ b/kubectl/kubectl.go @@ -8,11 +8,11 @@ type Runner interface { // ClusterInfo returns Kubernetes cluster info ClusterInfo() ([]byte, error) // Create uploads a chart to Kubernetes - Create([]byte, string) ([]byte, error) + Create(stdin []byte) ([]byte, error) // Delete removes a chart from Kubernetes. - Delete(string, string, string) ([]byte, error) + Delete(name string, ktype string) ([]byte, error) // Get returns Kubernetes resources - Get([]byte, string) ([]byte, error) + Get(stdin []byte, ns string) ([]byte, error) // GetByKind gets an entry by kind, name, and namespace. // From 838d5c0401dcedf9d54da73a1bb56129016f3fb7 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 10 Feb 2016 12:30:46 -0800 Subject: [PATCH 2/2] chore(spelling): s/primative/primitive/ --- dm/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm/client.go b/dm/client.go index b95a59356..217508b05 100644 --- a/dm/client.go +++ b/dm/client.go @@ -103,7 +103,7 @@ func (c *Client) CallService(path, method, action string, dest interface{}, read return nil } -// callHTTP is a low-level primative for executing HTTP operations. +// callHTTP is a low-level primitive for executing HTTP operations. func (c *Client) callHTTP(path, method, action string, reader io.ReadCloser) (string, error) { request, err := http.NewRequest(method, path, reader)