From 3da5985916ec208250480a6b93d64234296b8437 Mon Sep 17 00:00:00 2001 From: Angus Lees Date: Tue, 21 Nov 2017 16:43:36 +1100 Subject: [PATCH] Only check Readiness of masters, not every node --- cmd/kubeadm/app/phases/upgrade/BUILD | 1 + cmd/kubeadm/app/phases/upgrade/health.go | 30 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/kubeadm/app/phases/upgrade/BUILD b/cmd/kubeadm/app/phases/upgrade/BUILD index d6fb5dc1659..907707d127e 100644 --- a/cmd/kubeadm/app/phases/upgrade/BUILD +++ b/cmd/kubeadm/app/phases/upgrade/BUILD @@ -43,6 +43,7 @@ go_library( "//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", diff --git a/cmd/kubeadm/app/phases/upgrade/health.go b/cmd/kubeadm/app/phases/upgrade/health.go index 5e81cc5964b..2ce9314fac9 100644 --- a/cmd/kubeadm/app/phases/upgrade/health.go +++ b/cmd/kubeadm/app/phases/upgrade/health.go @@ -24,6 +24,7 @@ import ( apps "k8s.io/api/apps/v1beta2" "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/sets" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/cmd/kubeadm/app/constants" @@ -53,7 +54,7 @@ func (c *healthCheck) Name() string { // CheckClusterHealth makes sure: // - the API /healthz endpoint is healthy -// - all Nodes are Ready +// - all master Nodes are Ready // - (if self-hosted) that there are DaemonSets with at least one Pod for all control plane components // - (if static pod-hosted) that all required Static Pod manifests exist on disk func CheckClusterHealth(client clientset.Interface, ignoreChecksErrors sets.String) error { @@ -66,9 +67,9 @@ func CheckClusterHealth(client clientset.Interface, ignoreChecksErrors sets.Stri f: apiServerHealthy, }, &healthCheck{ - name: "NodeHealth", + name: "MasterNodesReady", client: client, - f: nodesHealthy, + f: masterNodesReady, }, // TODO: Add a check for ComponentStatuses here? } @@ -106,16 +107,25 @@ func apiServerHealthy(client clientset.Interface) error { return nil } -// nodesHealthy checks whether all Nodes in the cluster are in the Running state -func nodesHealthy(client clientset.Interface) error { - nodes, err := client.CoreV1().Nodes().List(metav1.ListOptions{}) +// masterNodesReady checks whether all master Nodes in the cluster are in the Running state +func masterNodesReady(client clientset.Interface) error { + selector := labels.SelectorFromSet(labels.Set(map[string]string{ + constants.LabelNodeRoleMaster: "", + })) + masters, err := client.CoreV1().Nodes().List(metav1.ListOptions{ + LabelSelector: selector.String(), + }) if err != nil { - return fmt.Errorf("couldn't list all nodes in cluster: %v", err) + return fmt.Errorf("couldn't list masters in cluster: %v", err) } - notReadyNodes := getNotReadyNodes(nodes.Items) - if len(notReadyNodes) != 0 { - return fmt.Errorf("there are NotReady Nodes in the cluster: %v", notReadyNodes) + if len(masters.Items) == 0 { + return fmt.Errorf("failed to find any nodes with master role") + } + + notReadyMasters := getNotReadyNodes(masters.Items) + if len(notReadyMasters) != 0 { + return fmt.Errorf("there are NotReady masters in the cluster: %v", notReadyMasters) } return nil }