Enhanced OpenShift CLI: More Stories

The enhanced OpenShift CLI can help you manage a large amount of OpenShift clusters securely and efficiently. It is an open source project I created on GitHub.

As the third post of enhanced oc series, in this post, I will share with you more stories regarding the use of enhanced oc.

Organize Cluster Contexts Hierarchically

This is natively supported by gopass because in the secret store maintained by gopass, each secret data lives in its own file and related secret data can be put in the same directory. For example, if you have three clusters and want to save the contexts for them, you can use the path/to/your/context format to name the context alias for the clusters.

$ oc login -s https://api.foo.example.com -c dev-env/cluster-foo
$ oc login -s https://api.bar.example.com -c dev-env/cluster-bar
$ oc login -s https://api.baz.example.com -c dev-env/cluster-baz

Then your cluster contexts will be organized hierarchically in the secret store and the directory structure maps to how you name the context alias. This can be seen with a very straightforward view by running gopass ls:

$ gopass ls
└── dev-env
├── cluster-foo
├── cluster-bar
└── cluster-baz

When you switch among these clusters, use the path/to/your/context alias to refer to the target cluster that you want to access:

$ oc login -c dev-env/cluster-foo
$ oc login -c dev-env/cluster-bar
$ oc login -c dev-env/cluster-baz

Choose Among Multiple Clusters

The enhanced oc supports partial input for context alias when you run oc login. For example, if you put all clusters for development in category dev-env, you can just input the first few characters such as de, dev, dev-, dev-env when you specify the context alias. If there are more than one results that match your input, a numbered list will be presented. You can enter a number to choose one option in the list:

$ oc login -c dev
1) dev-env/cluster-bar
2) dev-env/cluster-baz
3) dev-env/cluster-foo
#? 1
Read context 'dev-env/cluster-bar' from secret store...
Context loaded successfully.
Login successful.
You have access to 59 projects, the list has been suppressed. You can list all projects with 'oc projects'Using project "default".

Fuzzy Search

Customize Shell Prompt

The enhanced oc can auto-detect the existence of kube-ps1 and work with it seamlessly without any additional setup after you get kube-ps1 installed. It will customize the shell prompt, replace the full cluster context name, which is usually much longer and more machine readable, with the context alias, which is much shorter and more human readable. For how to install kube-ps1, please refer to the kube-ps1 documentation.


In next post, I will introduce another import feature supported by enhanced oc: how to share your cluster access information with your team members.

The enhanced OpenShift CLI is an open source project I created on GitHub. If you like it, you can consider to give star to it. You can also learn more on this project by reading its online documents. Any contributions such as bug report and code submission are very welcome.

Life is coding and writing! I am a software engineer who have been in IT field for 10+ years. I would love to write beautiful code and story for people.