mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Wait for apiserver to be health, not just running
This commit is contained in:
parent
b3336f69cf
commit
29b270dce6
@ -31,9 +31,10 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apiserver/pkg/authentication/authenticator"
|
"k8s.io/apiserver/pkg/authentication/authenticator"
|
||||||
"k8s.io/client-go/discovery"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
ccmapp "k8s.io/kubernetes/cmd/cloud-controller-manager/app"
|
ccmapp "k8s.io/kubernetes/cmd/cloud-controller-manager/app"
|
||||||
|
app2 "k8s.io/kubernetes/cmd/controller-manager/app"
|
||||||
"k8s.io/kubernetes/cmd/kube-apiserver/app"
|
"k8s.io/kubernetes/cmd/kube-apiserver/app"
|
||||||
cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
|
cmapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
|
||||||
sapp "k8s.io/kubernetes/cmd/kube-scheduler/app"
|
sapp "k8s.io/kubernetes/cmd/kube-scheduler/app"
|
||||||
@ -858,25 +859,24 @@ func waitForAPIServer(ctx context.Context, runtime *config.ControlRuntime) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
discoveryclient, err := discovery.NewDiscoveryClientForConfig(restConfig)
|
k8sClient, err := kubernetes.NewForConfig(restConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 60; i++ {
|
select {
|
||||||
info, err := discoveryclient.ServerVersion()
|
case <-ctx.Done():
|
||||||
if err == nil {
|
return ctx.Err()
|
||||||
logrus.Infof("apiserver %s is up and running", info)
|
case err := <-promise(func() error { return app2.WaitForAPIServer(k8sClient, 5*time.Minute) }):
|
||||||
return nil
|
return err
|
||||||
}
|
|
||||||
logrus.Infof("waiting for apiserver to become available")
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return fmt.Errorf("timeout waiting for apiserver")
|
|
||||||
|
func promise(f func() error) <-chan error {
|
||||||
|
c := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
c <- f()
|
||||||
|
close(c)
|
||||||
|
}()
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user