[ Agent ] [ App ] - fix some bugs

This commit is contained in:
zeaslity
2023-12-04 16:46:50 +08:00
parent 22ac34ae4e
commit 004c0ba184
6 changed files with 28 additions and 27 deletions

View File

@@ -241,15 +241,15 @@ func KubectlDeleteExec(resourcesYamlFile string) (bool, []string) {
func K8sCreateNamespace(namespaceName string) bool {
if k8sClient == nil {
log.ErrorF("k8s client is nil, run k8s function error !")
return false
// this should be the first call of k8s function
k8sClient = newK8sClientInstance()
if k8sClient == nil {
log.ErrorF("k8s client is nil, run k8s function error !")
return false
}
}
namespace, err := k8sClient.CoreV1().Namespaces().Get(context.TODO(), namespaceName, metav1.GetOptions{})
if err != nil {
log.ErrorF("Error getting namespace: %s ", err.Error())
return false
}
namespace, _ := k8sClient.CoreV1().Namespaces().Get(context.TODO(), namespaceName, metav1.GetOptions{})
if namespace != nil {
log.InfoF("[K8sCreateNamespace] - namespace of [%s] already exists!", namespaceName)
return true
@@ -263,6 +263,7 @@ func K8sCreateNamespace(namespaceName string) bool {
},
}
// 使用客户端创建命名空间
var err error
namespace, err = k8sClient.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{})
if err != nil {
log.ErrorF("Error getting namespace: %s ", err.Error())