1
0
mirror of https://github.com/rancher/rke.git synced 2025-09-04 08:24:28 +00:00

Check if etcd is healthy before running kubeapi

This commit is contained in:
galal-hussein
2019-01-25 21:26:29 +02:00
committed by Alena Prokharchyk
parent c0ee3327ba
commit 860058e878
2 changed files with 17 additions and 3 deletions

View File

@@ -92,7 +92,7 @@ func (c *Cluster) DeployControlPlane(ctx context.Context) error {
if len(c.Services.Etcd.ExternalURLs) > 0 { if len(c.Services.Etcd.ExternalURLs) > 0 {
log.Infof(ctx, "[etcd] External etcd connection string has been specified, skipping etcd plane") log.Infof(ctx, "[etcd] External etcd connection string has been specified, skipping etcd plane")
} else { } else {
if err := services.RunEtcdPlane(ctx, c.EtcdHosts, etcdNodePlanMap, c.LocalConnDialerFactory, c.PrivateRegistriesMap, c.UpdateWorkersOnly, c.SystemImages.Alpine, c.Services.Etcd); err != nil { if err := services.RunEtcdPlane(ctx, c.EtcdHosts, etcdNodePlanMap, c.LocalConnDialerFactory, c.PrivateRegistriesMap, c.UpdateWorkersOnly, c.SystemImages.Alpine, c.Services.Etcd, c.Certificates); err != nil {
return fmt.Errorf("[etcd] Failed to bring up Etcd Plane: %v", err) return fmt.Errorf("[etcd] Failed to bring up Etcd Plane: %v", err)
} }
} }

View File

@@ -19,6 +19,7 @@ import (
"github.com/rancher/types/apis/management.cattle.io/v3" "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"k8s.io/client-go/util/cert"
) )
const ( const (
@@ -37,7 +38,8 @@ func RunEtcdPlane(
prsMap map[string]v3.PrivateRegistry, prsMap map[string]v3.PrivateRegistry,
updateWorkersOnly bool, updateWorkersOnly bool,
alpineImage string, alpineImage string,
es v3.ETCDService) error { es v3.ETCDService,
certMap map[string]pki.CertificatePKI) error {
log.Infof(ctx, "[%s] Building up etcd plane..", ETCDRole) log.Infof(ctx, "[%s] Building up etcd plane..", ETCDRole)
for _, host := range etcdHosts { for _, host := range etcdHosts {
if updateWorkersOnly { if updateWorkersOnly {
@@ -64,7 +66,19 @@ func RunEtcdPlane(
return err return err
} }
} }
log.Infof(ctx, "[%s] Successfully started etcd plane..", ETCDRole) log.Infof(ctx, "[%s] Successfully started etcd plane.. Checking etcd cluster health", ETCDRole)
clientCert := cert.EncodeCertPEM(certMap[pki.KubeNodeCertName].Certificate)
clientkey := cert.EncodePrivateKeyPEM(certMap[pki.KubeNodeCertName].Key)
var healthy bool
for _, host := range etcdHosts {
_, _, healthCheckURL := GetProcessConfig(etcdNodePlanMap[host.Address].Processes[EtcdContainerName])
if healthy = isEtcdHealthy(ctx, localConnDialerFactory, host, clientCert, clientkey, healthCheckURL); healthy {
break
}
}
if !healthy {
return fmt.Errorf("[etcd] Etcd Cluster is not healthy")
}
return nil return nil
} }