[ Agent ] [ CMII ] - 新增大量功能 - 1

This commit is contained in:
zeaslity
2024-01-10 16:45:41 +08:00
parent 7ce838289b
commit bc231b0866
6 changed files with 251 additions and 345 deletions

View File

@@ -1,6 +1,7 @@
package k8s_exec
import (
"agent-go/utils"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"strings"
@@ -18,11 +19,14 @@ type CmiiPodInterface struct {
HostIP string
NodeName string
RestartCountMap map[string]int32
RestartCount int32
ContainerName string
Image string
ImageTag string
GitBranch string
GitCommit string
PodStatus bool
PodPhase corev1.PodPhase
}
type CmiiDeploymentInterface struct {
@@ -104,6 +108,7 @@ func (pod CmiiPodInterface) Convert(podDetail corev1.Pod) CmiiPodInterface {
for _, containerStatus := range containerStatuses {
containerStatusMap[containerStatus.Name] = containerStatus.RestartCount
pod.RestartCount = utils.MaxInt32(pod.RestartCount, containerStatus.RestartCount)
}
pod.Name = podDetail.Name
@@ -113,9 +118,22 @@ func (pod CmiiPodInterface) Convert(podDetail corev1.Pod) CmiiPodInterface {
pod.PodIP = podDetail.Status.PodIP
pod.HostIP = podDetail.Status.HostIP
pod.NodeName = podDetail.Spec.NodeName
//if len(podDetail.ObjectMeta.OwnerReferences) > 0 {
// pod.ReplicaSetName = podDetail.ObjectMeta.OwnerReferences[0].Name
//}
pod.PodPhase = podDetail.Status.Phase
switch podDetail.Status.Phase {
case corev1.PodFailed:
pod.PodStatus = false
break
case corev1.PodPending:
pod.PodStatus = false
break
case corev1.PodReasonUnschedulable:
pod.PodStatus = false
break
default:
pod.PodStatus = true
break
}
return pod
}