From 0622e876a619438c9064161a668bf0418fc7bb89 Mon Sep 17 00:00:00 2001 From: ghostloda <78798447@qq.com> Date: Wed, 22 May 2024 15:15:30 +0800 Subject: [PATCH 1/2] fix control-plane component status --- pkg/checker/cluster_checker.go | 38 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/pkg/checker/cluster_checker.go b/pkg/checker/cluster_checker.go index 0d74ec96cd9..425d5e30860 100644 --- a/pkg/checker/cluster_checker.go +++ b/pkg/checker/cluster_checker.go @@ -21,6 +21,7 @@ import ( "os" "time" + corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/labring/sealos/pkg/client-go/kubernetes" @@ -67,23 +68,25 @@ func (n *ClusterChecker) Check(cluster *v2.Cluster, phase string) error { IP: ip, Node: node.Name, } - apiPod, err := ke.FetchStaticPod(ctx, node.Name, kubernetes.KubeAPIServer) - if err != nil { - return err - } - cStatus.KubeAPIServer = healthyClient.ForHealthyPod(apiPod) + if isControlPlaneNode(node) { + apiPod, err := ke.FetchStaticPod(ctx, node.Name, kubernetes.KubeAPIServer) + if err != nil { + return err + } + cStatus.KubeAPIServer = healthyClient.ForHealthyPod(apiPod) - controllerPod, err := ke.FetchStaticPod(ctx, node.Name, kubernetes.KubeControllerManager) - if err != nil { - return err - } - cStatus.KubeControllerManager = healthyClient.ForHealthyPod(controllerPod) + controllerPod, err := ke.FetchStaticPod(ctx, node.Name, kubernetes.KubeControllerManager) + if err != nil { + return err + } + cStatus.KubeControllerManager = healthyClient.ForHealthyPod(controllerPod) - schedulerPod, err := ke.FetchStaticPod(ctx, node.Name, kubernetes.KubeScheduler) - if err != nil { - return err + schedulerPod, err := ke.FetchStaticPod(ctx, node.Name, kubernetes.KubeScheduler) + if err != nil { + return err + } + cStatus.KubeScheduler = healthyClient.ForHealthyPod(schedulerPod) } - cStatus.KubeScheduler = healthyClient.ForHealthyPod(schedulerPod) if err = healthyClient.ForHealthyKubelet(5*time.Second, ip); err != nil { cStatus.KubeletErr = err.Error() @@ -96,6 +99,13 @@ func (n *ClusterChecker) Check(cluster *v2.Cluster, phase string) error { return n.Output(NodeList) } +func isControlPlaneNode(node corev1.Node) bool { + if _, ok := node.Labels["node-role.kubernetes.io/control-plane"]; ok { + return true + } + return false +} + func (n *ClusterChecker) Output(clusterStatus []ClusterStatus) error { tpl, isOk, err := template.TryParse(` Cluster Status From 50a0fe92f9fcb8b16be861184af7d58efd9353e8 Mon Sep 17 00:00:00 2001 From: ghostloda <78798447@qq.com> Date: Wed, 29 May 2024 10:19:17 +0800 Subject: [PATCH 2/2] add the old version "master" labels --- pkg/checker/cluster_checker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/checker/cluster_checker.go b/pkg/checker/cluster_checker.go index 425d5e30860..401183c521a 100644 --- a/pkg/checker/cluster_checker.go +++ b/pkg/checker/cluster_checker.go @@ -103,6 +103,9 @@ func isControlPlaneNode(node corev1.Node) bool { if _, ok := node.Labels["node-role.kubernetes.io/control-plane"]; ok { return true } + if _, ok := node.Labels["node-role.kubernetes.io/master"]; ok { + return true + } return false }