Skip to content

Commit c9a7c08

Browse files
Arta AsadiArta Asadi
authored andcommitted
fix: have most of the structs
1 parent a84c8d9 commit c9a7c08

File tree

2 files changed

+110
-93
lines changed

2 files changed

+110
-93
lines changed

cloudql/kubernetes/table_kubernetes_node.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,21 @@ func transformNodeCpuAndMemoryUnit(_ context.Context, d *transform.TransformData
197197

198198
switch param {
199199
case "Capacity.CPU":
200-
return normalizeCPUToMilliCores(node.Status.Capacity.Cpu().String())
200+
if v, ok := node.Status.Capacity["cpu"]; ok {
201+
return v, nil
202+
}
201203
case "Capacity.Memory":
202-
return normalizeMemoryToBytes(node.Status.Capacity.Memory().String())
204+
if v, ok := node.Status.Capacity["memory"]; ok {
205+
return v, nil
206+
}
203207
case "Allocatable.CPU":
204-
return normalizeCPUToMilliCores(node.Status.Allocatable.Cpu().String())
208+
if v, ok := node.Status.Allocatable["cpu"]; ok {
209+
return v, nil
210+
}
205211
case "Allocatable.Memory":
206-
return normalizeMemoryToBytes(node.Status.Allocatable.Memory().String())
212+
if v, ok := node.Status.Allocatable["memory"]; ok {
213+
return v, nil
214+
}
207215
}
208216

209217
return nil, nil
@@ -215,13 +223,21 @@ func transformNodeCpuAndMemory(_ context.Context, d *transform.TransformData) (a
215223
node := d.HydrateItem.(opengovernance.KubernetesNode).Description.Node
216224
switch param {
217225
case "Capacity.CPU":
218-
return node.Status.Capacity.Cpu().String(), nil
226+
if v, ok := node.Status.Capacity["cpu"]; ok {
227+
return v, nil
228+
}
219229
case "Capacity.Memory":
220-
return node.Status.Capacity.Memory().String(), nil
230+
if v, ok := node.Status.Capacity["memory"]; ok {
231+
return v, nil
232+
}
221233
case "Allocatable.CPU":
222-
return node.Status.Allocatable.Cpu().String(), nil
234+
if v, ok := node.Status.Allocatable["cpu"]; ok {
235+
return v, nil
236+
}
223237
case "Allocatable.Memory":
224-
return node.Status.Allocatable.Memory().String(), nil
238+
if v, ok := node.Status.Allocatable["memory"]; ok {
239+
return v, nil
240+
}
225241
}
226242

227243
return nil, nil

cloudql/kubernetes/table_kubernetes_pod.go

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ func tableKubernetesPod(ctx context.Context) *plugin.Table {
2929
Description: "List of containers belonging to the pod.",
3030
Transform: transform.FromField("Description.Pod.Spec.Containers"),
3131
},
32-
{
33-
Name: "containers_resources_limits_std",
34-
Type: proto.ColumnType_JSON,
35-
Description: "Standardized CPU and memory resource limits in millicores for each container in the pod.",
36-
Transform: transform.FromP(transformPodCpuAndMemoryUnit, "limit"),
37-
},
38-
{
39-
Name: "containers_resources_requests_std",
40-
Type: proto.ColumnType_JSON,
41-
Description: "Standardized CPU and memory resource requests in millicores for each container in the pod.",
42-
Transform: transform.FromP(transformPodCpuAndMemoryUnit, "request"),
43-
},
32+
//{
33+
// Name: "containers_resources_limits_std",
34+
// Type: proto.ColumnType_JSON,
35+
// Description: "Standardized CPU and memory resource limits in millicores for each container in the pod.",
36+
// Transform: transform.FromP(transformPodCpuAndMemoryUnit, "limit"),
37+
//},
38+
//{
39+
// Name: "containers_resources_requests_std",
40+
// Type: proto.ColumnType_JSON,
41+
// Description: "Standardized CPU and memory resource requests in millicores for each container in the pod.",
42+
// Transform: transform.FromP(transformPodCpuAndMemoryUnit, "request"),
43+
//},
4444
{
4545
Name: "ephemeral_containers",
4646
Type: proto.ColumnType_JSON,
@@ -403,76 +403,77 @@ func transformPodTags(_ context.Context, d *transform.TransformData) (interface{
403403
return mergeTags(obj.Labels, obj.Annotations), nil
404404
}
405405

406-
func transformPodCpuAndMemoryUnit(ctx context.Context, d *transform.TransformData) (interface{}, error) {
407-
param := d.Param.(string)
408-
409-
pod := d.HydrateItem.(opengovernance.KubernetesPod).Description.Pod
410-
411-
containers := pod.Spec.DeepCopy().Containers
412-
413-
if param == "limit" {
414-
limitCPUMemoryMaps := make([]map[string]interface{}, 0)
415-
416-
limitCPUMemoryMap := make(map[string]interface{})
417-
418-
for _, container := range containers {
419-
limit := container.Resources.Limits
420-
limitCPUMemoryMap["containerName"] = container.Name
421-
limitCPUMemoryMap["containerImage"] = container.Image
422-
if limit.Cpu().String() != "" && !limit.Cpu().IsZero() {
423-
cpu, err := normalizeCPUToMilliCores(limit.Cpu().String())
424-
if err != nil {
425-
plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the CPU value", err)
426-
return nil, err
427-
}
428-
limitCPUMemoryMap["cpu"] = cpu
429-
}
430-
431-
if limit.Memory().String() != "" && !limit.Memory().IsZero() {
432-
memory, err := normalizeMemoryToBytes(limit.Memory().String())
433-
if err != nil {
434-
plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the memory value", err)
435-
return nil, err
436-
}
437-
limitCPUMemoryMap["memory"] = memory
438-
}
439-
limitCPUMemoryMaps = append(limitCPUMemoryMaps, limitCPUMemoryMap)
440-
441-
}
442-
443-
return limitCPUMemoryMaps, nil
444-
} else if param == "request" {
445-
requestCPUMemoryMaps := make([]map[string]interface{}, 0)
446-
447-
requestCPUMemoryMap := make(map[string]interface{})
448-
449-
for _, container := range containers {
450-
request := container.Resources.Requests
451-
requestCPUMemoryMap["containerName"] = container.Name
452-
requestCPUMemoryMap["containerImage"] = container.Image
453-
if request.Cpu().String() != "" && !request.Cpu().IsZero() {
454-
cpu, err := normalizeCPUToMilliCores(request.Cpu().String())
455-
if err != nil {
456-
plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the CPU value", err)
457-
return nil, err
458-
}
459-
requestCPUMemoryMap["cpu"] = cpu
460-
}
461-
462-
if request.Memory().String() != "" && !request.Memory().IsZero() {
463-
memory, err := normalizeMemoryToBytes(request.Memory().String())
464-
if err != nil {
465-
plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the memory value", err)
466-
return nil, err
467-
}
468-
requestCPUMemoryMap["memory"] = memory
469-
}
470-
requestCPUMemoryMaps = append(requestCPUMemoryMaps, requestCPUMemoryMap)
471-
472-
}
473-
474-
return requestCPUMemoryMaps, nil
475-
}
476-
477-
return nil, nil
478-
}
406+
//
407+
//func transformPodCpuAndMemoryUnit(ctx context.Context, d *transform.TransformData) (interface{}, error) {
408+
// param := d.Param.(string)
409+
//
410+
// pod := d.HydrateItem.(opengovernance.KubernetesPod).Description.Pod
411+
//
412+
// containers := pod.Spec.Containers
413+
//
414+
// if param == "limit" {
415+
// limitCPUMemoryMaps := make([]map[string]interface{}, 0)
416+
//
417+
// limitCPUMemoryMap := make(map[string]interface{})
418+
//
419+
// for _, container := range containers {
420+
// limit := container.Resources.Limits
421+
// limitCPUMemoryMap["containerName"] = container.Name
422+
// limitCPUMemoryMap["containerImage"] = container.Image
423+
// if limit.Cpu().String() != "" && !limit.Cpu().IsZero() {
424+
// cpu, err := normalizeCPUToMilliCores(limit.Cpu().String())
425+
// if err != nil {
426+
// plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the CPU value", err)
427+
// return nil, err
428+
// }
429+
// limitCPUMemoryMap["cpu"] = cpu
430+
// }
431+
//
432+
// if limit.Memory().String() != "" && !limit.Memory().IsZero() {
433+
// memory, err := normalizeMemoryToBytes(limit.Memory().String())
434+
// if err != nil {
435+
// plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the memory value", err)
436+
// return nil, err
437+
// }
438+
// limitCPUMemoryMap["memory"] = memory
439+
// }
440+
// limitCPUMemoryMaps = append(limitCPUMemoryMaps, limitCPUMemoryMap)
441+
//
442+
// }
443+
//
444+
// return limitCPUMemoryMaps, nil
445+
// } else if param == "request" {
446+
// requestCPUMemoryMaps := make([]map[string]interface{}, 0)
447+
//
448+
// requestCPUMemoryMap := make(map[string]interface{})
449+
//
450+
// for _, container := range containers {
451+
// request := container.Resources.Requests
452+
// requestCPUMemoryMap["containerName"] = container.Name
453+
// requestCPUMemoryMap["containerImage"] = container.Image
454+
// if request.Cpu().String() != "" && !request.Cpu().IsZero() {
455+
// cpu, err := normalizeCPUToMilliCores(request.Cpu().String())
456+
// if err != nil {
457+
// plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the CPU value", err)
458+
// return nil, err
459+
// }
460+
// requestCPUMemoryMap["cpu"] = cpu
461+
// }
462+
//
463+
// if request.Memory().String() != "" && !request.Memory().IsZero() {
464+
// memory, err := normalizeMemoryToBytes(request.Memory().String())
465+
// if err != nil {
466+
// plugin.Logger(ctx).Error("k8_pod.transformPodCpuAndMemoryUnit", "error in parsing the memory value", err)
467+
// return nil, err
468+
// }
469+
// requestCPUMemoryMap["memory"] = memory
470+
// }
471+
// requestCPUMemoryMaps = append(requestCPUMemoryMaps, requestCPUMemoryMap)
472+
//
473+
// }
474+
//
475+
// return requestCPUMemoryMaps, nil
476+
// }
477+
//
478+
// return nil, nil
479+
//}

0 commit comments

Comments
 (0)