mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Disable helm CRD installation for disable-helm-controller (#8702)
* Disable helm CRD installation for disable-helm-controller The NewContext package requires config as input which would require all third-party callers to update when the new go module is published. This change only affects the behaviour of installation of helm CRDs. Existing helm crds installed in a cluster would not be removed when disable-helm-controller flag is set on the server. Addresses #8701 * address review comments * remove redundant check Signed-off-by: Harsimran Singh Maan <maan.harry@gmail.com>
This commit is contained in:
parent
07ee854914
commit
abc2efdd57
@ -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)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -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)
|
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)
|
restConfig, err := clientcmd.BuildConfigFromFlags("", cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -53,7 +57,7 @@ func NewContext(ctx context.Context, cfg string, forServer bool) (*Context, erro
|
|||||||
var recorder record.EventRecorder
|
var recorder record.EventRecorder
|
||||||
if forServer {
|
if forServer {
|
||||||
recorder = util.BuildControllerEventRecorder(k8s, version.Program+"-supervisor", metav1.NamespaceAll)
|
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")
|
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
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func crds(ctx context.Context, config *rest.Config) error {
|
func registerCrds(ctx context.Context, config *Config, restConfig *rest.Config) error {
|
||||||
factory, err := crd.NewFactoryFromClient(config)
|
factory, err := crd.NewFactoryFromClient(restConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
types := append(helmcrd.List(), addoncrd.List()...)
|
factory.BatchCreateCRDs(ctx, crds(config)...)
|
||||||
factory.BatchCreateCRDs(ctx, types...)
|
|
||||||
|
|
||||||
return factory.BatchWait()
|
return factory.BatchWait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func crds(config *Config) []crd.CRD {
|
||||||
|
defaultCrds := addoncrd.List()
|
||||||
|
if !config.ControlConfig.DisableHelmController {
|
||||||
|
defaultCrds = append(defaultCrds, helmcrd.List()...)
|
||||||
|
}
|
||||||
|
return defaultCrds
|
||||||
|
}
|
||||||
|
@ -97,7 +97,7 @@ func startOnAPIServerReady(ctx context.Context, config *Config) {
|
|||||||
func runControllers(ctx context.Context, config *Config) error {
|
func runControllers(ctx context.Context, config *Config) error {
|
||||||
controlConfig := &config.ControlConfig
|
controlConfig := &config.ControlConfig
|
||||||
|
|
||||||
sc, err := NewContext(ctx, controlConfig.Runtime.KubeConfigSupervisor, true)
|
sc, err := NewContext(ctx, config, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create new server context")
|
return errors.Wrap(err, "failed to create new server context")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user