Bug 1827463

Summary: [oc-cli]oc-sa-create-kubeconfig command does not work with `--context`
Product: OpenShift Container Platform Reporter: Hongkai Liu <hongkliu>
Component: ocAssignee: Jan Chaloupka <jchaloup>
Status: CLOSED ERRATA QA Contact: zhou ying <yinzhou>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.5CC: aos-bugs, jokerman, mfojtik, skuznets, yinzhou
Target Milestone: ---   
Target Release: 4.5.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Cause: oc sa create-kubeconfig did not respect --context option Consequence: oc sa create-kubeconfig created kubeconfig from the current context only Fix: have oc sa create-kubeconfig respect --context option Result: oc sa create-kubeconfig creates kubeconfig with --context as the current context if provided
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-07-13 17:30:56 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Hongkai Liu 2020-04-24 01:48:23 UTC
oc version --client
Client Version: 4.5.0-202004231620-ae3e321

oc config get-contexts
CURRENT   NAME      CLUSTER                                        AUTHINFO                                                  NAMESPACE
          build01   api-build01-ci-devcluster-openshift-com:6443   hongkailiu/api-build01-ci-devcluster-openshift-com:6443   hongkliu-test
*         default   api-ci-openshift-org:443                       hongkailiu/api-ci-openshift-org:443                       hongkliu-test


oc --context build01 sa create-kubeconfig default
apiVersion: v1
clusters:
- cluster:
    server: https://api.ci.openshift.org:443
  name: api-ci-openshift-org:443
contexts:
- context:
    cluster: api-ci-openshift-org:443
    namespace: hongkliu-test
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    token: bar

Comment 4 Jan Chaloupka 2020-05-18 10:16:55 UTC
With `oc --context zhouy/api-pdhamdhe-vsp18-qe-devcluster-openshift-com:6443/testuser-6 sa create-kubeconfig default`, I expect the generated kubeconfig to have api-pdhamdhe-vsp18-qe-devcluster-openshift-com:6443 in the cluster name, not api-yinzhou18-qe-gcp-devcluster-openshift-com:6443. Can you please re-verify again?

Comment 5 Steve Kuznetsov 2020-05-20 19:59:49 UTC
*** Bug 1838298 has been marked as a duplicate of this bug. ***

Comment 6 Hongkai Liu 2020-05-22 21:32:16 UTC
oc version --client
Client Version: 4.5.0-202005220507-44354e2

oc config get-contexts
CURRENT   NAME      CLUSTER                                        AUTHINFO                                                  NAMESPACE
          api.ci    api-ci-openshift-org:443                       hongkailiu/api-ci-openshift-org:443                       hongkliu-test
*         app.ci    api-ci-l2s4-p1-openshiftapps-com:6443          hongkailiu/api-ci-l2s4-p1-openshiftapps-com:6443          hongkliu-test
          build01   api-build01-ci-devcluster-openshift-com:6443   hongkailiu/api-build01-ci-devcluster-openshift-com:6443   hongkliu-test
          build02   api-build02-gcp-ci-openshift-org:6443          hongkailiu/api-build02-gcp-ci-openshift-org:6443          hongkliu-test


oc --context build01 sa create-kubeconfig default
apiVersion: v1
clusters:
- cluster:
    server: https://api.build01.ci.devcluster.openshift.com:6443
  name: api-build01-ci-devcluster-openshift-com:6443
contexts:
- context:
    cluster: api-build01-ci-devcluster-openshift-com:6443
    namespace: hongkliu-test
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    token: XXX

Thanks for the fix.

Comment 7 zhou ying 2020-05-28 01:23:07 UTC
[root@dhcp-140-138 ~]# oc config get-contexts
CURRENT   NAME                                                                          CLUSTER                                                    AUTHINFO      NAMESPACE
          /api-ugdci28074134-qe-azure-devcluster-openshift-com:6443/testuser-49         api-ugdci28074134-qe-azure-devcluster-openshift-com:6443   testuser-49   
          /api-yinzhou27-qe-gcp-devcluster-openshift-com:6443/testuser-30               api-yinzhou27-qe-gcp-devcluster-openshift-com:6443         testuser-30   
*         testzy/api-ugdci28074134-qe-azure-devcluster-openshift-com:6443/testuser-49   api-ugdci28074134-qe-azure-devcluster-openshift-com:6443   testuser-49   testzy
          zhouy/api-yinzhou27-qe-gcp-devcluster-openshift-com:6443/testuser-30          api-yinzhou27-qe-gcp-devcluster-openshift-com:6443         testuser-30   zhouy
[root@dhcp-140-138 ~]# oc --context zhouy/api-yinzhou27-qe-gcp-devcluster-openshift-com:6443/testuser-30 sa create-kubeconfig default
apiVersion: v1
clusters:
- cluster:
    insecure-skip-tls-verify: true
    server: https://api.yinzhou27.qe.gcp.devcluster.openshift.com:6443
  name: api-yinzhou27-qe-gcp-devcluster-openshift-com:6443
contexts:
- context:
    cluster: api-yinzhou27-qe-gcp-devcluster-openshift-com:6443
    namespace: zhouy
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
.....

Comment 10 errata-xmlrpc 2020-07-13 17:30:56 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:2409