Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update replace kubeconfig token logic #1158

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions rancher2/resource_rancher2_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,21 @@ func getClusterKubeconfig(c *Config, id, origconfig string) (*managementClient.G
if err != nil {
return nil, fmt.Errorf("Getting cluster Kubeconfig: %v", err)
}
// kubeconfig is not valid due to an invalid token. Use the cached kubeconfig
// and replace the token
if !kubeValid && len(token) == 0 {
newConfig, err := replaceKubeConfigToken(c, origconfig, token)
if err != nil {
return nil, err
}
origconfig = newConfig
kubeValid = true
}
if kubeValid {
return &managementClient.GenerateKubeConfigOutput{Config: origconfig}, nil
}

// kubeconfig is not valid for other reasons, download a new one
client, err := c.ManagementClient()
if err != nil {
return nil, fmt.Errorf("Getting cluster Kubeconfig: %v", err)
Expand Down Expand Up @@ -734,17 +745,12 @@ func getClusterKubeconfig(c *Config, id, origconfig string) (*managementClient.G
}
err = client.APIBaseClient.Action(managementClient.ClusterType, action, clusterResource, nil, kubeConfig)
if err == nil {
if isRancher26 && len(token) > 0 {
newConfig, err := replaceKubeConfigToken(c, kubeConfig.Config, token)
if err != nil {
return nil, err
}
kubeConfig.Config = newConfig
}
return kubeConfig, nil
}
if !IsNotFound(err) && !IsForbidden(err) && !IsServiceUnavailableError(err) {
return nil, fmt.Errorf("Getting cluster Kubeconfig: %v", err)
if err != nil {
if !IsNotFound(err) && !IsForbidden(err) && !IsServiceUnavailableError(err) {
return nil, fmt.Errorf("Getting cluster Kubeconfig: %w", err)
}
}
}
select {
Expand Down