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

Add conditions attribute to kubernetes_nodes data source #2612

Merged
Merged
Show file tree
Hide file tree
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
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"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not feasible to test for all the newly introduced attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly do that! Will update the test, to include the additional attributes 👍

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
Loading