MVP Plugins for Service-Catalog Interaction #1621
Changes from 19 commits
d0f3881
2642f9d
833f379
807c7b3
a7b5086
bf4dedd
8d1cf3e
a81afa9
8113214
412c1b2
74e55b4
a84e54f
dd3eb7d
ffbbf61
2a41027
9d3e5bd
0586082
fe0b140
f8e9aa0
3ca40a8
59c3bc4
fa9fbce
fba2ea0
961883c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2017 |
||
|
||
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 ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/kubectl/client" | ||
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/kubectl/utils" | ||
) | ||
|
||
const usage = `Usage: | ||
kubectl plugin binding SUBCOMMAND | ||
|
||
Available subcommands: | ||
list | ||
get | ||
` | ||
|
||
const listUsage = `Usage: | ||
kubectl plugin binding list NAMESPACE | ||
` | ||
|
||
const getUsage = `Usage: | ||
kubectl plugin binding get NAMESPACE INSTANCENAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor thing, but INSTANCENAME There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it depends on whether its a required arg or not. As of now its required. I know some other kubectl commands use Having said all of that, I think we do need to look ahead and think about how we're going to deal with cluster and NS scoped resources. That's when an optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if it's required for the processing, it should not be required for users to provide. In The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah good point - I forgot that kubectl has the notion of the current/default namespace. I would,however, prefer to use kubectl's and not create a new plugin-specific current/default namespace. To me plugins are extending kubectl, not an alternative to it, so whatever defaults kubectl has should apply to plugins as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly! So just use the value in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is what plugins must consider as the namespace to use in the current call. If you need a namespace, just use the value set in that env var as is and you're good. kubectl does all its namespace processing (take the default namespace, kubeconfig, what user provided through There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not suggesting we duplicate it, we should just use it. Part of what @jberkhahn is doing is creating a shared library kind of thing and I would think the getting the current NS would be a util in there that both kubectl and plugins can leverage. IOW, the "current namespace" should yield the same answer for kubectl as it does for the plugin. |
||
` | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
utils.Exit1(usage) | ||
} | ||
|
||
client, err := client.NewClient() | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to initialize service catalog client (%s)", err)) | ||
} | ||
if os.Args[1] == "list" { | ||
if len(os.Args) != 3 { | ||
utils.Exit1(listUsage) | ||
} | ||
namespace := os.Args[2] | ||
bindings, err := client.ListBindings(namespace) | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to list bindings in namespace %s (%s)", namespace, err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
} | ||
|
||
table := utils.NewTable("BINDING NAME", "NAMESPACE", "INSTANCE NAME") | ||
for _, v := range bindings.Items { | ||
table.AddRow(v.Name, v.Namespace, v.Spec.ServiceInstanceRef.Name) | ||
err = table.Print() | ||
} | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Error printing result (%s)", err)) | ||
} | ||
} else if os.Args[1] == "get" { | ||
if len(os.Args) != 4 { | ||
utils.Exit1(getUsage) | ||
} | ||
namespace := os.Args[2] | ||
bindingName := os.Args[3] | ||
binding, err := client.GetBinding(bindingName, namespace) | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to find binding %s in namespae %s (%s)", bindingName, namespace, err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. %q for the first 2 %s's |
||
} | ||
table := utils.NewTable("BINDINGNAME", "NAMESPACE", "INSTANCE NAME") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add space before NAME, in BINDINGNAME to be consistent with instance name |
||
table.AddRow(binding.Name, binding.Namespace, binding.Spec.ServiceInstanceRef.Name) | ||
err = table.Print() | ||
} else { | ||
utils.Exit1(usage) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: "binding" | ||
shortDesc: "This command interacts with Service Bindings" | ||
command: "./binding" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. leave off the "./" since you don't now how they'll specify the path to the exe (if I'm understanding how this is being used) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, that needs to be there for kubectl to know how to invoke the executable - it will need to be different for these to work on windows, but that has other issues. |
||
tree: | ||
- name: "list" | ||
shortDesc: "Lists all Service Bindings in a particular namespace" | ||
command: "./binding list" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/.\/// |
||
- name: "get" | ||
shortDesc: "Gets a particular Service Bindings in a particular namespace" | ||
command: "./binding get" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
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 ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/kubectl/client" | ||
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/kubectl/utils" | ||
) | ||
|
||
const usage = `Usage: | ||
kubectl plugin broker SUBCOMMAND | ||
|
||
Available subcommands: | ||
list | ||
get | ||
` | ||
|
||
const getUsage = `Usage: | ||
kubectl plugin broker get BROKERNAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BROKER_NAME |
||
` | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
utils.Exit1(usage) | ||
} | ||
|
||
client, err := client.NewClient() | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to initialize service catalog client (%s)", err)) | ||
} | ||
if os.Args[1] == "list" { | ||
brokers, err := client.ListBrokers() | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to list brokers (%s)", err)) | ||
} | ||
|
||
table := utils.NewTable("BROKER NAME", "NAMESPACE", "URL") | ||
for _, v := range brokers.Items { | ||
table.AddRow(v.Name, v.Namespace, v.Spec.URL) | ||
err = table.Print() | ||
} | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Error printing result (%s)", err)) | ||
} | ||
} else if os.Args[1] == "get" { | ||
if len(os.Args) != 3 { | ||
utils.Exit1(getUsage) | ||
} | ||
brokerName := os.Args[2] | ||
broker, err := client.GetBroker(brokerName) | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to find broker %s (%s)", brokerName, err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. %q |
||
} | ||
table := utils.NewTable("BROKER NAME", "NAMESPACE", "URL") | ||
table.AddRow(broker.Name, broker.Namespace, broker.Spec.URL) | ||
err = table.Print() | ||
} else { | ||
utils.Exit1(usage) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: "broker" | ||
shortDesc: "This command interacts with Cluster Service Brokers" | ||
command: "./broker" | ||
tree: | ||
- name: "list" | ||
shortDesc: "Lists all Cluster Service Brokers" | ||
command: "./broker list" | ||
- name: "get" | ||
shortDesc: "Gets a particular Cluster Service Broker" | ||
command: "./broker get" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
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 ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/kubectl/client" | ||
"github.com/kubernetes-incubator/service-catalog/plugin/pkg/kubectl/utils" | ||
) | ||
|
||
const usage = `Usage: | ||
kubectl plugin class SUBCOMMAND | ||
|
||
Available subcommands: | ||
list | ||
get | ||
` | ||
|
||
const getUsage = `Usage: | ||
kubectl plugin class get CLASSNAME | ||
` | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
utils.Exit1(usage) | ||
} | ||
|
||
client, err := client.NewClient() | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to initialize service catalog client (%s)", err)) | ||
} | ||
if os.Args[1] == "list" { | ||
classes, err := client.ListClasses() | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to list classes (%s)", err)) | ||
} | ||
|
||
table := utils.NewTable("CLASS NAME", "NAMESPACE", "BROKER NAME") | ||
for _, v := range classes.Items { | ||
table.AddRow(v.Name, v.Namespace, v.Spec.ClusterServiceBrokerName) | ||
err = table.Print() | ||
} | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Error printing result (%s)", err)) | ||
} | ||
} else if os.Args[1] == "get" { | ||
if len(os.Args) != 3 { | ||
utils.Exit1(getUsage) | ||
} | ||
className := os.Args[2] | ||
class, err := client.GetClass(className) | ||
if err != nil { | ||
utils.Exit1(fmt.Sprintf("Unable to find class %s (%s)", className, err)) | ||
} | ||
table := utils.NewTable("CLASS NAME", "NAMESPACE", "BROKER NAME") | ||
table.AddRow(class.Name, class.Namespace, class.Spec.ClusterServiceBrokerName) | ||
err = table.Print() | ||
} else { | ||
utils.Exit1(usage) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: "class" | ||
shortDesc: "This command interacts with Cluster Service Classes" | ||
command: "./class" | ||
tree: | ||
- name: "list" | ||
shortDesc: "Lists all Cluster Service Classes" | ||
command: "./class list" | ||
- name: "get" | ||
shortDesc: "Gets a particular Cluster Service Class" | ||
command: "./class get" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space issue