Skip to content

Commit

Permalink
Merge branch 'add-node-conditions-to-kubernetes-nodes-data-source'
Browse files Browse the repository at this point in the history
  • Loading branch information
JaylonmcShan03 committed Nov 14, 2024
2 parents 3328d19 + 24776a3 commit 488c591
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/2612.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
Added `conditions` attribute to `kubernetes_nodes` data source, which will provide detailed node health and status information
```
12 changes: 11 additions & 1 deletion docs/data-sources/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Read-Only:
- `allocatable` (Map of String)
- `capacity` (Map of String)
- `node_info` (List of Object) (see [below for nested schema](#nestedobjatt--nodes--status--node_info))

- `conditions` (List of Object) (see [below for nested schema](#nestedobjatt--nodes--status--conditions))
<a id="nestedobjatt--nodes--status--addresses"></a>
### Nested Schema for `nodes.status.addresses`

Expand All @@ -108,7 +108,17 @@ Read-Only:
- `os_image` (String)
- `system_uuid` (String)

<a id="nestedobjatt--nodes--status--conditions"></a>
### Nested Schema for `nodes.status.conditions`

Read-Only:

- `type` (String)
- `status` (String)
- `last_heartbeat_time` (String)
- `last_transition_time` (String)
- `reason` (String)
- `message` (String)



Expand Down
7 changes: 7 additions & 0 deletions kubernetes/data_source_kubernetes_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ func TestAccKubernetesDataSourceNodes_basic(t *testing.T) {
resource.TestCheckResourceAttrWith(dataSourceName, "nodes.0.status.0.capacity.memory", checkParsableQuantity),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.node_info.0.architecture"),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.addresses.0.address"),
resource.TestMatchResourceAttr(dataSourceName, "nodes.0.status.0.conditions.#", oneOrMore),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.conditions.0.type"),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.conditions.0.status"),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.conditions.0.last_heartbeat_time"),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.conditions.0.last_transition_time"),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.conditions.0.reason"),
resource.TestCheckResourceAttrSet(dataSourceName, "nodes.0.status.0.conditions.0.message"),
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
33 changes: 33 additions & 0 deletions kubernetes/schema_node_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,39 @@ func nodeStatusFields() map[string]*schema.Schema {
},
},
},
"conditions": {
Type: schema.TypeList,
Computed: true,
Description: "List of conditions describing each node's health and operational status.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"last_heartbeat_time": {
Type: schema.TypeString,
Computed: true,
},
"last_transition_time": {
Type: schema.TypeString,
Computed: true,
},
"reason": {
Type: schema.TypeString,
Computed: true,
},
"message": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
}
}

Expand Down
17 changes: 17 additions & 0 deletions kubernetes/structures_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,29 @@ func flattenNodeInfo(in v1.NodeSystemInfo) []interface{} {
return []interface{}{att}
}

func flattenNodeConditions(conditions []v1.NodeCondition) []interface{} {
out := make([]interface{}, len(conditions))
for i, condition := range conditions {
m := make(map[string]interface{})
m["type"] = condition.Type
m["status"] = condition.Status
m["last_heartbeat_time"] = condition.LastHeartbeatTime.String()
m["last_transition_time"] = condition.LastTransitionTime.String()
m["reason"] = condition.Reason
m["message"] = condition.Message
out[i] = m
}
return out
}

func flattenNodeStatus(in v1.NodeStatus) []interface{} {
att := make(map[string]interface{})
att["addresses"] = flattenAddresses(in.Addresses...)
att["allocatable"] = flattenResourceList(in.Allocatable)
att["capacity"] = flattenResourceList(in.Capacity)
att["node_info"] = flattenNodeInfo(in.NodeInfo)
att["conditions"] = flattenNodeConditions(in.Conditions)

return []interface{}{att}
}

Expand Down

0 comments on commit 488c591

Please sign in to comment.