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

Conversation

andrewsomething
Copy link
Member

For some reason, we only return an error when attempting to fetch a cluster's credentials if it is a 404 response. This can lead to a panic in other error cases as we attempt to flatten the credential which are nil. This handles the error properly and protect against a panic in flattenCredentials.

Example panic:

Stack trace from the terraform-provider-digitalocean_v2.30.0 plugin:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xcfad4c]
goroutine 465 [running]:
github.com/digitalocean/terraform-provider-digitalocean/digitalocean/kubernetes.flattenCredentials({0xc000b61490, 0xc}, {0xc000b6147c, 0x4}, 0x0)
github.com/digitalocean/terraform-provider-digitalocean/digitalocean/kubernetes/resource_kubernetes_cluster.go:680 +0x4c
github.com/digitalocean/terraform-provider-digitalocean/digitalocean/kubernetes.digitaloceanKubernetesClusterRead(0xc00012a580, 0xc000736480, 0x1974200?)
github.com/digitalocean/terraform-provider-digitalocean/digitalocean/kubernetes/resource_kubernetes_cluster.go:409 +0xccc
github.com/digitalocean/terraform-provider-digitalocean/digitalocean/kubernetes.resourceDigitalOceanKubernetesClusterRead({0x12938c0?, 0xc000cffaa0?}, 0xc00072e480, {0xe80840?, 0xc000671890?})
github.com/digitalocean/terraform-provider-digitalocean/digitalocean/kubernetes/resource_kubernetes_cluster.go:337 +0x1c9
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc00056ce00, {0x12938c0, 0xc000cffaa0}, 0xd?, {0xe80840, 0xc000671890})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:724 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc00056ce00, {0x12938c0, 0xc000cffaa0}, 0xc0007dc8f0, {0xe80840, 0xc000671890})
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1015 +0x549
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc0004137d0, {0x12938c0?, 0xc000cff170?}, 0xc00064afc0)
github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:613 +0x48a
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc000092140, {0x12938c0?, 0xc000cfe1e0?}, 0xc000764120)
github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:748 +0x48a
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xf61920?, 0xc000092140}, {0x12938c0, 0xc000cfe1e0}, 0xc0007def50, 0x0)
github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00041c000, {0x12984e0, 0xc0000b2680}, 0xc000a05560, 0xc000585620, 0x1937430, 0x0)
google.golang.org/[email protected]/server.go:1336 +0xd67
google.golang.org/grpc.(*Server).handleStream(0xc00041c000, {0x12984e0, 0xc0000b2680}, 0xc000a05560, 0x0)
google.golang.org/[email protected]/server.go:1704 +0x9e7
google.golang.org/grpc.(*Server).serveStreams.func1.2()
google.golang.org/[email protected]/server.go:965 +0x8d
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 13
google.golang.org/[email protected]/server.go:963 +0x246

@andrewsomething andrewsomething requested a review from a team November 1, 2023 15:15
@andrewsomething andrewsomething merged commit 2351b82 into main Nov 1, 2023
2 checks passed
@andrewsomething andrewsomething deleted the asb/k8s-panic branch November 1, 2023 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants