[ Agent ] [ CMII ] - 完成工具类的代码
This commit is contained in:
76
agent-go/k8s_exec/CmiiStatus.go
Normal file
76
agent-go/k8s_exec/CmiiStatus.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package k8s_exec
|
||||
|
||||
import (
|
||||
v1 "k8s.io/api/apps/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
type CmiiInterfaceConvert interface {
|
||||
}
|
||||
|
||||
type CmiiPodInterface struct {
|
||||
Name string
|
||||
Namespace string
|
||||
//ReplicaSetName string
|
||||
ContainerImageMap map[string]string
|
||||
PodIP string
|
||||
HostIP string
|
||||
NodeName string
|
||||
RestartCountMap map[string]int32
|
||||
}
|
||||
|
||||
type CmiiDeploymentInterface struct {
|
||||
Name string
|
||||
Namespace string
|
||||
AvailableReplicas int32
|
||||
Replicas int32
|
||||
ContainerImageMap map[string]string
|
||||
StatusOk bool
|
||||
}
|
||||
|
||||
func (deploy CmiiDeploymentInterface) Convert(deployment v1.Deployment) CmiiDeploymentInterface {
|
||||
|
||||
containers := deployment.Spec.Template.Spec.Containers
|
||||
|
||||
containerImageMap := make(map[string]string, len(containers))
|
||||
for _, container := range containers {
|
||||
containerImageMap[container.Name] = container.Image
|
||||
}
|
||||
|
||||
deploy.Name = deployment.Name
|
||||
deploy.Namespace = deployment.Namespace
|
||||
deploy.AvailableReplicas = deployment.Status.AvailableReplicas
|
||||
deploy.Replicas = *deployment.Spec.Replicas
|
||||
deploy.ContainerImageMap = containerImageMap
|
||||
deploy.StatusOk = deployment.Status.AvailableReplicas == *deployment.Spec.Replicas
|
||||
|
||||
return deploy
|
||||
}
|
||||
|
||||
func (pod CmiiPodInterface) Convert(podDetail corev1.Pod) CmiiPodInterface {
|
||||
|
||||
containers := podDetail.Spec.Containers
|
||||
containerImageMap := make(map[string]string, len(containers))
|
||||
for _, container := range containers {
|
||||
containerImageMap[container.Name] = container.Image
|
||||
}
|
||||
|
||||
containerStatuses := podDetail.Status.ContainerStatuses
|
||||
containerStatusMap := make(map[string]int32, len(containerStatuses))
|
||||
for _, containerStatus := range containerStatuses {
|
||||
containerStatusMap[containerStatus.Name] = containerStatus.RestartCount
|
||||
}
|
||||
|
||||
pod.Name = podDetail.Name
|
||||
pod.Namespace = podDetail.Namespace
|
||||
pod.ContainerImageMap = containerImageMap
|
||||
pod.RestartCountMap = containerStatusMap
|
||||
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
|
||||
//}
|
||||
|
||||
return pod
|
||||
}
|
||||
Reference in New Issue
Block a user