diff --git a/pkg/cli/cmds/server.go b/pkg/cli/cmds/server.go index 08df36e678..b6a0913573 100644 --- a/pkg/cli/cmds/server.go +++ b/pkg/cli/cmds/server.go @@ -13,6 +13,16 @@ const ( defaultSnapshotIntervalHours = 12 ) +type StartupHookArgs struct { + Wg *sync.WaitGroup + APIServerReady <-chan struct{} + KubeConfigAdmin string + Skips map[string]bool + Disables map[string]bool +} + +type StartupHook func(context.Context, StartupHookArgs) error + type Server struct { ClusterCIDR cli.StringSlice AgentToken string @@ -64,7 +74,7 @@ type Server struct { ClusterResetRestorePath string EncryptSecrets bool SystemDefaultRegistry string - StartupHooks []func(context.Context, *sync.WaitGroup, <-chan struct{}, string) error + StartupHooks []StartupHook EtcdSnapshotName string EtcdDisableSnapshots bool EtcdExposeMetrics bool diff --git a/pkg/server/server.go b/pkg/server/server.go index 9dcb04f737..ccfd4fd904 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -13,11 +13,10 @@ import ( "sync" "time" - corev1 "k8s.io/api/core/v1" - "github.com/k3s-io/helm-controller/pkg/helm" "github.com/pkg/errors" "github.com/rancher/k3s/pkg/apiaddresses" + "github.com/rancher/k3s/pkg/cli/cmds" "github.com/rancher/k3s/pkg/clientaccess" "github.com/rancher/k3s/pkg/daemons/config" "github.com/rancher/k3s/pkg/daemons/control" @@ -34,6 +33,7 @@ import ( "github.com/rancher/wrangler/pkg/leader" "github.com/rancher/wrangler/pkg/resolvehome" "github.com/sirupsen/logrus" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/net" ) @@ -72,8 +72,15 @@ func StartServer(ctx context.Context, config *Config) error { config.StartupHooksWg = &sync.WaitGroup{} config.StartupHooksWg.Add(len(config.StartupHooks)) + shArgs := cmds.StartupHookArgs{ + Wg: config.StartupHooksWg, + APIServerReady: config.ControlConfig.Runtime.APIServerReady, + KubeConfigAdmin: config.ControlConfig.Runtime.KubeConfigAdmin, + Skips: config.ControlConfig.Skips, + Disables: config.ControlConfig.Disables, + } for _, hook := range config.StartupHooks { - if err := hook(ctx, config.StartupHooksWg, config.ControlConfig.Runtime.APIServerReady, config.ControlConfig.Runtime.KubeConfigAdmin); err != nil { + if err := hook(ctx, shArgs); err != nil { return errors.Wrap(err, "startup hook") } } diff --git a/pkg/server/types.go b/pkg/server/types.go index 998b1996ff..d26ea663a5 100644 --- a/pkg/server/types.go +++ b/pkg/server/types.go @@ -4,6 +4,7 @@ import ( "context" "sync" + "github.com/rancher/k3s/pkg/cli/cmds" "github.com/rancher/k3s/pkg/daemons/config" ) @@ -13,7 +14,7 @@ type Config struct { ControlConfig config.Control Rootless bool SupervisorPort int - StartupHooks []func(context.Context, *sync.WaitGroup, <-chan struct{}, string) error + StartupHooks []cmds.StartupHook StartupHooksWg *sync.WaitGroup LeaderControllers CustomControllers Controllers CustomControllers