Disable cloud-node and cloud-node-lifecycle if CCM is disabled

If CCM and ServiceLB are both disabled, don't run the cloud-controller-manager at all;
this should provide the same CLI flag behavior as previous releases, and not create
problems when users disable the CCM but still want ServiceLB.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/6250/head
Brad Davidson 2022-09-29 20:50:05 +00:00 committed by Brad Davidson
parent 76f13d3558
commit 69dd30433b
4 changed files with 19 additions and 3 deletions

View File

@ -367,7 +367,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
serverConfig.ControlConfig.DisableServiceLB = true
}
if serverConfig.ControlConfig.DisableCCM {
if serverConfig.ControlConfig.DisableCCM && serverConfig.ControlConfig.DisableServiceLB {
serverConfig.ControlConfig.Skips["ccm"] = true
serverConfig.ControlConfig.Disables["ccm"] = true
}

View File

@ -2,6 +2,7 @@ package cloudprovider
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
@ -28,6 +29,7 @@ type Config struct {
LBEnabled bool `json:"lbEnabled"`
LBImage string `json:"lbImage"`
LBNamespace string `json:"lbNamespace"`
NodeEnabled bool `json:"nodeEnabled"`
Rootless bool `json:"rootless"`
}
@ -54,6 +56,7 @@ func init() {
LBEnabled: true,
LBImage: DefaultLBImage,
LBNamespace: DefaultLBNS,
NodeEnabled: true,
},
}
@ -65,6 +68,10 @@ func init() {
}
}
if !k.LBEnabled && !k.NodeEnabled {
return nil, fmt.Errorf("all cloud-provider functionality disabled by config")
}
return &k, err
})
}
@ -113,7 +120,7 @@ func (k *k3s) Instances() (cloudprovider.Instances, bool) {
}
func (k *k3s) InstancesV2() (cloudprovider.InstancesV2, bool) {
return k, true
return k, k.NodeEnabled
}
func (k *k3s) LoadBalancer() (cloudprovider.LoadBalancer, bool) {

View File

@ -777,6 +777,7 @@ func genCloudConfig(controlConfig *config.Control) error {
LBNamespace: controlConfig.ServiceLBNamespace,
LBImage: cloudprovider.DefaultLBImage,
Rootless: controlConfig.Rootless,
NodeEnabled: !controlConfig.DisableCCM,
}
if controlConfig.SystemDefaultRegistry != "" {
cloudConfig.LBImage = controlConfig.SystemDefaultRegistry + "/" + cloudConfig.LBImage

View File

@ -81,7 +81,7 @@ func Server(ctx context.Context, cfg *config.Control) error {
}
}
if !cfg.DisableCCM {
if !cfg.DisableCCM || !cfg.DisableServiceLB {
if err := cloudControllerManager(ctx, cfg); err != nil {
return err
}
@ -301,10 +301,12 @@ func cloudControllerManager(ctx context.Context, cfg *config.Control) error {
argsMap := map[string]string{
"profiling": "false",
"allocate-node-cidrs": "true",
"leader-elect-resource-name": version.Program + "-cloud-controller-manager",
"cloud-provider": version.Program,
"cloud-config": runtime.CloudControllerConfig,
"cluster-cidr": util.JoinIPNets(cfg.ClusterIPRanges),
"configure-cloud-routes": "false",
"controllers": "*,-route",
"kubeconfig": runtime.KubeConfigCloudController,
"authorization-kubeconfig": runtime.KubeConfigCloudController,
"authentication-kubeconfig": runtime.KubeConfigCloudController,
@ -314,6 +316,12 @@ func cloudControllerManager(ctx context.Context, cfg *config.Control) error {
if cfg.NoLeaderElect {
argsMap["leader-elect"] = "false"
}
if cfg.DisableCCM {
argsMap["controllers"] = argsMap["controllers"] + ",-cloud-node,-cloud-node-lifecycle"
}
if cfg.DisableServiceLB {
argsMap["controllers"] = argsMap["controllers"] + ",-service"
}
args := config.GetArgs(argsMap, cfg.ExtraCloudControllerArgs)
logrus.Infof("Running cloud-controller-manager %s", config.ArgString(args))