[ Agent ] [ CMII ] - 新增大量功能
This commit is contained in:
@@ -3,6 +3,7 @@ package k8s_exec
|
||||
import (
|
||||
v1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CmiiInterfaceConvert interface {
|
||||
@@ -17,6 +18,11 @@ type CmiiPodInterface struct {
|
||||
HostIP string
|
||||
NodeName string
|
||||
RestartCountMap map[string]int32
|
||||
ContainerName string
|
||||
Image string
|
||||
ImageTag string
|
||||
GitBranch string
|
||||
GitCommit string
|
||||
}
|
||||
|
||||
type CmiiDeploymentInterface struct {
|
||||
@@ -25,6 +31,11 @@ type CmiiDeploymentInterface struct {
|
||||
AvailableReplicas int32
|
||||
Replicas int32
|
||||
ContainerImageMap map[string]string
|
||||
ContainerName string
|
||||
Image string
|
||||
ImageTag string
|
||||
GitBranch string
|
||||
GitCommit string
|
||||
StatusOk bool
|
||||
}
|
||||
|
||||
@@ -33,8 +44,24 @@ func (deploy CmiiDeploymentInterface) Convert(deployment v1.Deployment) CmiiDepl
|
||||
containers := deployment.Spec.Template.Spec.Containers
|
||||
|
||||
containerImageMap := make(map[string]string, len(containers))
|
||||
if len(containers) > 1 {
|
||||
log.WarnF("[CmiiDeploymentInterface Convert] - deployment [%s] [%s] container greater than one !", deployment.Namespace, deployment.Name)
|
||||
}
|
||||
for _, container := range containers {
|
||||
containerImageMap[container.Name] = container.Image
|
||||
deploy.Image = container.Image
|
||||
deploy.ContainerName = container.Name
|
||||
deploy.ImageTag = strings.Split(container.Image, ":")[1]
|
||||
|
||||
for _, envVar := range container.Env {
|
||||
if strings.HasPrefix(envVar.Name, "GIT_BRANCH") {
|
||||
deploy.GitBranch = envVar.Value
|
||||
}
|
||||
|
||||
if strings.HasPrefix(envVar.Name, "GIT_COMMIT") {
|
||||
deploy.GitCommit = envVar.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deploy.Name = deployment.Name
|
||||
@@ -51,12 +78,30 @@ func (pod CmiiPodInterface) Convert(podDetail corev1.Pod) CmiiPodInterface {
|
||||
|
||||
containers := podDetail.Spec.Containers
|
||||
containerImageMap := make(map[string]string, len(containers))
|
||||
if len(containers) > 1 {
|
||||
log.WarnF("[CmiiDeploymentInterface Convert] - pod [%s] [%s] container greater than one !", podDetail.Namespace, podDetail.Name)
|
||||
}
|
||||
for _, container := range containers {
|
||||
containerImageMap[container.Name] = container.Image
|
||||
|
||||
pod.Image = container.Image
|
||||
pod.ContainerName = container.Name
|
||||
pod.ImageTag = strings.Split(container.Image, ":")[1]
|
||||
|
||||
for _, envVar := range container.Env {
|
||||
if strings.HasPrefix(envVar.Name, "GIT_BRANCH") {
|
||||
pod.GitBranch = envVar.Value
|
||||
}
|
||||
|
||||
if strings.HasPrefix(envVar.Name, "GIT_COMMIT") {
|
||||
pod.GitCommit = envVar.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
containerStatuses := podDetail.Status.ContainerStatuses
|
||||
containerStatusMap := make(map[string]int32, len(containerStatuses))
|
||||
|
||||
for _, containerStatus := range containerStatuses {
|
||||
containerStatusMap[containerStatus.Name] = containerStatus.RestartCount
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user