Skip to content

Commit 129d98e

Browse files
carolynvskibbles-n-bytes
authored andcommitted
Contribute svcat (openshift#1664)
* Copy svcat from github.com/Azure/service-catalog-cli * Support running as a kubectl plugin Detect when running as a kubectl plugin and load flags from the kubectl environment variables * Vendor svcat dependencies * github.com/spf13/viper * github.com/olekukonko/tablewriter * package: github.com/hashicorp/go-multierror * Add svcat install plugin command $ svcat install plugin --help Install as a kubectl plugin Usage: svcat install plugin [flags] Examples: svcat install plugin svcat install plugin --plugins-path /tmp/kube/plugins Flags: -p, --plugins-path string The installation path. Defaults to KUBECTL_PLUGINS_PATH, if defined, otherwise the plugins directory under the KUBECONFIG dir. In most cases, this is ~/.kube/plugins. * Don't add global kubectl flags in plugin mode Also now that we have viper, --kubeconfig is set automatically to KUBECONFIG * Add svcat cli README * Run go fmt * Make golint happy * Add boilerplate headers * Add unit tests for all readonly commands * Integration tests were planned for commands that mutate state because the value of extensively mocking these commands is too low. * Switch tests to use ups broker data from the walkthrough. * Fix bugs found by new unit tests * Remove 'azure' from svcat help text * Print status timestamps in UTC Otherwise when you run tests they may fail depending on the local timezone. Not 100% sure if the user experience is better with local times or UTC, but that can be considered in a follow-up.
1 parent ff9739b commit 129d98e

File tree

483 files changed

+58237
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

483 files changed

+58237
-3
lines changed

Diff for: cmd/svcat/README.md

+211
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# Service Catalog CLI
2+
3+
This is a command-line interface (CLI) for interacting with
4+
[Kubernetes Service Catalog](../../README.md)
5+
resources. svcat is a domain-specific tool to make interacting with the Service Catalog easier.
6+
While many of its commands have analogs to `kubectl`, our goal is to streamline and optimize
7+
the operator experience, contributing useful code back upstream to Kubernetes where applicable.
8+
9+
svcat communicates with the Service Catalog API through the [aggregated API][agg-api] endpoint on a
10+
Kubernetes cluster.
11+
12+
[agg-api]: https://kubernetes.io/docs/concepts/api-extension/apiserver-aggregation/
13+
14+
# Prerequisites
15+
In order to use svcat, you will need:
16+
17+
* A Kubernetes cluster running v1.7+ or higher
18+
* A broker compatible with the Open Service Broker API installed on the cluster, such as:
19+
* [User Provided Service Broker](../../charts/ups-broker)
20+
* [Open Service Broke for Azure](https://github.com/Azure/helm-charts/tree/master/open-service-broker-azure)
21+
* The [Service Catalog](../../docs/install.md) installed on the cluster.
22+
23+
# Install
24+
Follow the appropriate instructions for your shell to download svcat. The binary
25+
can be used by itself, or as kubectl plugin.
26+
27+
## Bash
28+
```
29+
curl -sLO https://servicecatalogcli.blob.core.windows.net/cli/latest/$(uname -s)/$(uname -m)/svcat
30+
chmod +x ./svcat
31+
mv ./svcat /usr/local/bin/
32+
svcat --version
33+
```
34+
35+
## PowerShell
36+
37+
```
38+
iwr 'https://servicecatalogcli.blob.core.windows.net/cli/latest/Windows/x86_64/svcat.exe' -UseBasicParsing -OutFile svcat.exe
39+
mkdir -f ~\bin
40+
$env:PATH += ";${pwd}\bin"
41+
svcat --version
42+
```
43+
44+
The snippet above adds a directory to your PATH for the current session only.
45+
You will need to find a permanent location for it and add it to your PATH.
46+
47+
## Manual
48+
1. Download the appropriate binary for your operating system:
49+
* macOS: https://servicecatalogcli.blob.core.windows.net/cli/latest/Darwin/x86_64/svcat
50+
* Windows: https://servicecatalogcli.blob.core.windows.net/cli/latest/Windows/x86_64/svcat.exe
51+
* Linux: https://servicecatalogcli.blob.core.windows.net/cli/latest/Linux/x86_64/svcat
52+
1. Make the binary executable.
53+
1. Move the binary to a directory on your PATH.
54+
55+
## Plugin
56+
To use svcat as a plugin, run the following command after downloading:
57+
58+
```console
59+
$ ./svcat install plugin
60+
Plugin has been installed to ~/.kube/plugins/svcat. Run kubectl plugin svcat --help for help using the plugin.
61+
```
62+
63+
When operating as a plugin, the commands are the same with the addition of the global
64+
kubectl configuration flags. One exception is that boolean flags aren't supported
65+
when running in plugin mode, so instead of using `--flag` you must specify a value `--flag=true`.
66+
67+
68+
# Use
69+
70+
Run `svcat -h` to see the available commands.
71+
72+
Below are some common tasks made easy with svcat. The example output assumes that [User Provided Service Broker](../../charts/ups-broker) is installed on the cluster.
73+
74+
## Find brokers installed on the cluster
75+
76+
```console
77+
$ svcat get brokers
78+
NAME URL STATUS
79+
+------------+-----------------------------------------------------------+--------+
80+
ups-broker http://ups-broker-ups-broker.ups-broker.svc.cluster.local Ready
81+
```
82+
83+
## Trigger a sync of a broker's catalog
84+
85+
```console
86+
$ svcat sync broker ups-broker
87+
Successfully fetched catalog entries from the ups-broker broker
88+
```
89+
90+
## List available service classes
91+
92+
```console
93+
$ svcat get classes
94+
NAME DESCRIPTION UUID
95+
+-----------------------+-------------------------+--------------------------------------+
96+
user-provided-service A user provided service 4f6e6cf6-ffdd-425f-a2c7-3c9258ad2468
97+
```
98+
99+
## View service plans associated with a class
100+
101+
```console
102+
$ svcat describe class user-provided-service
103+
Name: user-provided-service
104+
Description: A user provided service
105+
UUID: 4f6e6cf6-ffdd-425f-a2c7-3c9258ad2468
106+
Status: Active
107+
Tags:
108+
Broker: ups-broker
109+
110+
Plans:
111+
NAME DESCRIPTION
112+
+---------+-------------------------+
113+
default Sample plan description
114+
premium Premium plan
115+
```
116+
117+
## Provision a service
118+
119+
```console
120+
$ svcat provision -n test-ns ups-instance --class user-provided-service --plan default
121+
Name: ups-instance
122+
Namespace: test-ns
123+
Status:
124+
Class: user-provided-service
125+
Plan: default
126+
```
127+
128+
Additional parameters and secrets can be provided using the `--param` and `--secret` flags:
129+
130+
```
131+
--param p1=foo --param p2=bar --secret creds[db]
132+
```
133+
134+
## View all instances of a service plan on the cluster
135+
136+
```console
137+
$ svcat describe plan premium
138+
Name: premium
139+
Description: Premium plan
140+
UUID: cc0d7529-18e8-416d-8946-6f7456acd589
141+
Status: Active
142+
Free: false
143+
Class: user-provided-service
144+
145+
Instances:
146+
NAME NAMESPACE STATUS
147+
+--------------+-----------+--------+
148+
ups-instance test-ns Ready
149+
```
150+
151+
## List all service instances in a namespace
152+
153+
```console
154+
$ svcat get instances -n test-ns
155+
NAME NAMESPACE CLASS PLAN STATUS
156+
+--------------+-----------+-----------------------+---------+--------+
157+
ups-instance test-ns user-provided-service default Ready
158+
```
159+
160+
## Bind an instance
161+
162+
```console
163+
$ svcat bind -n test-ns ups-instance --name ups-binding
164+
Name: ups-binding
165+
Namespace: test-ns
166+
Status:
167+
Instance: ups-instance
168+
```
169+
170+
When omitted, the names of the binding and secret are defaulted to the name of the instance.
171+
172+
```console
173+
$ svcat bind ups
174+
Name: ups
175+
Namespace: default
176+
Status:
177+
Instance: ups
178+
```
179+
180+
## View the details of a service instance
181+
182+
```console
183+
$ svcat describe instance -n test-ns ups-instance
184+
Name: ups-instance
185+
Namespace: test-ns
186+
Status: Ready - The instance was provisioned successfully @ 2018-01-11 14:59:47 -0600 CST
187+
Class: user-provided-service
188+
Plan: default
189+
190+
Bindings:
191+
NAME STATUS
192+
+-------------+--------+
193+
ups-binding Ready
194+
```
195+
196+
## Unbind all applications from an instance
197+
```
198+
svcat unbind -n test-ns ups-instance
199+
```
200+
201+
## Unbind a single application from an instance
202+
```
203+
svcat unbind -n test-ns --name ups-binding
204+
```
205+
206+
## Delete a service instance
207+
Deprovisioning is the process of preparing an instance to be removed, and then deleting it.
208+
209+
```
210+
svcat deprovision ups-instance
211+
```

Diff for: cmd/svcat/binding/bind_cmd.go

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package binding
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/command"
23+
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/output"
24+
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/parameters"
25+
"github.com/spf13/cobra"
26+
)
27+
28+
type bindCmd struct {
29+
*command.Context
30+
ns string
31+
instanceName string
32+
bindingName string
33+
secretName string
34+
rawParams []string
35+
params map[string]string
36+
rawSecrets []string
37+
secrets map[string]string
38+
}
39+
40+
// NewBindCmd builds a "svcat bind" command
41+
func NewBindCmd(cxt *command.Context) *cobra.Command {
42+
bindCmd := &bindCmd{Context: cxt}
43+
cmd := &cobra.Command{
44+
Use: "bind INSTANCE_NAME",
45+
Short: "Binds an instance's metadata to a secret, which can then be used by an application to connect to the instance",
46+
Example: `
47+
svcat bind wordpress
48+
svcat bind wordpress-mysql-instance --name wordpress-mysql-binding --secret-name wordpress-mysql-secret
49+
`,
50+
RunE: func(cmd *cobra.Command, args []string) error {
51+
return bindCmd.run(args)
52+
},
53+
}
54+
cmd.Flags().StringVarP(
55+
&bindCmd.ns,
56+
"namespace",
57+
"n",
58+
"default",
59+
"The instance namespace",
60+
)
61+
cmd.Flags().StringVarP(
62+
&bindCmd.bindingName,
63+
"name",
64+
"",
65+
"",
66+
"The name of the binding. Defaults to the name of the instance.",
67+
)
68+
cmd.Flags().StringVarP(
69+
&bindCmd.secretName,
70+
"secret-name",
71+
"",
72+
"",
73+
"The name of the secret. Defaults to the name of the instance.",
74+
)
75+
cmd.Flags().StringArrayVarP(&bindCmd.rawParams, "param", "p", nil,
76+
"Additional parameter to use when binding the instance, format: NAME=VALUE")
77+
cmd.Flags().StringArrayVarP(&bindCmd.rawSecrets, "secret", "s", nil,
78+
"Additional parameter, whose value is stored in a secret, to use when binding the instance, format: SECRET[KEY]")
79+
80+
return cmd
81+
}
82+
83+
func (c *bindCmd) run(args []string) error {
84+
if len(args) == 0 {
85+
return fmt.Errorf("instance is required")
86+
}
87+
c.instanceName = args[0]
88+
89+
var err error
90+
c.params, err = parameters.ParseVariableAssignments(c.rawParams)
91+
if err != nil {
92+
return fmt.Errorf("invalid --param value (%s)", err)
93+
}
94+
95+
c.secrets, err = parameters.ParseKeyMaps(c.rawSecrets)
96+
if err != nil {
97+
return fmt.Errorf("invalid --secret value (%s)", err)
98+
}
99+
100+
return c.bind()
101+
}
102+
103+
func (c *bindCmd) bind() error {
104+
binding, err := c.App.Bind(c.ns, c.bindingName, c.instanceName, c.secretName, c.params, c.secrets)
105+
if err != nil {
106+
return err
107+
}
108+
109+
output.WriteBindingDetails(c.Output, binding)
110+
return nil
111+
}

0 commit comments

Comments
 (0)