Bash completion for oc command does not work

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 7.4
  • Red Hat OpenShift Linux Client (oc) v3.6.173.0.21

Issue

  • Bash completion for oc command does not work. Pressing tab key after oc does not show openshift client command parameters.

Resolution

  • When deploying the Openshift Linux client from tar.gz archive, user should manually generate the completion script for bash with the following command:

    # oc completion bash >>/etc/bash_completion.d/oc_completion
    
  • The output file can be saved in user local directory and sourced from ~/.bashrc file as well.

Note: We need to make sure bash-completion package is already present on the system in order to get oc bash completions are working.

Root Cause

OpenShift Linux Client /usr/bin/oc can be installed from atomic-openshift-clients.rpm package or simply extracted from tar.gz archive to any user directory.

The package version contains manual pages and bash completion script which is installed in default location: /etc/bash_completion.d/oc while only a single executable file is available in the archive version.

Diagnostic Steps

With autocompletion enabled the shell presents oc supported commands:

# oc 
adm              completion       describe         get              new-app          process          rsync            tag
annotate         config           edit             idle             new-build        project          run              types
apply            convert          env              import           new-project      projects         scale            version
attach           cp               exec             import-image     observe          proxy            secrets          volumes
auth             create           explain          label            options          replace          serviceaccounts  whoami
autoscale        debug            export           login            patch            rollback         set              
cancel-build     delete           expose           logout           policy           rollout          start-build      
cluster          deploy           extract          logs             port-forward     rsh              status 

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments