Unverified Commit 8a81349b authored by Luther Monson's avatar Luther Monson Committed by GitHub

Adding support for waitgroup to the Startuphooks (#3654) (#3658)

The startup hooks where executing after the deploy controller. We needed the deploy controller to wait until the startup hooks had completed. Signed-off-by: 's avatarLuther Monson <luther.monson@gmail.com> Co-authored-by: 's avatarJamie Phillips <jamie.phillips@suse.com>
parent 89c44337
...@@ -2,6 +2,7 @@ package cmds ...@@ -2,6 +2,7 @@ package cmds
import ( import (
"context" "context"
"sync"
"github.com/rancher/k3s/pkg/version" "github.com/rancher/k3s/pkg/version"
"github.com/urfave/cli" "github.com/urfave/cli"
...@@ -62,7 +63,8 @@ type Server struct { ...@@ -62,7 +63,8 @@ type Server struct {
ClusterReset bool ClusterReset bool
ClusterResetRestorePath string ClusterResetRestorePath string
EncryptSecrets bool EncryptSecrets bool
StartupHooks []func(context.Context, <-chan struct{}, string) error SystemDefaultRegistry string
StartupHooks []func(context.Context, *sync.WaitGroup, <-chan struct{}, string) error
EtcdSnapshotName string EtcdSnapshotName string
EtcdDisableSnapshots bool EtcdDisableSnapshots bool
EtcdSnapshotDir string EtcdSnapshotDir string
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
...@@ -68,8 +69,10 @@ func StartServer(ctx context.Context, config *Config) error { ...@@ -68,8 +69,10 @@ func StartServer(ctx context.Context, config *Config) error {
return errors.Wrap(err, "starting tls server") return errors.Wrap(err, "starting tls server")
} }
config.StartupHooksWg = &sync.WaitGroup{}
config.StartupHooksWg.Add(len(config.StartupHooks))
for _, hook := range config.StartupHooks { for _, hook := range config.StartupHooks {
if err := hook(ctx, config.ControlConfig.Runtime.APIServerReady, config.ControlConfig.Runtime.KubeConfigAdmin); err != nil { if err := hook(ctx, config.StartupHooksWg, config.ControlConfig.Runtime.APIServerReady, config.ControlConfig.Runtime.KubeConfigAdmin); err != nil {
return errors.Wrap(err, "startup hook") return errors.Wrap(err, "startup hook")
} }
} }
...@@ -127,6 +130,7 @@ func runControllers(ctx context.Context, config *Config) error { ...@@ -127,6 +130,7 @@ func runControllers(ctx context.Context, config *Config) error {
return err return err
} }
config.StartupHooksWg.Wait()
if err := stageFiles(ctx, sc, controlConfig); err != nil { if err := stageFiles(ctx, sc, controlConfig); err != nil {
return err return err
} }
......
...@@ -2,6 +2,7 @@ package server ...@@ -2,6 +2,7 @@ package server
import ( import (
"context" "context"
"sync"
"github.com/rancher/k3s/pkg/daemons/config" "github.com/rancher/k3s/pkg/daemons/config"
) )
...@@ -12,7 +13,8 @@ type Config struct { ...@@ -12,7 +13,8 @@ type Config struct {
ControlConfig config.Control ControlConfig config.Control
Rootless bool Rootless bool
SupervisorPort int SupervisorPort int
StartupHooks []func(context.Context, <-chan struct{}, string) error StartupHooks []func(context.Context, *sync.WaitGroup, <-chan struct{}, string) error
StartupHooksWg *sync.WaitGroup
LeaderControllers CustomControllers LeaderControllers CustomControllers
Controllers CustomControllers Controllers CustomControllers
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment