fix: Fixing k8s nodes and pods parsing error (#9581)
This commit is contained in:
parent
bfcd0f6bb1
commit
16597586f5
|
|
@ -26,26 +26,27 @@ func (ki *KubernetesInventory) gatherNode(n corev1.Node, acc telegraf.Accumulato
|
|||
}
|
||||
|
||||
for resourceName, val := range n.Status.Capacity {
|
||||
|
||||
switch resourceName {
|
||||
case "cpu":
|
||||
fields["capacity_cpu_cores"] = convertQuantity(string(val.Format), 1)
|
||||
fields["capacity_millicpu_cores"] = convertQuantity(string(val.Format), 1000)
|
||||
fields["capacity_cpu_cores"] = convertQuantity(val.String(), 1)
|
||||
fields["capacity_millicpu_cores"] = convertQuantity(val.String(), 1000)
|
||||
case "memory":
|
||||
fields["capacity_memory_bytes"] = convertQuantity(string(val.Format), 1)
|
||||
fields["capacity_memory_bytes"] = convertQuantity(val.String(), 1)
|
||||
case "pods":
|
||||
fields["capacity_pods"] = atoi(string(val.Format))
|
||||
fields["capacity_pods"] = atoi(val.String())
|
||||
}
|
||||
}
|
||||
|
||||
for resourceName, val := range n.Status.Allocatable {
|
||||
switch resourceName {
|
||||
case "cpu":
|
||||
fields["allocatable_cpu_cores"] = convertQuantity(string(val.Format), 1)
|
||||
fields["allocatable_millicpu_cores"] = convertQuantity(string(val.Format), 1000)
|
||||
fields["allocatable_cpu_cores"] = convertQuantity(val.String(), 1)
|
||||
fields["allocatable_millicpu_cores"] = convertQuantity(val.String(), 1000)
|
||||
case "memory":
|
||||
fields["allocatable_memory_bytes"] = convertQuantity(string(val.Format), 1)
|
||||
fields["allocatable_memory_bytes"] = convertQuantity(val.String(), 1)
|
||||
case "pods":
|
||||
fields["allocatable_pods"] = atoi(string(val.Format))
|
||||
fields["allocatable_pods"] = atoi(val.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,20 +50,20 @@ func TestNode(t *testing.T) {
|
|||
},
|
||||
Phase: "Running",
|
||||
Capacity: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "16"},
|
||||
"ephemeral_storage_bytes": resource.Quantity{Format: "49536401408"},
|
||||
"hugepages_1Gi_bytes": resource.Quantity{Format: "0"},
|
||||
"hugepages_2Mi_bytes": resource.Quantity{Format: "0"},
|
||||
"memory": resource.Quantity{Format: "125817904Ki"},
|
||||
"pods": resource.Quantity{Format: "110"},
|
||||
"cpu": resource.MustParse("16"),
|
||||
"ephemeral_storage_bytes": resource.MustParse("49536401408"),
|
||||
"hugepages_1Gi_bytes": resource.MustParse("0"),
|
||||
"hugepages_2Mi_bytes": resource.MustParse("0"),
|
||||
"memory": resource.MustParse("125817904Ki"),
|
||||
"pods": resource.MustParse("110"),
|
||||
},
|
||||
Allocatable: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "1000m"},
|
||||
"ephemeral_storage_bytes": resource.Quantity{Format: "44582761194"},
|
||||
"hugepages_1Gi_bytes": resource.Quantity{Format: "0"},
|
||||
"hugepages_2Mi_bytes": resource.Quantity{Format: "0"},
|
||||
"memory": resource.Quantity{Format: "125715504Ki"},
|
||||
"pods": resource.Quantity{Format: "110"},
|
||||
"cpu": resource.MustParse("1000m"),
|
||||
"ephemeral_storage_bytes": resource.MustParse("44582761194"),
|
||||
"hugepages_1Gi_bytes": resource.MustParse("0"),
|
||||
"hugepages_2Mi_bytes": resource.MustParse("0"),
|
||||
"memory": resource.MustParse("125715504Ki"),
|
||||
"pods": resource.MustParse("110"),
|
||||
},
|
||||
Conditions: []corev1.NodeCondition{
|
||||
{Type: "Ready", Status: "true", LastTransitionTime: metav1.Time{Time: now}},
|
||||
|
|
|
|||
|
|
@ -102,17 +102,17 @@ func gatherPodContainer(ki *KubernetesInventory, p corev1.Pod, cs corev1.Contain
|
|||
for resourceName, val := range req {
|
||||
switch resourceName {
|
||||
case "cpu":
|
||||
fields["resource_requests_millicpu_units"] = convertQuantity(string(val.Format), 1000)
|
||||
fields["resource_requests_millicpu_units"] = convertQuantity(val.String(), 1000)
|
||||
case "memory":
|
||||
fields["resource_requests_memory_bytes"] = convertQuantity(string(val.Format), 1)
|
||||
fields["resource_requests_memory_bytes"] = convertQuantity(val.String(), 1)
|
||||
}
|
||||
}
|
||||
for resourceName, val := range lim {
|
||||
switch resourceName {
|
||||
case "cpu":
|
||||
fields["resource_limits_millicpu_units"] = convertQuantity(string(val.Format), 1000)
|
||||
fields["resource_limits_millicpu_units"] = convertQuantity(val.String(), 1000)
|
||||
case "memory":
|
||||
fields["resource_limits_memory_bytes"] = convertQuantity(string(val.Format), 1)
|
||||
fields["resource_limits_memory_bytes"] = convertQuantity(val.String(), 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,10 +60,10 @@ func TestPod(t *testing.T) {
|
|||
},
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Limits: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -78,10 +78,10 @@ func TestPod(t *testing.T) {
|
|||
},
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Limits: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -96,10 +96,10 @@ func TestPod(t *testing.T) {
|
|||
},
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Limits: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -335,10 +335,10 @@ func TestPodSelectorFilter(t *testing.T) {
|
|||
},
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Limits: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -582,10 +582,10 @@ func TestPodPendingContainers(t *testing.T) {
|
|||
},
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Limits: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -600,10 +600,10 @@ func TestPodPendingContainers(t *testing.T) {
|
|||
},
|
||||
Resources: corev1.ResourceRequirements{
|
||||
Limits: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
Requests: corev1.ResourceList{
|
||||
"cpu": resource.Quantity{Format: "100m"},
|
||||
"cpu": resource.MustParse("100m"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue