Mauricio Magnani bio photo

Mauricio Magnani

A guy who loves technology and new challenges!

Email Twitter LinkedIn Github

OpenShift is an open source container application platform by Red Hat based on the Kubernetes container orchestrator. The Kubernetes platform for big ideas.

Writing Plug-ins

A very interesting feature was made available as a tech preview from OpenShift 3.7. This feature allows the OpenShift cluster administrator to create custom plugins to improve productivity in administration/troubleshooting.

I will not go into detail because we have clear documentation of what is required but on the other hand I will describe below some steps for you to write your first plugin.

To make it easier to manage versions and clones in other environments, create a repository in github such as openshift-etcd-plugin.

In the openshift-etcd-plugin.git directory, create the and plugin.yaml files.

The plugin.yml file is the central point of calls for scripts, binaries, etc.


name: "etcd"
shortDesc: "Plugin for check etcd info from OpenShift."
command: "./"
  - name: "output"
    desc: "Output format of data "

The file will take the actions needed to get this information:

exec {BASH_XTRACEFD}>>$DEST/etcd.log
set -x
openshift version
source /etc/etcd/etcd.conf
export ETCDCTL_API=3
ETCD_ALL_ENDPOINTS=` etcdctl  --cert=$ETCD_PEER_CERT_FILE --key=$ETCD_PEER_KEY_FILE --cacert=$ETCD_TRUSTED_CA_FILE --endpoints=$ETCD_LISTEN_CLIENT_URLS --write-out=fields   member list | awk '/ClientURL/{printf "%s%s",sep,$3; sep=","}'`
etcdctl  --cert=$ETCD_PEER_CERT_FILE --key=$ETCD_PEER_KEY_FILE --cacert=$ETCD_TRUSTED_CA_FILE --endpoints=$ETCD_LISTEN_CLIENT_URLS --write-out=table  member list
etcdctl  --cert=$ETCD_PEER_CERT_FILE --key=$ETCD_PEER_KEY_FILE --cacert=$ETCD_TRUSTED_CA_FILE --endpoints=$ETCD_ALL_ENDPOINTS  --write-out=table endpoint status
etcdctl  --cert=$ETCD_PEER_CERT_FILE --key=$ETCD_PEER_KEY_FILE --cacert=$ETCD_TRUSTED_CA_FILE --endpoints=$ETCD_ALL_ENDPOINTS endpoint health

Push the files to the repository in github.

Now in your cluster openshift clone repository into your ~/.kube/plugins directory:

[root@master-0]# git clone ~/.kube/plugins/openshift-etcd-plugin

Verify that it is working:

[root@master-0]# oc plugin
Runs a command-line plugin. 

Plugins are subcommands that are not part of the major command-line distribution and can even be provided by
third-parties. Please refer to the documentation and examples for more information about how to install and write your
own plugins.

  oc plugin NAME [options]

Available Commands:
  etcd        Plugin for gathering etcd info from OpenShift.

Now simply run:

[root@master-0 openshift-etcd-plugin]# oc plugin etcd
+ openshift version
openshift v3.9.25
kubernetes v1.9.1+a0ce1bc657
etcd 3.2.16
+ source /etc/etcd/etcd.conf
++ ETCD_DATA_DIR=/var/lib/etcd/
++ ETCD_TRUSTED_CA_FILE=/etc/etcd/ca.crt
++ ETCD_CERT_FILE=/etc/etcd/server.crt
++ ETCD_KEY_FILE=/etc/etcd/server.key
++ ETCD_PEER_TRUSTED_CA_FILE=/etc/etcd/ca.crt
++ ETCD_PEER_CERT_FILE=/etc/etcd/peer.crt
++ ETCD_PEER_KEY_FILE=/etc/etcd/peer.key
+ export ETCDCTL_API=3
++ etcdctl --cert=/etc/etcd/peer.crt --key=/etc/etcd/peer.key --cacert=/etc/etcd/ca.crt --endpoints= --write-out=fields member list
++ awk '/ClientURL/{printf "%s%s",sep,$3; sep=","}'
+ etcdctl --cert=/etc/etcd/peer.crt --key=/etc/etcd/peer.key --cacert=/etc/etcd/ca.crt --endpoints= --write-out=table member list
|        ID        | STATUS  |                      NAME                      |        PEER ADDRS         |       CLIENT ADDRS        |
| 10639905e92fe697 | started | | | |
+ etcdctl --cert=/etc/etcd/peer.crt --key=/etc/etcd/peer.key --cacert=/etc/etcd/ca.crt '--endpoints=""' --write-out=table endpoint status
|         ENDPOINT          |        ID        | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
| | 10639905e92fe697 |  3.2.15 |   14 MB |      true |         2 |    2608889 |
+ etcdctl --cert=/etc/etcd/peer.crt --key=/etc/etcd/peer.key --cacert=/etc/etcd/ca.crt '--endpoints=""' endpoint health is healthy: successfully committed proposal: took = 849.061┬Ás

It seems like a very interesting feature! The example I presented was quite simple.

You can find an excellent example of use at OpenShift SOS Plugin

See you!