Fix master role label in ha setups

This commit is contained in:
galal-hussein 2019-10-11 23:43:00 +02:00
parent c12d2a1aea
commit 7c60285435

View File

@ -109,7 +109,7 @@ func startWrangler(ctx context.Context, config *Config) (string, error) {
return "", err
}
if err := sc.Start(ctx); err != nil {
if err := startNodeCache(ctx, sc); err != nil {
return "", err
}
@ -122,7 +122,7 @@ func startWrangler(ctx context.Context, config *Config) (string, error) {
}
}
if !config.DisableAgent {
go setMasterRoleLabel(ctx, sc, config)
go setMasterRoleLabel(ctx, sc)
}
if controlConfig.NoLeaderElect {
go func() {
@ -364,11 +364,12 @@ func isSymlink(config string) bool {
return false
}
func setMasterRoleLabel(ctx context.Context, sc *Context, config *Config) error {
func setMasterRoleLabel(ctx context.Context, sc *Context) error {
for {
nodeName := os.Getenv("NODE_NAME")
nodeController := sc.Core.Core().V1().Node()
nodeCached, err := nodeController.Cache().Get(nodeName)
nodeCache := nodeController.Cache()
nodeCached, err := nodeCache.Get(nodeName)
if err != nil {
logrus.Infof("Waiting for master node %s startup: %v", nodeName, err)
time.Sleep(1 * time.Second)
@ -395,3 +396,9 @@ func setMasterRoleLabel(ctx context.Context, sc *Context, config *Config) error
}
return nil
}
func startNodeCache(ctx context.Context, sc *Context) error {
sc.Core.Core().V1().Node().Cache()
return sc.Start(ctx)
}