Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix control-plane component status #4749

Merged
merged 2 commits into from
May 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions pkg/checker/cluster_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issues with older versions need to be considered

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed,I'll add an old version label to check.

return true
}
return false
}

func (n *ClusterChecker) Output(clusterStatus []ClusterStatus) error {
tpl, isOk, err := template.TryParse(`
Cluster Status
Expand Down
Loading