Skip to content

Commit

Permalink
Fixed a bug that the --context flag is not reflected (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
superbrothers authored Sep 28, 2020
1 parent 72f6616 commit 76340c7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/cmd/view-serviceaccount-kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,30 @@ func (o *ViewServiceaccountKubeconfigOptions) Run() error {
return fmt.Errorf("Failed to get current kubeconfig data")
}

currentContext := rawConfig.CurrentContext
var currentContext string
if *o.configFlags.Context != "" {
currentContext = *o.configFlags.Context
} else {
currentContext = rawConfig.CurrentContext
}
cluster := rawConfig.Contexts[currentContext].Cluster
server := rawConfig.Clusters[cluster].Server

config := &clientcmdapi.Config{
CurrentContext: currentContext,
Clusters: map[string]*clientcmdapi.Cluster{
"cluster": &clientcmdapi.Cluster{
"cluster": {
Server: server,
CertificateAuthorityData: caCrt,
},
},
AuthInfos: map[string]*clientcmdapi.AuthInfo{
serviceaccount.GetName(): &clientcmdapi.AuthInfo{
serviceaccount.GetName(): {
Token: string(token[:]),
},
},
Contexts: map[string]*clientcmdapi.Context{
"context": &clientcmdapi.Context{
"context": {
Cluster: cluster,
AuthInfo: serviceaccount.GetName(),
Namespace: namespace,
Expand Down

0 comments on commit 76340c7

Please sign in to comment.