Details
Description
1. Proposed title of this feature request
"OC login - config_path an easy way to switch between clusters"
2. What is the nature and description of the request?
rhn-support-rbost and I have worked on a shell script to easily switch between OCP Clusters.
The code is available in Robert's repository
The aim of the script is to scan a config_path for kubeconfig and kuebadmin-password.
The script will check for a kubeconfig file in the PATH.
If only one kubeconfig file is found, it will automatically try to connect this cluster.
If multiple kubeconfig files are found, it will prompt the user to select the desired cluster.
# alias oc_login oc_login='$CLUSTER_PATH/oc-flogin $CLUSTER_PATH' # echo $CLUSTER_PATH /Users/vlours/clusters # tree ~/clusters/ /Users/vlours/clusters/ ├── 02842162 ├── aws │ ├── ocp4.4 │ ├── ocp4.4.19 │ │ ├── auth │ │ │ ├── kubeadmin-password │ │ │ └── kubeconfig │ │ ├── metadata.json │ │ ├── terraform.aws.auto.tfvars.json │ │ ├── terraform.tfstate │ │ ├── terraform.tfvars.json │ │ └── tls │ │ ├── journal-gatewayd.crt │ │ └── journal-gatewayd.key │ ├── ocp4.4.30 │ ├── ocp4.5 │ ├── ocp4.6 │ └── ocp4.6.3 │ ├── auth │ │ ├── kubeadmin-password │ │ └── kubeconfig │ ├── metadata.json │ ├── terraform.aws.auto.tfvars.json │ ├── terraform.tfstate │ ├── terraform.tfvars.json │ └── tls │ ├── journal-gatewayd.crt │ └── journal-gatewayd.key ├── azure ├── gcp ├── install-config.yaml ├── oc-flogin -> /Users/vlours/Documents/git/oc-flogin/oc-flogin ├── openshift-install-mac-4.1.0 ├── openshift-install-mac-4.1.41 ├── openshift-install-mac-4.2.0 ├── openshift-install-mac-4.2.36 ├── openshift-install-mac-4.3.0 ├── openshift-install-mac-4.3.28 ├── openshift-install-mac-4.3.40 ├── openshift-install-mac-4.4.16 ├── openshift-install-mac-4.4.19 ├── openshift-install-mac-4.4.3 ├── openshift-install-mac-4.4.30 ├── openshift-install-mac-4.4.32 ├── openshift-install-mac-4.5 ├── openshift-install-mac-4.5.0 ├── openshift-install-mac-4.5.25 ├── openshift-install-mac-4.6.0 ├── openshift-install-mac-4.6.1 ├── openshift-install-mac-4.6.10 ├── openshift-install-mac-4.6.3 ├── openstack ├── ovirt └── vsphere 17 directories, 40 files [21-01-19-13:34] vlours@vlours-mac clusters # alias bastion_aws='ssh -i ~/.ssh/vlours-shiftapac-aws-keypair.pem ec2-user@13.115.248.61' crc=/Users/vlours/CRC/crc oc=/Users/vlours/.crc/bin/oc/oc oc_login='$CLUSTER_PATH/oc-flogin $CLUSTER_PATH' run-help=man supportshell='ssh supportshell.cee.redhat.com' which-command=whence [21-01-19-13:36] vlours@vlours-mac clusters # echo $CLUSTER_PATH /Users/vlours/clusters [21-01-19-13:36] vlours@vlours-mac clusters # alias oc_login oc_login='$CLUSTER_PATH/oc-flogin $CLUSTER_PATH' [21-01-19-13:40] vlours@vlours-mac clusters # tree $CLUSTER_PATH /Users/vlours/clusters ├── aws │ ├── ocp4.4 │ ├── ocp4.4.19 │ │ ├── auth │ │ │ ├── kubeadmin-password │ │ │ └── kubeconfig │ │ ├── metadata.json │ │ ├── terraform.aws.auto.tfvars.json │ │ ├── terraform.tfstate │ │ ├── terraform.tfvars.json │ │ └── tls │ │ ├── journal-gatewayd.crt │ │ └── journal-gatewayd.key │ ├── ocp4.4.30 │ ├── ocp4.5 │ ├── ocp4.6 │ └── ocp4.6.3 │ ├── auth │ │ ├── kubeadmin-password │ │ └── kubeconfig │ ├── metadata.json │ ├── terraform.aws.auto.tfvars.json │ ├── terraform.tfstate │ ├── terraform.tfvars.json │ └── tls │ ├── journal-gatewayd.crt │ └── journal-gatewayd.key ├── azure ├── gcp ├── install-config.yaml ├── openshift-install ├── openstack ├── ovirt └── vsphere oc_login Multiple kubeconfig files found. [0] /Users/vlours/clusters/aws/ocp4.4.19/auth/kubeconfig [1] /Users/vlours/clusters/aws/ocp4.6.3/auth/kubeconfig Please select the desired kubeconfig file: 1 Login with user/password from /Users/vlours/clusters/aws/ocp4.6.3/auth/kubeconfig Login successful. You have access to 58 projects, the list has been suppressed. You can list all projects with 'oc projects' Using project "default".
3. Why does the customer need this? (List the business requirements here)*
I'm sure customer needs should be the same as ours.
For Red Hat internal purpose (CEE support), we need to manage multiple OCP clusters and may have to switch multiple times a day between those clusters.
So far the shell script is working fine, but it may be easier to include this functionality in the oc command itself using a new parameter called --config_path='' or --from-config-path=''
# oc login --help
Log in to your server and save login for subsequent use
[...]
--from-config-path='': PATH, to connect from available kubeconfig files
4. List any affected packages or components.*
This will affect the oc login command to include the new parameter.
Feel free to contact us if you need clarification.
Cheers,
Vincent