Skip to content

Instantly share code, notes, and snippets.

@carolynvs
Last active January 9, 2018 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carolynvs/de7b431dc45feba5c01d808f41878857 to your computer and use it in GitHub Desktop.
Save carolynvs/de7b431dc45feba5c01d808f41878857 to your computer and use it in GitHub Desktop.
Dual Mode Service Catalog CLI

Dual Mode Service Catalog CLI

We can use the same binary as a standalone Service Catalog CLI, and as a kubectl plugin, with only minor modifications.

Standalone Binary

This is what you see today with svcat.

Installation

curl -sLO https://servicecatalogcli.blob.core.windows.net/cli/latest/$(uname -s)/$(uname -m)/svcat
chmod +x ./svcat
mv ./svcat /usr/local/bin/

Upgrade

Performs an in-place upgrade of the binary.

svcat upgrade

This is on our backlog, currently upgrading involves repeating the installation steps.

Commands

$ svcat get bindings
$ svcat sync broker osba
$ svcat unbind mysql

Plugin

By adding a new svcat install-plugin command, we can use the binary in either standalone or plugin mode.

Flags passed to the plugin are intercepted by kubectl and are converted to environment variables:

  • The flag must be defined in the manifest.
  • Global kubectl flags, like --namespace, are converted to KUBECTL_PLUGINS_GLOBAL_FLAG_NAMESPACE.
  • Command-specific flags, like svcat provision --class, are converted to KUBECTL_PLUGINS_LOCAL_FLAG_CLASS.

Installation

This will install the the svcat binary and an accompanying plugin manifest to ~/.kube/plugins/svcat/.

curl -sLo /tmp/svcat https://servicecatalogcli.blob.core.windows.net/cli/latest/$(uname -s)/$(uname -m)/svcat
chmod +x /tmp/svcat
/tmp/svcat install-plugin

Upgrade

Performs an in-place upgrade of the binary and the plugin manifest.

kubectl plugin svcat upgrade

Commands

In an ideal world, the plugin sub-command would not be necessary. When a sub-command is used that isn't a built-in command, kubectl would search for a matching plugin, making a command like kubectl svcat get bindings possible. We would need to follow-up to know if that was considered and rejected previously.

$ kubectl plugin svcat get bindings
$ kubectl plugin svcat sync broker osba
$ kubectl plugin svcat unbind mysql

Some commands are simple enough that you could use kubectl entirely, without using the plugin:

  • kubectl plugin svcat bind mysql -> kubectl create -f mybinding.yaml
  • kubectl plugin svcat unbind mysql-binding-1 -> kubectl delete servicebinding mysql-binding-1

Falling back to kubectl to perform easy tasks depart from the "domain-specific tool" goal of svcatt to use the same terms when speaking about service catalog on the command line. Rolling up multi-step concerns and tasks into a single domain-based task. For example svcat unbind mysql-instance, iterates all of the existing bindings and removes them. Yes, you can do the same with kubectl, but this fits an entire concept into a single command. It shouldn't be up to the user to know about these special cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment