[ Agent ] [ App ] - offline fix bugs

This commit is contained in:
zeaslity
2023-12-15 14:56:34 +08:00
parent a3185f0241
commit 3312052645
4 changed files with 66 additions and 16 deletions

View File

@@ -47,6 +47,15 @@ func newK8sClientInstance() *kubernetes.Clientset {
func K8sCheckPodStatusTimeout(specificPod string, supreme string, waitTimeOut int) bool {
if k8sClient == nil {
// 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
}
}
// 设置超时时间和时间间隔
timeout := time.After(time.Duration(waitTimeOut) * time.Second)
tick := time.Tick(5 * time.Second)
@@ -73,6 +82,15 @@ func K8sCheckPodStatusTimeout(specificPod string, supreme string, waitTimeOut in
func K8sCheckDeploymentStatusTimeout(specificDeployment string, supreme string, waitTimeOut int) bool {
if k8sClient == nil {
// 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
}
}
// 设置超时时间和时间间隔
timeout := time.After(time.Duration(waitTimeOut) * time.Second)
tick := time.Tick(5 * time.Second)
@@ -102,8 +120,14 @@ func K8sCheckDeploymentStatusTimeout(specificDeployment string, supreme string,
func K8sListPVCInNamespace(supreme string) (bool, []string) {
if k8sClient == nil {
log.ErrorF("k8s client is nil, run k8s function error !")
return false, nil
// 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, []string{
"[K8sListPVCInNamespace] - k8s client not exits !",
}
}
}
pvcs, err := k8sClient.CoreV1().PersistentVolumeClaims(supreme).List(context.TODO(), metav1.ListOptions{})
@@ -124,8 +148,12 @@ func K8sListPVCInNamespace(supreme string) (bool, []string) {
func K8sCheckPVCStatusTimeOut(specificPvcName string, supreme string, waitTimeOut int) 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
}
}
// 设置超时时间和时间间隔
@@ -287,7 +315,16 @@ func K8sCreateNamespace(namespaceName string) bool {
return true
}
func K8sGetDashBoardAuthKey() {
func K8sGetDashBoardAuthKey() bool {
if k8sClient == nil {
// 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
}
}
// 获取 kube-system 命名空间的 secrets 列表
secrets, err := k8sClient.CoreV1().Secrets("kube-system").List(context.TODO(), metav1.ListOptions{})
@@ -323,4 +360,6 @@ func K8sGetDashBoardAuthKey() {
fmt.Printf("%s: %s\n", key, value)
}
return false
}