Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Fix some more "verify" issues
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Davis <[email protected]>
  • Loading branch information
Doug Davis authored and MHBauer committed Aug 9, 2017
1 parent 77fe796 commit 935494b
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 17 deletions.
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/

22 changes: 19 additions & 3 deletions plugin/cmd/kubectl/bind-service/bind-service.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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() {
Expand All @@ -22,7 +38,7 @@ func main() {
}

if len(os.Args) != 4 {
utils.Exit1(USAGE)
utils.Exit1(usage)
}

binding := v1alpha1.Binding{}
Expand All @@ -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())
}
Expand Down
20 changes: 18 additions & 2 deletions plugin/cmd/kubectl/create-service-broker/create-service-broker.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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() {
Expand All @@ -21,7 +37,7 @@ func main() {
}

if len(os.Args) != 3 {
utils.Exit1(USAGE)
utils.Exit1(usage)
}

broker := v1alpha1.Broker{}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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() {
Expand All @@ -21,7 +37,7 @@ func main() {
}

if len(os.Args) != 5 {
utils.Exit1(USAGE)
utils.Exit1(usage)
}

instance := v1alpha1.Instance{}
Expand All @@ -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())
}
Expand Down
19 changes: 19 additions & 0 deletions plugin/cmd/kubectl/utils/table_printer.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -6,6 +22,7 @@ import (
"text/tabwriter"
)

// Table defines a tabular output - obviously in table format
type Table struct {
headers []string
rows [][]string
Expand All @@ -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

Expand Down
22 changes: 22 additions & 0 deletions plugin/cmd/kubectl/utils/ui.go
Original file line number Diff line number Diff line change
@@ -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"))
}
29 changes: 27 additions & 2 deletions plugin/cmd/kubectl/utils/utils.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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 == "" {
Expand All @@ -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)
Expand Down

0 comments on commit 935494b

Please sign in to comment.