diff --git a/Makefile b/Makefile index e4d8dbb61d6..34fad8da9b8 100644 --- a/Makefile +++ b/Makefile @@ -291,7 +291,6 @@ clean: clean-bin clean-build-image clean-generated clean-coverage clean-bin: rm -rf $(BINDIR) rm -f .generate_exes - rm -f $(PLUGINS) clean-build-image: rm -rf .pkg @@ -412,25 +411,23 @@ $(BINDIR)/bind-service/bind-service: \ plugin/cmd/kubectl/bind-service/bind-service.go \ plugin/cmd/kubectl/bind-service/plugin.yaml rm -rf $(BINDIR)/bind-service - mkdir $(BINDIR)/bind-service $(DOCKER_CMD) go build -o $@ $< - cp plugin/cmd/kubectl/bind-service/*yaml $(BINDIR)/bind-service/ + $(DOCKER_CMD) cp plugin/cmd/kubectl/bind-service/*yaml \ + $(BINDIR)/bind-service/ $(BINDIR)/create-service-broker/create-service-broker: \ plugin/cmd/kubectl/create-service-broker/create-service-broker.go \ plugin/cmd/kubectl/create-service-broker/plugin.yaml rm -rf $(BINDIR)/create-service-broker - mkdir $(BINDIR)/create-service-broker $(DOCKER_CMD) go build -o $@ $< - cp plugin/cmd/kubectl/create-service-broker/*yaml \ + $(DOCKER_CMD) cp plugin/cmd/kubectl/create-service-broker/*yaml \ $(BINDIR)/create-service-broker/ $(BINDIR)/create-service-instance/create-service-instance: \ plugin/cmd/kubectl/create-service-instance/create-service-instance.go \ plugin/cmd/kubectl/create-service-instance/plugin.yaml rm -rf $(BINDIR)/create-service-instance - mkdir $(BINDIR)/create-service-instance $(DOCKER_CMD) go build -o $@ $< - cp plugin/cmd/kubectl/create-service-instance/*yaml \ + $(DOCKER_CMD) cp plugin/cmd/kubectl/create-service-instance/*yaml \ $(BINDIR)/create-service-instance/ diff --git a/plugin/cmd/kubectl/bind-service/bind-service.go b/plugin/cmd/kubectl/bind-service/bind-service.go index a43c5343886..77a75db94fd 100644 --- a/plugin/cmd/kubectl/bind-service/bind-service.go +++ b/plugin/cmd/kubectl/bind-service/bind-service.go @@ -1,3 +1,19 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package main import ( @@ -12,7 +28,7 @@ import ( "k8s.io/client-go/rest" ) -const USAGE = `Usage: +const usage = `Usage: kubectl plugin bind-service INSTANCE_NAME BINDING_NAME NAMESPACE` func main() { @@ -22,7 +38,7 @@ func main() { } if len(os.Args) != 4 { - utils.Exit1(USAGE) + utils.Exit1(usage) } binding := v1alpha1.Binding{} @@ -34,7 +50,7 @@ func main() { } binding.Spec.SecretName = os.Args[2] - fmt.Printf("Looking up Namespace %s...\n", utils.Entity(binding.Name)) + fmt.Printf("Looking up Namespace %s...\n", utils.Entity(binding.Namespace)) if err := utils.CheckNamespaceExists(binding.Namespace); err != nil { utils.Exit1(err.Error()) } diff --git a/plugin/cmd/kubectl/create-service-broker/create-service-broker.go b/plugin/cmd/kubectl/create-service-broker/create-service-broker.go index b06c72b23d9..26d20085706 100644 --- a/plugin/cmd/kubectl/create-service-broker/create-service-broker.go +++ b/plugin/cmd/kubectl/create-service-broker/create-service-broker.go @@ -1,3 +1,19 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package main import ( @@ -11,7 +27,7 @@ import ( "k8s.io/client-go/rest" ) -const USAGE = `Usage: +const usage = `Usage: kubectl plugin create-service-broker BROKER_NAME BROKER_URL` func main() { @@ -21,7 +37,7 @@ func main() { } if len(os.Args) != 3 { - utils.Exit1(USAGE) + utils.Exit1(usage) } broker := v1alpha1.Broker{} diff --git a/plugin/cmd/kubectl/create-service-instance/create-service-instance.go b/plugin/cmd/kubectl/create-service-instance/create-service-instance.go index 1f5d4e06cee..5c4c622c024 100644 --- a/plugin/cmd/kubectl/create-service-instance/create-service-instance.go +++ b/plugin/cmd/kubectl/create-service-instance/create-service-instance.go @@ -1,3 +1,19 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package main import ( @@ -11,7 +27,7 @@ import ( "k8s.io/client-go/rest" ) -const USAGE = `Usage: +const usage = `Usage: kubectl plugin create-service-instance SERVICE_CLASS_NAME PLAN_NAME INSTANCE_NAME NAMESPACE` func main() { @@ -21,7 +37,7 @@ func main() { } if len(os.Args) != 5 { - utils.Exit1(USAGE) + utils.Exit1(usage) } instance := v1alpha1.Instance{} @@ -31,7 +47,7 @@ func main() { instance.Spec.PlanName = os.Args[2] instance.Spec.ServiceClassName = os.Args[1] - fmt.Printf("Looking up Namespace %s...\n", utils.Entity(instance.Name)) + fmt.Printf("Looking up Namespace %s...\n", utils.Entity(instance.Namespace)) if err := utils.CheckNamespaceExists(instance.Namespace); err != nil { utils.Exit1(err.Error()) } diff --git a/plugin/cmd/kubectl/utils/table_printer.go b/plugin/cmd/kubectl/utils/table_printer.go index f2cd65a274a..08da20aad41 100644 --- a/plugin/cmd/kubectl/utils/table_printer.go +++ b/plugin/cmd/kubectl/utils/table_printer.go @@ -1,3 +1,19 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package utils import ( @@ -6,6 +22,7 @@ import ( "text/tabwriter" ) +// Table defines a tabular output - obviously in table format type Table struct { headers []string rows [][]string @@ -18,10 +35,12 @@ func NewTable(headers ...string) *Table { } } +// AddRow will append the specified row to the table func (t *Table) AddRow(row ...string) { t.rows = append(t.rows, row) } +// Print prints the table to the screen func (t *Table) Print() error { padding := 3 diff --git a/plugin/cmd/kubectl/utils/ui.go b/plugin/cmd/kubectl/utils/ui.go index 1e6daca0e87..531982ff11d 100644 --- a/plugin/cmd/kubectl/utils/ui.go +++ b/plugin/cmd/kubectl/utils/ui.go @@ -1,22 +1,44 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package utils import "fmt" +// Green will print the specified string in green text func Green(str string) string { return fmt.Sprintf("\x1b[32;1m%s\x1b[0m", str) } +// Red will print the specified string in red text func Red(str string) string { return fmt.Sprintf("\x1b[31;1m%s\x1b[0m", str) } +// Entity will print the specified string in bold text func Entity(str string) string { return fmt.Sprintf("\x1b[36;1m%s\x1b[0m", str) } +// Error will print the specified error string in red text func Error(msg string) { fmt.Printf("%s\n\n%s\n\n", Red("ERROR"), msg) } + +// Ok will print "OK" in green func Ok() { fmt.Printf("%s\n\n", Green("OK")) } diff --git a/plugin/cmd/kubectl/utils/utils.go b/plugin/cmd/kubectl/utils/utils.go index 7fb84ea6c7a..693ce29336a 100644 --- a/plugin/cmd/kubectl/utils/utils.go +++ b/plugin/cmd/kubectl/utils/utils.go @@ -1,3 +1,19 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package utils import ( @@ -18,6 +34,8 @@ type metadata struct { Name string `json:"name"` } +// CheckNamespaceExists will query our kube apiserver to see if the +// specified namespace exists - if not it returns an error func CheckNamespaceExists(name string) error { proxyURL := "http://127.0.0.1" proxyPort := "8881" @@ -36,10 +54,14 @@ func CheckNamespaceExists(name string) error { resp, err := http.Get(fmt.Sprintf("%s:%s/api/v1/namespaces/%s", proxyURL, proxyPort, name)) if err != nil { - fmt.Errorf("Error looking up namespace from core api server (%s)", err) + return fmt.Errorf("Error looking up namespace from core api server (%s)", err) } - defer resp.Body.Close() + defer func() { + if resp.Body != nil { + resp.Body.Close() + } + }() body, err := ioutil.ReadAll(resp.Body) if err != nil { return fmt.Errorf("Error retrieving core api server response body during namespace lookup (%s)", err) @@ -58,6 +80,7 @@ func CheckNamespaceExists(name string) error { return nil } +// SCUrlEnv will return the value of the SERVICE_CATALOG_URL env var func SCUrlEnv() string { url := os.Getenv("SERVICE_CATALOG_URL") if url == "" { @@ -66,6 +89,8 @@ func SCUrlEnv() string { return url } +// Exit1 will print the specified error string to the screen and +// then stop the program, with an exit code of 1 func Exit1(errStr string) { Error(errStr) os.Exit(1)