[ Agent ] [ CMII ] - 新增Node部分
This commit is contained in:
@@ -43,6 +43,27 @@ type CmiiDeploymentInterface struct {
|
||||
StatusOk bool
|
||||
}
|
||||
|
||||
type CmiiNodeInterface struct {
|
||||
Name string
|
||||
Hostname string
|
||||
InternalIP string
|
||||
KernelVersion string
|
||||
OsImage string
|
||||
Architecture string
|
||||
KubeletVersion string
|
||||
CpuCapacity string
|
||||
MemoryCapacity string
|
||||
PodCapacity string
|
||||
StorageCapacity string
|
||||
Labels map[string]string
|
||||
Unschedulable bool
|
||||
NodeStatus bool
|
||||
MemoryPressure bool
|
||||
DiskPressure bool
|
||||
PIDPressure bool
|
||||
NetworkUnavailable bool
|
||||
}
|
||||
|
||||
func (deploy CmiiDeploymentInterface) Convert(deployment v1.Deployment) CmiiDeploymentInterface {
|
||||
|
||||
containers := deployment.Spec.Template.Spec.Containers
|
||||
@@ -90,7 +111,9 @@ func (pod CmiiPodInterface) Convert(podDetail corev1.Pod) CmiiPodInterface {
|
||||
|
||||
pod.Image = container.Image
|
||||
pod.ContainerName = container.Name
|
||||
pod.ImageTag = strings.Split(container.Image, ":")[1]
|
||||
if strings.Contains(container.Image, ":") {
|
||||
pod.ImageTag = strings.Split(container.Image, ":")[1]
|
||||
}
|
||||
|
||||
for _, envVar := range container.Env {
|
||||
if strings.HasPrefix(envVar.Name, "GIT_BRANCH") {
|
||||
@@ -137,3 +160,60 @@ func (pod CmiiPodInterface) Convert(podDetail corev1.Pod) CmiiPodInterface {
|
||||
|
||||
return pod
|
||||
}
|
||||
|
||||
func (node CmiiNodeInterface) Convert(sourceNode corev1.Node) CmiiNodeInterface {
|
||||
|
||||
node.Name = sourceNode.Name
|
||||
for _, nodeAddress := range sourceNode.Status.Addresses {
|
||||
if nodeAddress.Type == corev1.NodeInternalIP {
|
||||
node.InternalIP = nodeAddress.Address
|
||||
}
|
||||
if nodeAddress.Type == corev1.NodeHostName {
|
||||
node.Hostname = nodeAddress.Address
|
||||
}
|
||||
}
|
||||
|
||||
node.KernelVersion = sourceNode.Status.NodeInfo.KernelVersion
|
||||
node.OsImage = sourceNode.Status.NodeInfo.OSImage
|
||||
node.KubeletVersion = sourceNode.Status.NodeInfo.KubeletVersion
|
||||
node.Architecture = sourceNode.Status.NodeInfo.Architecture
|
||||
|
||||
node.CpuCapacity = sourceNode.Status.Capacity.Cpu().String()
|
||||
node.MemoryCapacity = sourceNode.Status.Capacity.Memory().String()
|
||||
node.PodCapacity = sourceNode.Status.Capacity.Pods().String()
|
||||
node.StorageCapacity = sourceNode.Status.Capacity.Storage().String()
|
||||
|
||||
node.Labels = sourceNode.Labels
|
||||
|
||||
for _, nodeCondition := range sourceNode.Status.Conditions {
|
||||
switch nodeCondition.Type {
|
||||
case corev1.NodeReady:
|
||||
node.NodeStatus = uniformNodeConditionStatus(nodeCondition.Status)
|
||||
break
|
||||
case corev1.NodeMemoryPressure:
|
||||
node.MemoryPressure = uniformNodeConditionStatus(nodeCondition.Status)
|
||||
break
|
||||
case corev1.NodeDiskPressure:
|
||||
node.DiskPressure = uniformNodeConditionStatus(nodeCondition.Status)
|
||||
break
|
||||
case corev1.NodePIDPressure:
|
||||
node.PIDPressure = uniformNodeConditionStatus(nodeCondition.Status)
|
||||
break
|
||||
case corev1.NodeNetworkUnavailable:
|
||||
node.NetworkUnavailable = uniformNodeConditionStatus(nodeCondition.Status)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
node.Unschedulable = sourceNode.Spec.Unschedulable
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
func uniformNodeConditionStatus(conditionType corev1.ConditionStatus) bool {
|
||||
if conditionType == corev1.ConditionTrue {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user