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

Feature/add addresses info to nodes #2137

Merged
merged 7 commits into from
Jul 6, 2023
Merged
1 change: 1 addition & 0 deletions kubernetes/data_source_kubernetes_nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccKubernetesDataSourceNodes_basic(t *testing.T) {
resource.TestCheckResourceAttrWith("data.kubernetes_nodes.test", "nodes.0.status.0.capacity.cpu", checkParsableQuantity),
resource.TestCheckResourceAttrWith("data.kubernetes_nodes.test", "nodes.0.status.0.capacity.memory", checkParsableQuantity),
resource.TestCheckResourceAttrSet("data.kubernetes_nodes.test", "nodes.0.status.0.node_info.0.architecture"),
resource.TestCheckResourceAttrSet("data.kubernetes_nodes.test", "nodes.0.status.0.addresses.0.address"),
)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
17 changes: 17 additions & 0 deletions kubernetes/schema_node_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ func nodeSpecFields() map[string]*schema.Schema {

func nodeStatusFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"addresses": {
Type: schema.TypeList,
Computed: true,
Description: "Set of IP addresses and/or Hostname assigned to the node. More info: https://kubernetes.io/docs/concepts/architecture/nodes/#addresses/node/#info",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Computed: true,
},
"address": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"allocatable": {
Type: schema.TypeMap,
Description: "Represents the total resources of a node.",
Expand Down
12 changes: 12 additions & 0 deletions kubernetes/structures_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ func flattenNodeSpec(in v1.NodeSpec) []interface{} {
return []interface{}{att}
}

func flattenAddresses(in ...v1.NodeAddress) []interface{} {
out := make([]interface{}, len(in))
for i, address := range in {
m := make(map[string]interface{})
m["address"] = address.Address
m["type"] = address.Type
out[i] = m
}
return out
}

func flattenNodeInfo(in v1.NodeSystemInfo) []interface{} {
att := make(map[string]interface{})
if in.MachineID != "" {
Expand Down Expand Up @@ -62,6 +73,7 @@ func flattenNodeInfo(in v1.NodeSystemInfo) []interface{} {

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)
Expand Down
10 changes: 9 additions & 1 deletion website/docs/d/nodes.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,23 @@ The following arguments are supported:

### Attributes

* `addresses` - (Optional) A set of IP address(es) and/or Hostname assigned to the node. See [addresses](#addresses) and [Kubernetes reference](https://kubernetes.io/docs/concepts/architecture/nodes/#addresses/node/#info) for more info.
* `allocatable` - (Optional) The total resources of a node.
* `capacity` - (Optional) The resources of a node that are available for scheduling.
* `node_info` - (Optional) A set of ids/uuids to uniquely identify the node. See [node_info](#node_info) for more info. [Kubernetes reference](https://kubernetes.io/docs/concepts/nodes/node/#info)

### `addresses`

#### Attributes

* `type` - Type of the address: HostName, ExternalIP or InternalIP.
* `address` - The IP (if type is ExternalIP or InternalIP) or the hostname (if type is HostName).

### `node_info`

#### Attributes

* `machine_id` - Machine ID reporte by the node see [main(5)
* `machine_id` - Machine ID reported by the node see [main(5)
machine-id](http://man7.org/linux/man-pages/man5/machine-id.5.html) for more info.
* `system_uuid` - System UUID reported by the node. This field is
specific to [Red Hat hosts](https://access.redhat.com/documentation/en-us/red_hat_subscription_management/1/html/rhsm/uuid)
Expand Down
Loading