Merge pull request #894 from galal-hussein/fix_master_label_ha

Fix Master label in HA setups
This commit is contained in:
Erik Wilson 2019-10-16 16:31:12 -07:00 committed by GitHub
commit 0ee586c233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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