#!/bin/bash # optional argument handling if [[ "$1" == "version" ]] then echo "1.0.0" exit 0 fi # optional argument handling if [[ "$1" == "config" ]] then echo $KUBECONFIG exit 0 fi echo "I am a plugin named kubectl-foo"
You can write a plugin for the OpenShift Container Platform CLI in any programming language
or script that allows you to write command-line commands. Note that you can not
use a plugin to overwrite an existing
This procedure creates a simple Bash plugin that prints a message to the
terminal when the
oc foo command is issued.
Create a file called
When naming your plugin file, keep the following in mind:
The file must begin with
kubectl- to be recognized as a
The file name determines the command that invokes the plugin. For example, a
plugin with the file name
oc-foo-bar can be invoked by a command of
oc foo bar. You can also use underscores if you want the command to contain
dashes. For example, a plugin with the file name
oc-foo_bar can be invoked
by a command of
Add the following contents to the file.
After you install this plugin for the OpenShift Container Platform CLI, it can be invoked
oc foo command.
After you write a custom plugin for the OpenShift Container Platform CLI, you must install it to use the functionality that it provides.
You must have the
oc CLI tool installed.
You must have a CLI plugin file that begins with
If necessary, update the plugin file to be executable.
$ chmod +x <plugin_file>
Place the file anywhere in your
PATH, such as
$ sudo mv <plugin_file> /usr/local/bin/.
oc plugin list to make sure that the plugin is listed.
$ oc plugin list
The following compatible plugins are available: /usr/local/bin/<plugin_file>
If your plugin is not listed here, verify that the file begins with
kubectl-, is executable, and is on your
Invoke the new command or option introduced by the plugin.
For example, if you built and installed the
kubectl-ns plugin from the
Sample plugin repository,
you can use the following command to view the current namespace.
$ oc ns
Note that the command to invoke the plugin depends on the plugin file name.
For example, a plugin with the file name of
oc-foo-bar is invoked by the
oc foo bar