Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding startup hooks args to access to Disables and Skips #3674

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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")
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"sync"

"github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/k3s/pkg/daemons/config"
)

Expand All @@ -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
Expand Down