-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathzedkubetypes.go
422 lines (379 loc) · 18.6 KB
/
zedkubetypes.go
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
// Copyright (c) 2024 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"time"
"github.com/lf-edge/eve-api/go/info"
"google.golang.org/protobuf/types/known/timestamppb"
)
// KubeNodeStatus - Enum for the status of a Kubernetes node
type KubeNodeStatus int8
const (
KubeNodeStatusUnknown KubeNodeStatus = iota // KubeNodeStatusUnknown - Node status is unknown
KubeNodeStatusReady // KubeNodeStatusReady - Node is in ready status
KubeNodeStatusNotReady // KubeNodeStatusNotReady - Node is in not ready status
KubeNodeStatusNotReachable // KubeNodeStatusNotReachable - Node is not reachable
)
// NodeAdmission - Enum for the admission status of a node in a cluster
type NodeAdmission uint8
const (
NodeAdmissionUnknown NodeAdmission = iota // NodeAdmissionUnknown - Node admission status is unknown
NodeAdmissionNotClustered // NodeAdmissionNotClustered - Node is not part of the cluster
NodeAdmissionLeaving // NodeAdmissionLeaving - Node is leaving the cluster
NodeAdmissionJoining // NodeAdmissionJoining - Node is joining the cluster
NodeAdmissionJoined // NodeAdmissionJoined - Node has joined the cluster
)
// ZNodeAdmission - Converts pubsub NodeAdmission to eve-api info.NodeAdmission
func (status NodeAdmission) ZNodeAdmission() info.NodeAdmission {
switch status {
case NodeAdmissionNotClustered:
return info.NodeAdmission_NODE_ADMISSION_NOT_CLUSTERED
case NodeAdmissionLeaving:
return info.NodeAdmission_NODE_ADMISSION_LEAVING
case NodeAdmissionJoining:
return info.NodeAdmission_NODE_ADMISSION_JOINING
case NodeAdmissionJoined:
return info.NodeAdmission_NODE_ADMISSION_JOINED
default:
return info.NodeAdmission_NODE_ADMISSION_UNSPECIFIED
}
}
// KubeNodeInfo - Information about a Kubernetes node
type KubeNodeInfo struct {
Name string
Status KubeNodeStatus
IsMaster bool
UsesEtcd bool
CreationTime time.Time
LastTransitionTime time.Time // Of Ready Condition
KubeletVersion string
InternalIP string
ExternalIP string
Schedulable bool
Admission NodeAdmission
NodeID string
}
// ZKubeNodeInfo - Converts pubsub KubeNodeInfo to eve-api info.KubeNodeInfo
func (kni KubeNodeInfo) ZKubeNodeInfo() *info.KubeNodeInfo {
iKni := new(info.KubeNodeInfo)
iKni.Name = kni.Name
rdyCondition := info.KubeNodeCondition{
Type: info.KubeNodeConditionType_KUBE_NODE_CONDITION_TYPE_READY,
Set: kni.Status == KubeNodeStatusReady,
LastTransitionTime: timestamppb.New(kni.LastTransitionTime),
}
iKni.Conditions = append(iKni.Conditions, &rdyCondition)
iKni.RoleServer = true
iKni.CreationTimestamp = timestamppb.New(kni.CreationTime)
iKni.ApiServerSersion = kni.KubeletVersion
iKni.InternalIp = kni.InternalIP
iKni.Schedulable = kni.Schedulable
iKni.AdmissionStatus = kni.Admission.ZNodeAdmission()
iKni.NodeId = kni.NodeID
return iKni
}
// KubePodStatus - Enum for the status of a Kubernetes pod
type KubePodStatus int8
const (
KubePodStatusUnknown KubePodStatus = iota // KubePodStatusUnknown - Pod status is unknown
KubePodStatusPending // KubePodStatusPending - Pod is in pending status
KubePodStatusRunning // KubePodStatusRunning - Pod is in running status
KubePodStatusSucceeded // KubePodStatusSucceeded - Pod is in succeeded status
KubePodStatusFailed // KubePodStatusFailed - Pod is in failed status
)
// ZKubePodStatus - Converts pubsub KubePodStatus to eve-api info.KubePodStatus
func (status KubePodStatus) ZKubePodStatus() info.KubePodStatus {
switch status {
case KubePodStatusUnknown:
return info.KubePodStatus_KUBE_POD_STATUS_UNSPECIFIED
case KubePodStatusPending:
return info.KubePodStatus_KUBE_POD_STATUS_PENDING
case KubePodStatusRunning:
return info.KubePodStatus_KUBE_POD_STATUS_RUNNING
case KubePodStatusSucceeded:
return info.KubePodStatus_KUBE_POD_STATUS_SUCCEEDED
case KubePodStatusFailed:
return info.KubePodStatus_KUBE_POD_STATUS_FAILED
default:
return info.KubePodStatus_KUBE_POD_STATUS_UNSPECIFIED
}
}
// KubePodInfo - Information about a Kubernetes pod
type KubePodInfo struct {
Name string
Status KubePodStatus
RestartCount int32
RestartTimestamp time.Time
CreationTimestamp time.Time
PodIP string
NodeName string
}
// ZKubeEVEAppPodInfo Converts pubsub KubePodInfo to eve-api info.KubeEVEAppPodInfo
func (kpi KubePodInfo) ZKubeEVEAppPodInfo() *info.KubeEVEAppPodInfo {
iKeapi := new(info.KubeEVEAppPodInfo)
iKeapi.Name = kpi.Name
iKeapi.Status = kpi.Status.ZKubePodStatus()
iKeapi.RestartCount = uint32(kpi.RestartCount)
iKeapi.RestartTimestamp = timestamppb.New(kpi.RestartTimestamp)
iKeapi.CreationTimestamp = timestamppb.New(kpi.CreationTimestamp)
iKeapi.IpAddress = kpi.PodIP
iKeapi.NodeName = kpi.NodeName
return iKeapi
}
// KubePodNameSpaceInfo - pod counts by state in a namespace of a Kubernetes cluster
type KubePodNameSpaceInfo struct {
// Name of the namespace
Name string
// Number of pods in the namespace
PodCount uint32
// Number of pods in the namespace that are running
PodRunningCount uint32
// Number of pods in the namespace that are pending
PodPendingCount uint32
// Number of pods in the namespace that are failed
PodFailedCount uint32
// Number of pods in the namespace that are succeeded
PodSucceededCount uint32
}
// KubeVMIStatus - Enum for the status of a VirtualMachineInstance
type KubeVMIStatus int8
const (
KubeVMIStatusUnset KubeVMIStatus = iota // KubeVMIStatusUnset - UnSet VMI status
KubeVMIStatusPending // KubeVMIStatusPending - VMI in pending status
KubeVMIStatusScheduling // KubeVMIStatusScheduling - VMI in Scheduling status
KubeVMIStatusScheduled // KubeVMIStatusScheduled - VMI in Scheduled status
KubeVMIStatusRunning // KubeVMIStatusRunning - VMI in Running status
KubeVMIStatusSucceeded // KubeVMIStatusSucceeded - VMI in Succeeded status
KubeVMIStatusFailed // KubeVMIStatusFailed - VMI in Failed status
KubeVMIStatusUnknown // KubeVMIStatusUnknown - VMI in Unknown status
)
// ZKubeVMIStatus - Converts pubsub KubeVMIStatus to eve-api info.KubeVMIStatus
func (status KubeVMIStatus) ZKubeVMIStatus() info.KubeVMIStatus {
switch status {
case KubeVMIStatusUnset:
return info.KubeVMIStatus_KUBE_VMI_STATUS_UNSPECIFIED
case KubeVMIStatusPending:
return info.KubeVMIStatus_KUBE_VMI_STATUS_PENDING
case KubeVMIStatusScheduling:
return info.KubeVMIStatus_KUBE_VMI_STATUS_SCHEDULING
case KubeVMIStatusScheduled:
return info.KubeVMIStatus_KUBE_VMI_STATUS_SCHEDULED
case KubeVMIStatusRunning:
return info.KubeVMIStatus_KUBE_VMI_STATUS_RUNNING
case KubeVMIStatusSucceeded:
return info.KubeVMIStatus_KUBE_VMI_STATUS_SUCCEEDED
case KubeVMIStatusFailed:
return info.KubeVMIStatus_KUBE_VMI_STATUS_FAILED
case KubeVMIStatusUnknown:
return info.KubeVMIStatus_KUBE_VMI_STATUS_UNKNOWN
default:
return info.KubeVMIStatus_KUBE_VMI_STATUS_UNKNOWN
}
}
// KubeVMIInfo - Information about a VirtualMachineInstance
type KubeVMIInfo struct {
Name string
Status KubeVMIStatus
CreationTime time.Time
LastTransitionTime time.Time
IsReady bool
NodeName string
}
// ZKubeVMIInfo - Converts KubeVMIInfo to info.KubeVMIInfo
func (kvi KubeVMIInfo) ZKubeVMIInfo() *info.KubeVMIInfo {
iKvi := new(info.KubeVMIInfo)
iKvi.Name = kvi.Name
iKvi.Status = kvi.Status.ZKubeVMIStatus()
iKvi.CreationTime = timestamppb.New(kvi.CreationTime)
iKvi.LastTransitionTime = timestamppb.New(kvi.LastTransitionTime)
iKvi.IsReady = kvi.IsReady
iKvi.NodeName = kvi.NodeName
return iKvi
}
// KubeClusterInfo - Information about a Kubernetes cluster
type KubeClusterInfo struct {
Nodes []KubeNodeInfo // List of nodes in the cluster
AppPods []KubePodInfo // List of EVE application pods
AppVMIs []KubeVMIInfo // List of VirtualMachineInstance
Storage KubeStorageInfo // Distributed storage info
PodNsInfo []KubePodNameSpaceInfo // General namespace pod running/failed count
}
// StorageHealthStatus - Enum for the redundancy level and replication status of a storage volume
type StorageHealthStatus uint8
const (
StorageHealthStatusUnknown StorageHealthStatus = iota // StorageHealthStatusUnknown - Storage health status is unknown
StorageHealthStatusHealthy // StorageHealthStatusHealthy - All replicas healthy
StorageHealthStatusDegraded2ReplicaAvailableReplicating // StorageHealthStatusDegraded2ReplicaAvailableReplicating - replicating to third replica
StorageHealthStatusDegraded2ReplicaAvailableNotReplicating // StorageHealthStatusDegraded2ReplicaAvailableNotReplicating - not replicating to third replica
StorageHealthStatusDegraded1ReplicaAvailableReplicating // StorageHealthStatusDegraded1ReplicaAvailableReplicating - replicating to one or two replicas
StorageHealthStatusDegraded1ReplicaAvailableNotReplicating // StorageHealthStatusDegraded1ReplicaAvailableNotReplicating - no redundancy, not replicating
StorageHealthStatusFailed // StorageHealthStatusFailed - no healthy replicas
)
// StorageVolumeState - Enum for the attachment state of a storage volume
type StorageVolumeState uint8
const (
StorageVolumeStateUnknown StorageVolumeState = iota // StorageVolumeStateUnknown - Volume state is unknown
StorageVolumeStateCreating // StorageVolumeStateCreating - Volume is being created
StorageVolumeStateAttached // StorageVolumeStateAttached - Volume is attached
StorageVolumeStateDetached // StorageVolumeStateDetached - Volume is detached
StorageVolumeStateAttaching // StorageVolumeStateAttaching - Volume is being attached
StorageVolumeStateDetaching // StorageVolumeStateDetaching - Volume is being detached
StorageVolumeStateDeleting // StorageVolumeStateDeleting - Volume is being deleted
)
// ZStorageVolumeState - Converts pubsub StorageVolumeState to eve-api info.StorageVolumeState
func (svs StorageVolumeState) ZStorageVolumeState() info.StorageVolumeState {
switch svs {
case StorageVolumeStateUnknown:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_UNSPECIFIED
case StorageVolumeStateCreating:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_CREATING
case StorageVolumeStateAttached:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_ATTACHED
case StorageVolumeStateDetached:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_DETACHED
case StorageVolumeStateAttaching:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_ATTACHING
case StorageVolumeStateDetaching:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_DETACHING
case StorageVolumeStateDeleting:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_DELETING
default:
return info.StorageVolumeState_STORAGE_VOLUME_STATE_UNSPECIFIED
}
}
// StorageVolumeRobustness - Enum for the replica robustness of a storage volume
type StorageVolumeRobustness uint8
const (
StorageVolumeRobustnessUnknown StorageVolumeRobustness = iota // StorageVolumeRobustnessUnknown - Volume robustness is unknown
StorageVolumeRobustnessHealthy // StorageVolumeRobustnessHealthy - All Volume replicas healthy
StorageVolumeRobustnessDegraded // StorageVolumeRobustnessDegraded - One or more Volume replicas degraded
StorageVolumeRobustnessFaulted // StorageVolumeRobustnessFaulted - no healthy replicas
)
// StorageVolumePvcStatus - Enum for the status of a PVC associated with a volume instance
type StorageVolumePvcStatus uint8
const (
StorageVolumePvcStatusUnknown StorageVolumePvcStatus = iota // StorageVolumePvcStatusUnknown - PVC status is unknown
StorageVolumePvcStatusBound // StorageVolumePvcStatusBound - PVC is bound
StorageVolumePvcStatusPending // StorageVolumePvcStatusPending - PVC is pending
StorageVolumePvcStatusAvailable // StorageVolumePvcStatusAvailable - PVC is available
StorageVolumePvcStatusReleased // StorageVolumePvcStatusReleased - PVC is released
StorageVolumePvcStatusFaulted // StorageVolumePvcStatusFaulted - PVC is faulted
)
// StorageVolumeReplicaStatus - Enum for the status of a replica of a storage volume
type StorageVolumeReplicaStatus uint8
const (
StorageVolumeReplicaStatusUnknown StorageVolumeReplicaStatus = iota // StorageVolumeReplicaStatusUnknown - Replica status is unknown
StorageVolumeReplicaStatusRebuilding // StorageVolumeReplicaStatusRebuilding - Replica is rebuilding
StorageVolumeReplicaStatusOnline // StorageVolumeReplicaStatusOnline - Replica is online
StorageVolumeReplicaStatusFailed // StorageVolumeReplicaStatusFailed - Replica has failed
StorageVolumeReplicaStatusOffline // StorageVolumeReplicaStatusOffline - Replica is offline
StorageVolumeReplicaStatusStarting // StorageVolumeReplicaStatusStarting - Replica is starting
StorageVolumeReplicaStatusStopping // StorageVolumeReplicaStatusStopping - Replica is stopping
)
// ZStorageVolumeReplicaStatus - Converts pubsub StorageVolumeReplicaStatus to eve-api info.StorageVolumeReplicaStatus
func (svrs StorageVolumeReplicaStatus) ZStorageVolumeReplicaStatus() info.StorageVolumeReplicaStatus {
switch svrs {
case StorageVolumeReplicaStatusUnknown:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_UNSPECIFIED
case StorageVolumeReplicaStatusRebuilding:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_REBUILDING
case StorageVolumeReplicaStatusOnline:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_ONLINE
case StorageVolumeReplicaStatusFailed:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_FAILED
case StorageVolumeReplicaStatusOffline:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_OFFLINE
case StorageVolumeReplicaStatusStarting:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_STARTING
case StorageVolumeReplicaStatusStopping:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_STOPPING
default:
return info.StorageVolumeReplicaStatus_STORAGE_VOLUME_REPLICA_STATUS_UNSPECIFIED
}
}
// KubeVolumeReplicaInfo - Information about a replica of a clustered volume in a kubernetes cluster
type KubeVolumeReplicaInfo struct {
Name string
OwnerNode string
RebuildProgressPercentage uint8
Status StorageVolumeReplicaStatus
}
// ZKubeVolumeReplicaInfo - Converts pubsub KubeVolumeReplicaInfo to eve-api info.KubeVolumeReplicaInfo
func (kvri KubeVolumeReplicaInfo) ZKubeVolumeReplicaInfo() *info.KubeVolumeReplicaInfo {
iKvri := new(info.KubeVolumeReplicaInfo)
iKvri.Name = kvri.Name
iKvri.OwnerNode = kvri.OwnerNode
iKvri.RebuildProgressPercentage = uint32(kvri.RebuildProgressPercentage)
iKvri.Status = kvri.Status.ZStorageVolumeReplicaStatus()
return iKvri
}
// KubeVolumeInfo - Information about a clustered volume in a kubernetes cluster
type KubeVolumeInfo struct {
Name string
State StorageVolumeState
Robustness StorageVolumeRobustness
CreatedAt time.Time
ProvisionedBytes uint64
AllocatedBytes uint64
PvcStatus StorageVolumePvcStatus
Replicas []KubeVolumeReplicaInfo
RobustnessSubstate StorageHealthStatus
VolumeID string
}
// ZKubeVolumeInfo - Converts pubsub KubeVolumeInfo to eve-api info.KubeVolumeInfo
func (kvi KubeVolumeInfo) ZKubeVolumeInfo() *info.KubeVolumeInfo {
iKvi := new(info.KubeVolumeInfo)
iKvi.Name = kvi.Name
iKvi.State = kvi.State.ZStorageVolumeState()
iKvi.Robustness = info.StorageVolumeRobustness(kvi.Robustness)
iKvi.CreationTimestamp = timestamppb.New(kvi.CreatedAt)
iKvi.ProvisionedBytes = kvi.ProvisionedBytes
iKvi.AllocatedBytes = kvi.AllocatedBytes
iKvi.PvcStatus = info.StorageVolumePVCStatus(kvi.PvcStatus)
for _, rep := range kvi.Replicas {
iKvi.Replica = append(iKvi.Replica, rep.ZKubeVolumeReplicaInfo())
}
iKvi.RobustnessSubstate = info.StorageHealthStatus(kvi.RobustnessSubstate)
iKvi.VolumeId = kvi.VolumeID
return iKvi
}
// ServiceStatus - Enum for the status of a service
type ServiceStatus int8
const (
ServiceStatusUnset ServiceStatus = iota // ServiceStatusUnset - Service status is unset
ServiceStatusFailed // ServiceStatusFailed - Service status is failed
ServiceStatusDegraded // ServiceStatusDegraded - Service status is degraded
ServiceStatusHealthy // ServiceStatusHealthy - Service status is healthy
)
// ZServiceStatus - Converts pubsub ServiceStatus to eve-api info.ServiceStatus
func (state ServiceStatus) ZServiceStatus() info.ServiceStatus {
switch state {
case ServiceStatusUnset:
return info.ServiceStatus_SERVICE_STATUS_UNSPECIFIED
case ServiceStatusFailed:
return info.ServiceStatus_SERVICE_STATUS_FAILED
case ServiceStatusDegraded:
return info.ServiceStatus_SERVICE_STATUS_DEGRADED
case ServiceStatusHealthy:
return info.ServiceStatus_SERVICE_STATUS_HEALTHY
default:
return info.ServiceStatus_SERVICE_STATUS_UNSPECIFIED
}
}
// KubeStorageInfo - Information about the storage services health in a Kubernetes cluster
// This also includes all clustered volumes
type KubeStorageInfo struct {
Health ServiceStatus
TransitionTime time.Time
Volumes []KubeVolumeInfo
}
// ZKubeStorageInfo - Converts pubsub KubeStorageInfo to eve-api info.KubeStorageInfo
func (ksi KubeStorageInfo) ZKubeStorageInfo() *info.KubeStorageInfo {
iKsi := new(info.KubeStorageInfo)
iKsi.TransitionTime = timestamppb.New(ksi.TransitionTime)
iKsi.Health = ksi.Health.ZServiceStatus()
for _, vol := range ksi.Volumes {
iKsi.Volumes = append(iKsi.Volumes, vol.ZKubeVolumeInfo())
}
return iKsi
}