-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathstructures_node.go
More file actions
113 lines (102 loc) · 2.77 KB
/
structures_node.go
File metadata and controls
113 lines (102 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright IBM Corp. 2017, 2025
// SPDX-License-Identifier: MPL-2.0
package kubernetes
import (
v1 "k8s.io/api/core/v1"
)
func flattenNodeSpec(in v1.NodeSpec) []interface{} {
att := make(map[string]interface{})
if in.PodCIDR != "" {
att["pod_cidr"] = in.PodCIDR
}
if len(in.PodCIDRs) > 0 {
att["pod_cidrs"] = in.PodCIDRs
}
if in.ProviderID != "" {
att["provider_id"] = in.ProviderID
}
att["unschedulable"] = in.Unschedulable
if len(in.Taints) > 0 {
att["taints"] = flattenNodeTaints(in.Taints...)
}
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 != "" {
att["machine_id"] = in.MachineID
}
if in.SystemUUID != "" {
att["system_uuid"] = in.SystemUUID
}
if in.BootID != "" {
att["boot_id"] = in.BootID
}
if in.KernelVersion != "" {
att["kernel_version"] = in.KernelVersion
}
if in.OSImage != "" {
att["os_image"] = in.OSImage
}
if in.ContainerRuntimeVersion != "" {
att["container_runtime_version"] = in.ContainerRuntimeVersion
}
if in.KubeletVersion != "" {
att["kubelet_version"] = in.KubeletVersion
}
//nolint:all
if in.KubeProxyVersion != "" {
att["kube_proxy_version"] = in.KubeProxyVersion
}
if in.OperatingSystem != "" {
att["operating_system"] = in.OperatingSystem
}
if in.Architecture != "" {
att["architecture"] = in.Architecture
}
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}
}
func flattenNodeTaints(in ...v1.Taint) []interface{} {
out := make([]interface{}, len(in))
for i, taint := range in {
m := make(map[string]interface{})
m["key"] = taint.Key
m["value"] = taint.Value
m["effect"] = taint.Effect
out[i] = m
}
return out
}