From e5b9cccba0b1cf711bbddeb650520dc89c82bf0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Xavier=20Costa?= Date: Tue, 6 Jun 2023 21:44:40 -0300 Subject: [PATCH 1/3] feat: Add Node Addresses structure to Data Source Kubernetes Nodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Xavier Costa --- kubernetes/schema_node_spec.go | 17 +++++++++++++++++ kubernetes/structures_node.go | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/kubernetes/schema_node_spec.go b/kubernetes/schema_node_spec.go index 2331f596bb..d87186039c 100644 --- a/kubernetes/schema_node_spec.go +++ b/kubernetes/schema_node_spec.go @@ -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.", diff --git a/kubernetes/structures_node.go b/kubernetes/structures_node.go index 17f31d142a..12f24504b0 100644 --- a/kubernetes/structures_node.go +++ b/kubernetes/structures_node.go @@ -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 != "" { @@ -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) From 83c1ff042a41f641159edce69c5865b9138df879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Xavier=20Costa?= Date: Wed, 7 Jun 2023 21:09:33 -0300 Subject: [PATCH 2/3] test: Add resource attribute set test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Xavier Costa --- kubernetes/data_source_kubernetes_nodes_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/kubernetes/data_source_kubernetes_nodes_test.go b/kubernetes/data_source_kubernetes_nodes_test.go index 4b765f4aa7..ffac00514c 100644 --- a/kubernetes/data_source_kubernetes_nodes_test.go +++ b/kubernetes/data_source_kubernetes_nodes_test.go @@ -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) }, From a4063fb524187a349176b435f98f4f569da33a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Xavier=20Costa?= Date: Sat, 24 Jun 2023 12:09:41 -0300 Subject: [PATCH 3/3] docs: Changed section of status and added section of addresses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André Xavier Costa --- website/docs/d/nodes.html.markdown | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/website/docs/d/nodes.html.markdown b/website/docs/d/nodes.html.markdown index 1467f97b72..3a29482281 100644 --- a/website/docs/d/nodes.html.markdown +++ b/website/docs/d/nodes.html.markdown @@ -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)