hashicorp / terraform-provider-kubernetes

Terraform Kubernetes provider
https://www.terraform.io/docs/providers/kubernetes/
Mozilla Public License 2.0
1.58k stars 966 forks source link

Include conditions in nodes data source #2430

Open simonostendorf opened 7 months ago

simonostendorf commented 7 months ago

Description

I would like to get the node conditions inside the kubernetes_nodes data source. Currently only addresses, allocatable, capacity and node_info are exported.

Potential Terraform Configuration

data "kubernetes_nodes" "example" {}

output "node_conditions" {
  value = [for node in data.kubernetes_nodes.example.nodes : node.status.conditions]
}

References

none

Community Note

alexsomesan commented 6 months ago

Thanks for bringing this up. We think it would make for a useful improvement to the nodes datasource and will add it to our backlog for triage.

In the mean time, you can achieve similar results by using the generic kubernetes_resources data source we already have in the provider.

Here's an example of how that would work:

data "kubernetes_resources" "nodes" {
  api_version = "v1"
  kind        = "Node"
}

output "nodes_conditions" {
  value = data.kubernetes_resources.nodes.objects.*.status.conditions
}
simonostendorf commented 6 months ago

In the mean time, you can achieve similar results by using the generic kubernetes_resources data source we already have in the provider.

Thank you for your reply and adding it to your backlog.

The kubernetes_resources data source results in a crash of the provider when i use it like your example.

alexsomesan commented 6 months ago

Can you share the crash log?

simonostendorf commented 6 months ago

Can you share the crash log?

Sure, here is the crash log.

│ Error: Plugin did not respond
│
│   with data.kubernetes_resources.nodes,
│   on main.tf line 48, in data "kubernetes_resources" "nodes":
│   48: data "kubernetes_resources" "nodes" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadDataSource call. The
│ plugin logs may contain more details.
╵

Stack trace from the terraform-provider-kubernetes_v2.26.0_x5 plugin:

panic: runtime error: index out of range [7] with length 7

goroutine 14 [running]:
github.com/hashicorp/terraform-provider-kubernetes/manifest/payload.sliceToTFTupleValue({0xc0044df100, 0x8, 0xc004f4f620?}, {0x24c6f28?, 0xc004f0ad80}, 0x8010103?, 0xc00294fe18)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/payload/to_value.go:192 +0x785
github.com/hashicorp/terraform-provider-kubernetes/manifest/payload.ToTFValue({0x1d38720?, 0xc001310300?}, {0x24c6f28, 0xc004f0ad80}, 0xc004f42730?, 0x4184e8?)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/payload/to_value.go:117 +0x6c6
github.com/hashicorp/terraform-provider-kubernetes/manifest/payload.mapToTFObjectValue(0x2060520?, {0x24c6cc0?, 0xc0048f68d0}, 0xc004f42730?, 0xc00294f878)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/payload/to_value.go:259 +0x308
github.com/hashicorp/terraform-provider-kubernetes/manifest/payload.ToTFValue({0x1e5e440?, 0xc004c2a840?}, {0x24c6cc0, 0xc0048f68d0}, 0x1e60300?, 0xc94b98?)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/payload/to_value.go:128 +0x9aa
github.com/hashicorp/terraform-provider-kubernetes/manifest/payload.mapToTFObjectValue(0x2060520?, {0x24c6cc0?, 0xc00497a540}, 0xc0044860c8?, 0xc00289f410)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/payload/to_value.go:259 +0x308
github.com/hashicorp/terraform-provider-kubernetes/manifest/payload.ToTFValue({0x1e5e440?, 0xc004c2a810?}, {0x24c6cc0, 0xc00497a540}, 0x20b2cc0?, 0xc004e54480?)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/payload/to_value.go:128 +0x9aa
github.com/hashicorp/terraform-provider-kubernetes/manifest/provider.(*RawProviderServer).ReadPluralDataSource(0xc000510400, {0x24bfd48, 0xc000bf1c50}, 0xc00068e9a0)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/provider/datasource.go:178 +0x15d1
github.com/hashicorp/terraform-provider-kubernetes/manifest/provider.(*RawProviderServer).ReadDataSource(0x24bfd48?, {0x24bfd48, 0xc000bf1c50}, 0xc00068e9a0)
        github.com/hashicorp/terraform-provider-kubernetes/manifest/provider/datasource.go:28 +0x85
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ReadDataSource(0x24bfd80?, {0x24bfd48?, 0xc000bf1950?}, 0xc00068e9a0)
        github.com/hashicorp/terraform-plugin-mux@v0.12.0/tf5muxserver/mux_server_ReadDataSource.go:36 +0x19f
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadDataSource(0xc0000ce460, {0x24bfd48?, 0xc000bf0fc0?}, 0xc000b88ff0)
        github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/tf5server/server.go:699 +0x3df
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler({0x20c12c0?, 0xc0000ce460}, {0x24bfd48, 0xc000bf0fc0}, 0xc0002acd80, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:539 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000a78000, {0x24bfd48, 0xc000bf0f30}, {0x24c80a0, 0xc000b341a0}, 0xc000bed200, 0xc000767710, 0x3543dc8, 0x0)
        google.golang.org/grpc@v1.60.0/server.go:1372 +0xe03
google.golang.org/grpc.(*Server).handleStream(0xc000a78000, {0x24c80a0, 0xc000b341a0}, 0xc000bed200)
        google.golang.org/grpc@v1.60.0/server.go:1783 +0xfec
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.60.0/server.go:1016 +0x59
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 54
        google.golang.org/grpc@v1.60.0/server.go:1027 +0x115

Error: The terraform-provider-kubernetes_v2.26.0_x5 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
alexsomesan commented 6 months ago

Which cluster type and version did you use this on? Also, which Terraform version?

I will try to reproduce it. The example works fine for me on a kind cluster.

simonostendorf commented 6 months ago

Which cluster type and version did you use this on? Also, which Terraform version?

I will try to reproduce it. The example works fine for me on a kind cluster.

I am using a kubeadm cluster build with cluster-api on version 1.24.14 and Terraform 1.7.3 with kubernetes-provider version 2.26.0.

alexsomesan commented 6 months ago

Could you also provide us with a core dump of the crash, please?

Instructions for getting core dumps from Go processes are here: https://github.com/dailymotion/hands-on-diagnosing-golang-apps/blob/master/core-files/README.md

alexsomesan commented 6 months ago

Don't share the core file here directly as it might contain credentials to your cluster. You could share it with me directly in a google drive using my company email: somesan@hashicorp.com

alexsomesan commented 6 months ago

@simonostendorf Do you think you'd be able to share a core file from the crash? I haven't been able to reproduce the same crash so far.

simonostendorf commented 6 months ago

@simonostendorf Do you think you'd be able to share a core file from the crash? I haven't been able to reproduce the same crash so far.

Sorry for the late reply. I don't have much time this week. I will look at the crash next week.

simonostendorf commented 6 months ago

@alexsomesan

Sorry, I don't have enough time to look at the bug and reproduce it. So far I've been able to detect crashes with Kubernetes 1.24 and 1.25, but not with 1.26 and 1.27, but I can't always reproduce them. Due to the unclear reproduction situation, the issue can be closed for now, and I will get back to you when I can narrow down the bug further and provide a core file.

alexsomesan commented 6 months ago

No worries. I'm also on vacation this week and didn't advance my research very much. Thanks for the versions detail. I think that should help. Let's keep the issue open for now - there is another one with a similar crash so we need to get to the bottom of it.