diff --git a/internal/store/node.go b/internal/store/node.go index 5dd1f28c41..b3cee9a366 100644 --- a/internal/store/node.go +++ b/internal/store/node.go @@ -134,23 +134,36 @@ func createNodeInfoFamilyGenerator() generator.FamilyGenerator { n.Status.NodeInfo.SystemUUID, } - internalIP := "" + internalIPs := []string{} + externalIPs := []string{} for _, address := range n.Status.Addresses { - if address.Type == "InternalIP" { - internalIP = address.Address + switch address.Type { + case "InternalIP": + internalIPs = append(internalIPs, address.Address) + case "ExternalIP": + externalIPs = append(externalIPs, address.Address) } } - labelKeys = append(labelKeys, "internal_ip") - labelValues = append(labelValues, internalIP) - externalIP := "" - for _, address := range n.Status.Addresses { - if address.Type == "ExternalIP" { - externalIP = address.Address + if len(internalIPs) > 0 { + for _, ip := range internalIPs { + labelKeys = append(labelKeys, "internal_ip") + labelValues = append(labelValues, ip) + } + } else { + labelKeys = append(labelKeys, "internal_ip") + labelValues = append(labelValues, "") + } + + if len(externalIPs) > 0 { + for _, ip := range externalIPs { + labelKeys = append(labelKeys, "external_ip") + labelValues = append(labelValues, ip) } + } else { + labelKeys = append(labelKeys, "external_ip") + labelValues = append(labelValues, "") } - labelKeys = append(labelKeys, "external_ip") - labelValues = append(labelValues, externalIP) return &metric.Family{ Metrics: []*metric.Metric{ diff --git a/internal/store/node_test.go b/internal/store/node_test.go index d25c2ec9af..9730f1085b 100644 --- a/internal/store/node_test.go +++ b/internal/store/node_test.go @@ -46,6 +46,7 @@ func TestNodeStore(t *testing.T) { }, Addresses: []v1.NodeAddress{ {Type: "InternalIP", Address: "1.2.3.4"}, + {Type: "InternalIP", Address: "fc00::"}, {Type: "ExternalIP", Address: "5.6.7.8"}, }, }, @@ -61,7 +62,7 @@ func TestNodeStore(t *testing.T) { # TYPE kube_node_info gauge # TYPE kube_node_labels gauge # TYPE kube_node_spec_unschedulable gauge - kube_node_info{container_runtime_version="rkt",kernel_version="kernel",kubelet_version="kubelet",kubeproxy_version="kubeproxy",node="127.0.0.1",os_image="osimage",pod_cidr="172.24.10.0/24",provider_id="provider://i-uniqueid",internal_ip="1.2.3.4",external_ip="5.6.7.8",system_uuid="6a934e21-5207-4a84-baea-3a952d926c80"} 1 + kube_node_info{container_runtime_version="rkt",kernel_version="kernel",kubelet_version="kubelet",kubeproxy_version="kubeproxy",node="127.0.0.1",os_image="osimage",pod_cidr="172.24.10.0/24",provider_id="provider://i-uniqueid",internal_ip="1.2.3.4",internal_ip="fc00::",external_ip="5.6.7.8",system_uuid="6a934e21-5207-4a84-baea-3a952d926c80"} 1 kube_node_spec_unschedulable{node="127.0.0.1"} 0 `, MetricNames: []string{"kube_node_spec_unschedulable", "kube_node_labels", "kube_node_info"}, @@ -106,6 +107,7 @@ func TestNodeStore(t *testing.T) { }, Addresses: []v1.NodeAddress{ {Type: "InternalIP", Address: "1.2.3.4"}, + {Type: "InternalIP", Address: "fc00::"}, {Type: "ExternalIP", Address: "5.6.7.8"}, }, Capacity: v1.ResourceList{ @@ -142,7 +144,7 @@ func TestNodeStore(t *testing.T) { # TYPE kube_node_status_allocatable gauge # TYPE kube_node_status_capacity gauge kube_node_created{node="127.0.0.1"} 1.5e+09 - kube_node_info{container_runtime_version="rkt",kernel_version="kernel",kubelet_version="kubelet",kubeproxy_version="kubeproxy",node="127.0.0.1",os_image="osimage",pod_cidr="172.24.10.0/24",provider_id="provider://i-randomidentifier",internal_ip="1.2.3.4",external_ip="5.6.7.8",system_uuid="6a934e21-5207-4a84-baea-3a952d926c80"} 1 + kube_node_info{container_runtime_version="rkt",kernel_version="kernel",kubelet_version="kubelet",kubeproxy_version="kubeproxy",node="127.0.0.1",os_image="osimage",pod_cidr="172.24.10.0/24",provider_id="provider://i-randomidentifier",internal_ip="1.2.3.4",internal_ip="fc00::",external_ip="5.6.7.8",system_uuid="6a934e21-5207-4a84-baea-3a952d926c80"} 1 kube_node_role{node="127.0.0.1",role="master"} 1 kube_node_spec_unschedulable{node="127.0.0.1"} 1 kube_node_status_allocatable{node="127.0.0.1",resource="cpu",unit="core"} 3