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

k8s: Handle error from GetCredentials and protect against panic. #1064

Merged
merged 1 commit into from
Nov 1, 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
10 changes: 6 additions & 4 deletions digitalocean/kubernetes/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,9 @@ func digitaloceanKubernetesClusterRead(
}
}
if expiresAt.IsZero() || expiresAt.Before(time.Now()) {
creds, resp, err := client.Kubernetes.GetCredentials(context.Background(), cluster.ID, &godo.KubernetesClusterCredentialsGetRequest{})
creds, _, err := client.Kubernetes.GetCredentials(context.Background(), cluster.ID, &godo.KubernetesClusterCredentialsGetRequest{})
if err != nil {
if resp != nil && resp.StatusCode == 404 {
return diag.Errorf("Unable to fetch Kubernetes credentials: %s", err)
}
return diag.Errorf("Unable to fetch Kubernetes credentials: %s", err)
}
d.Set("kube_config", flattenCredentials(cluster.Name, cluster.RegionSlug, creds))
}
Expand Down Expand Up @@ -676,6 +674,10 @@ type kubernetesConfigUserData struct {
}

func flattenCredentials(name string, region string, creds *godo.KubernetesClusterCredentials) []interface{} {
if creds == nil {
return nil
}

raw := map[string]interface{}{
"cluster_ca_certificate": base64.StdEncoding.EncodeToString(creds.CertificateAuthorityData),
"host": creds.Server,
Expand Down
Loading