diff --git a/pkg/cli/etcdsnapshot/etcd_snapshot.go b/pkg/cli/etcdsnapshot/etcd_snapshot.go index 97e8c696fa..0c152bef59 100644 --- a/pkg/cli/etcdsnapshot/etcd_snapshot.go +++ b/pkg/cli/etcdsnapshot/etcd_snapshot.go @@ -86,7 +86,7 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, config *server.Config) (*e return nil, fmt.Errorf("etcd database not found in %s", config.ControlConfig.DataDir) } - sc, err := server.NewContext(ctx, config.ControlConfig.Runtime.KubeConfigAdmin, false) + sc, err := server.NewContext(ctx, config, false) if err != nil { return nil, err } diff --git a/pkg/server/context.go b/pkg/server/context.go index 49666e31be..93bee0c6ea 100644 --- a/pkg/server/context.go +++ b/pkg/server/context.go @@ -38,7 +38,11 @@ func (c *Context) Start(ctx context.Context) error { return start.All(ctx, 5, c.K3s, c.Helm, c.Apps, c.Auth, c.Batch, c.Core) } -func NewContext(ctx context.Context, cfg string, forServer bool) (*Context, error) { +func NewContext(ctx context.Context, config *Config, forServer bool) (*Context, error) { + cfg := config.ControlConfig.Runtime.KubeConfigAdmin + if forServer { + cfg = config.ControlConfig.Runtime.KubeConfigSupervisor + } restConfig, err := clientcmd.BuildConfigFromFlags("", cfg) if err != nil { return nil, err @@ -53,7 +57,7 @@ func NewContext(ctx context.Context, cfg string, forServer bool) (*Context, erro var recorder record.EventRecorder if forServer { recorder = util.BuildControllerEventRecorder(k8s, version.Program+"-supervisor", metav1.NamespaceAll) - if err := crds(ctx, restConfig); err != nil { + if err := registerCrds(ctx, config, restConfig); err != nil { return nil, errors.Wrap(err, "failed to register CRDs") } } @@ -70,14 +74,21 @@ func NewContext(ctx context.Context, cfg string, forServer bool) (*Context, erro }, nil } -func crds(ctx context.Context, config *rest.Config) error { - factory, err := crd.NewFactoryFromClient(config) +func registerCrds(ctx context.Context, config *Config, restConfig *rest.Config) error { + factory, err := crd.NewFactoryFromClient(restConfig) if err != nil { return err } - types := append(helmcrd.List(), addoncrd.List()...) - factory.BatchCreateCRDs(ctx, types...) + factory.BatchCreateCRDs(ctx, crds(config)...) return factory.BatchWait() } + +func crds(config *Config) []crd.CRD { + defaultCrds := addoncrd.List() + if !config.ControlConfig.DisableHelmController { + defaultCrds = append(defaultCrds, helmcrd.List()...) + } + return defaultCrds +} diff --git a/pkg/server/server.go b/pkg/server/server.go index 7ddc7c23fa..860f40ecb3 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -97,7 +97,7 @@ func startOnAPIServerReady(ctx context.Context, config *Config) { func runControllers(ctx context.Context, config *Config) error { controlConfig := &config.ControlConfig - sc, err := NewContext(ctx, controlConfig.Runtime.KubeConfigSupervisor, true) + sc, err := NewContext(ctx, config, true) if err != nil { return errors.Wrap(err, "failed to create new server context") }