mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
use healthz api instead of componentstatus in WaitForAPI
This commit is contained in:
parent
dee81ed56a
commit
7f613f09b8
@ -26,7 +26,6 @@ go_library(
|
|||||||
"//pkg/kubectl/cmd/util:go_default_library",
|
"//pkg/kubectl/cmd/util:go_default_library",
|
||||||
"//pkg/util/version:go_default_library",
|
"//pkg/util/version:go_default_library",
|
||||||
"//vendor/github.com/ghodss/yaml:go_default_library",
|
"//vendor/github.com/ghodss/yaml:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
|
||||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
||||||
|
@ -18,13 +18,11 @@ package master
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/pkg/api/v1"
|
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
)
|
)
|
||||||
@ -44,28 +42,12 @@ func CreateClientAndWaitForAPI(file string) (*clientset.Clientset, error) {
|
|||||||
func WaitForAPI(client *clientset.Clientset) {
|
func WaitForAPI(client *clientset.Clientset) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
wait.PollInfinite(kubeadmconstants.APICallRetryInterval, func() (bool, error) {
|
wait.PollInfinite(kubeadmconstants.APICallRetryInterval, func() (bool, error) {
|
||||||
// TODO: use /healthz API instead of this
|
healthStatus := 0
|
||||||
cs, err := client.ComponentStatuses().List(metav1.ListOptions{})
|
client.Discovery().RESTClient().Get().AbsPath("/healthz").Do().StatusCode(&healthStatus)
|
||||||
if err != nil {
|
if healthStatus != http.StatusOK {
|
||||||
if apierrs.IsForbidden(err) {
|
|
||||||
fmt.Println("[apiclient] Waiting for API server authorization")
|
|
||||||
}
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(phase2) must revisit this when we implement HA
|
|
||||||
if len(cs.Items) < 3 {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
for _, item := range cs.Items {
|
|
||||||
for _, condition := range item.Conditions {
|
|
||||||
if condition.Type != v1.ComponentHealthy {
|
|
||||||
fmt.Printf("[apiclient] Control plane component %q is still unhealthy: %#v\n", item.ObjectMeta.Name, item.Conditions)
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("[apiclient] All control plane components are healthy after %f seconds\n", time.Since(start).Seconds())
|
fmt.Printf("[apiclient] All control plane components are healthy after %f seconds\n", time.Since(start).Seconds())
|
||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user