[ Agent ] [ CMII ] - 新增Node部分

This commit is contained in:
zeaslity
2024-01-11 14:54:01 +08:00
parent bc231b0866
commit 3800dc57af
19 changed files with 2036 additions and 143 deletions

View File

@@ -34,6 +34,7 @@ const (
integration = "uavcloud-test"
uat = "uavcloud-uat"
demo = "uavcloud-demo"
uavms = "uavcloud-uavms"
workerThread = 4
)
@@ -106,6 +107,10 @@ func (op *CmiiK8sOperator) changeOperatorEnv(cmiiEnv string) {
op.CurrentNamespace = demo
}
if strings.Contains(cmiiEnv, "uavms") {
op.CurrentNamespace = uavms
}
if op.CurrentNamespace == "" {
op.CurrentNamespace = dev
}
@@ -528,6 +533,12 @@ func (op *CmiiK8sOperator) PodAllInterface(cmiiEnv string) []CmiiPodInterface {
return results[:index]
}
// PodAllInSpecificNode cmiiEnv aims to specific k8s cluster
func PodAllInSpecificNode(cmiiEnv, nodeName string) (podList []CmiiPodInterface) {
return nil
}
func (op *CmiiK8sOperator) PodFizz(cmiiEnv, appFizz string) (fizzPod []corev1.Pod) {
podAll := op.PodAll(cmiiEnv)
@@ -545,3 +556,55 @@ func (op *CmiiK8sOperator) PodFizz(cmiiEnv, appFizz string) (fizzPod []corev1.Po
return fizzPod
}
func (op *CmiiK8sOperator) PodDelete(cmiiEnv, podName string) bool {
op.changeOperatorEnv(cmiiEnv)
client := op.CurrentClient
pod, err := client.CoreV1().Pods(op.CurrentNamespace).Get(context.TODO(), podName, metav1.GetOptions{})
if err != nil {
log.ErrorF("[PodDelete] - [%s] [%s] not exists", cmiiEnv, podName)
return false
}
// pod exists
err = client.CoreV1().Pods(op.CurrentNamespace).Delete(context.TODO(), pod.Name, metav1.DeleteOptions{})
if err != nil {
log.ErrorF("[PodDelete] - [%s] [%s] delete error ! %s", cmiiEnv, podName, err.Error())
return false
}
return true
}
func (op *CmiiK8sOperator) NodeAll(cmiiEnv string) (nodeListR []corev1.Node) {
op.changeOperatorEnv(cmiiEnv)
client := op.CurrentClient
nodeList, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
log.ErrorF("[NodeAll] - [%s] list all node failed %s", cmiiEnv, err.Error())
return nil
}
for _, node := range nodeList.Items {
node.SetManagedFields(nil)
nodeListR = append(nodeListR, node)
}
return nodeListR
}
func (op *CmiiK8sOperator) NodeAllInterface(cmiiEnv string) (nodeList []CmiiNodeInterface) {
nodeListR := op.NodeAll(cmiiEnv)
nodeInterface := CmiiNodeInterface{}
for _, node := range nodeListR {
nodeList = append(nodeList, nodeInterface.Convert(node))
}
return nodeList
}