Skip to content

Commit

Permalink
Expose flag to explicitly disable cloud-provider=external kubelet arg…
Browse files Browse the repository at this point in the history
…ument (#60)

* Expose flag to explicitly set cloud-provider=external kubelet argument
  • Loading branch information
anmazzotti authored Oct 12, 2023
1 parent ab40c40 commit 4a936a9
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 11 deletions.
4 changes: 4 additions & 0 deletions bootstrap/api/v1beta1/kthreesconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ type KThreesServerConfig struct {
// DisableComponents specifies extra commands to run before k3s setup runs
// +optional
DisableComponents []string `json:"disableComponents,omitempty"`

// DisableExternalCloudProvider suppresses the 'cloud-provider=external' kubelet argument. (default: false)
// +optional
DisableExternalCloudProvider bool `json:"disableExternalCloudProvider,omitempty"`
}

type KThreesAgentConfig struct {
Expand Down
5 changes: 5 additions & 0 deletions bootstrap/api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ spec:
items:
type: string
type: array
disableExternalCloudProvider:
description: 'DisableExternalCloudProvider suppresses the ''cloud-provider=external''
kubelet argument. (default: false)'
type: boolean
httpsListenPort:
description: 'HTTPSListenPort HTTPS listen port (default: 6443)'
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ spec:
items:
type: string
type: array
disableExternalCloudProvider:
description: 'DisableExternalCloudProvider suppresses
the ''cloud-provider=external'' kubelet argument. (default:
false)'
type: boolean
httpsListenPort:
description: 'HTTPSListenPort HTTPS listen port (default:
6443)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ spec:
items:
type: string
type: array
disableExternalCloudProvider:
description: 'DisableExternalCloudProvider suppresses the
''cloud-provider=external'' kubelet argument. (default:
false)'
type: boolean
httpsListenPort:
description: 'HTTPSListenPort HTTPS listen port (default:
6443)'
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: ghcr.io/cluster-api-provider-k3s/cluster-api-k3s/bootstrap-controller
newTag: v0.2.0
newTag: v0.1.7
2 changes: 1 addition & 1 deletion bootstrap/controllers/kthreesconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (r *KThreesConfigReconciler) joinWorker(ctx context.Context, scope *Scope)
return err
}

configStruct := k3s.GenerateWorkerConfig(serverURL, tokn, scope.Config.Spec.AgentConfig)
configStruct := k3s.GenerateWorkerConfig(serverURL, tokn, scope.Config.Spec.ServerConfig, scope.Config.Spec.AgentConfig)

b, err := kubeyaml.Marshal(configStruct)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ spec:
items:
type: string
type: array
disableExternalCloudProvider:
description: 'DisableExternalCloudProvider suppresses the ''cloud-provider=external''
kubelet argument. (default: false)'
type: boolean
httpsListenPort:
description: 'HTTPSListenPort HTTPS listen port (default: 6443)'
type: string
Expand All @@ -181,6 +185,12 @@ spec:
items:
type: string
type: array
kubeSchedulerArgs:
description: KubeSchedulerArgs is a customized flag for kube-scheduler
process
items:
type: string
type: array
serviceCidr:
description: 'ServiceCidr Network CIDR to use for services IPs
(default: "10.43.0.0/16")'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ spec:
items:
type: string
type: array
disableExternalCloudProvider:
description: 'DisableExternalCloudProvider suppresses
the ''cloud-provider=external'' kubelet argument. (default:
false)'
type: boolean
httpsListenPort:
description: 'HTTPSListenPort HTTPS listen port (default:
6443)'
Expand All @@ -196,6 +201,12 @@ spec:
items:
type: string
type: array
kubeSchedulerArgs:
description: KubeSchedulerArgs is a customized flag for
kube-scheduler process
items:
type: string
type: array
serviceCidr:
description: 'ServiceCidr Network CIDR to use for services
IPs (default: "10.43.0.0/16")'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ spec:
items:
type: string
type: array
disableExternalCloudProvider:
description: 'DisableExternalCloudProvider suppresses the
''cloud-provider=external'' kubelet argument. (default:
false)'
type: boolean
httpsListenPort:
description: 'HTTPSListenPort HTTPS listen port (default:
6443)'
Expand All @@ -262,6 +267,12 @@ spec:
items:
type: string
type: array
kubeSchedulerArgs:
description: KubeSchedulerArgs is a customized flag for kube-scheduler
process
items:
type: string
type: array
serviceCidr:
description: 'ServiceCidr Network CIDR to use for services
IPs (default: "10.43.0.0/16")'
Expand Down
2 changes: 1 addition & 1 deletion controlplane/config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: ghcr.io/cluster-api-provider-k3s/cluster-api-k3s/controlplane-controller
newTag: v0.2.0
newTag: v0.1.7
27 changes: 19 additions & 8 deletions pkg/k3s/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ type K3sAgentConfig struct {
}

func GenerateInitControlPlaneConfig(controlPlaneEndpoint string, token string, serverConfig bootstrapv1.KThreesServerConfig, agentConfig bootstrapv1.KThreesAgentConfig) K3sServerConfig {
kubeletExtraArgs := getKubeletExtraArgs(serverConfig)
k3sServerConfig := K3sServerConfig{
DisableCloudController: true,
DisableCloudController: !serverConfig.DisableExternalCloudProvider,
ClusterInit: true,
KubeAPIServerArgs: append(serverConfig.KubeAPIServerArgs, "anonymous-auth=true", getTLSCipherSuiteArg()),
TLSSan: append(serverConfig.TLSSan, controlPlaneEndpoint),
KubeControllerManagerArgs: append(serverConfig.KubeControllerManagerArgs, "cloud-provider=external"),
KubeControllerManagerArgs: append(serverConfig.KubeControllerManagerArgs, kubeletExtraArgs...),
KubeSchedulerArgs: serverConfig.KubeSchedulerArgs,
BindAddress: serverConfig.BindAddress,
HTTPSListenPort: serverConfig.HTTPSListenPort,
Expand All @@ -60,7 +61,7 @@ func GenerateInitControlPlaneConfig(controlPlaneEndpoint string, token string, s

k3sServerConfig.K3sAgentConfig = K3sAgentConfig{
Token: token,
KubeletArgs: append(agentConfig.KubeletArgs, "cloud-provider=external"),
KubeletArgs: append(agentConfig.KubeletArgs, kubeletExtraArgs...),
NodeLabels: agentConfig.NodeLabels,
NodeTaints: agentConfig.NodeTaints,
PrivateRegistry: agentConfig.PrivateRegistry,
Expand All @@ -72,11 +73,12 @@ func GenerateInitControlPlaneConfig(controlPlaneEndpoint string, token string, s
}

func GenerateJoinControlPlaneConfig(serverURL string, token string, controlplaneendpoint string, serverConfig bootstrapv1.KThreesServerConfig, agentConfig bootstrapv1.KThreesAgentConfig) K3sServerConfig {
kubeletExtraArgs := getKubeletExtraArgs(serverConfig)
k3sServerConfig := K3sServerConfig{
DisableCloudController: true,
DisableCloudController: !serverConfig.DisableExternalCloudProvider,
KubeAPIServerArgs: append(serverConfig.KubeAPIServerArgs, "anonymous-auth=true", getTLSCipherSuiteArg()),
TLSSan: append(serverConfig.TLSSan, controlplaneendpoint),
KubeControllerManagerArgs: append(serverConfig.KubeControllerManagerArgs, "cloud-provider=external"),
KubeControllerManagerArgs: append(serverConfig.KubeControllerManagerArgs, kubeletExtraArgs...),
KubeSchedulerArgs: serverConfig.KubeSchedulerArgs,
BindAddress: serverConfig.BindAddress,
HTTPSListenPort: serverConfig.HTTPSListenPort,
Expand All @@ -92,7 +94,7 @@ func GenerateJoinControlPlaneConfig(serverURL string, token string, controlplane
k3sServerConfig.K3sAgentConfig = K3sAgentConfig{
Token: token,
Server: serverURL,
KubeletArgs: append(agentConfig.KubeletArgs, "cloud-provider=external"),
KubeletArgs: append(agentConfig.KubeletArgs, kubeletExtraArgs...),
NodeLabels: agentConfig.NodeLabels,
NodeTaints: agentConfig.NodeTaints,
PrivateRegistry: agentConfig.PrivateRegistry,
Expand All @@ -103,11 +105,12 @@ func GenerateJoinControlPlaneConfig(serverURL string, token string, controlplane
return k3sServerConfig
}

func GenerateWorkerConfig(serverURL string, token string, agentConfig bootstrapv1.KThreesAgentConfig) K3sAgentConfig {
func GenerateWorkerConfig(serverURL string, token string, serverConfig bootstrapv1.KThreesServerConfig, agentConfig bootstrapv1.KThreesAgentConfig) K3sAgentConfig {
kubeletExtraArgs := getKubeletExtraArgs(serverConfig)
return K3sAgentConfig{
Server: serverURL,
Token: token,
KubeletArgs: append(agentConfig.KubeletArgs, "cloud-provider=external"),
KubeletArgs: append(agentConfig.KubeletArgs, kubeletExtraArgs...),
NodeLabels: agentConfig.NodeLabels,
NodeTaints: agentConfig.NodeTaints,
PrivateRegistry: agentConfig.PrivateRegistry,
Expand Down Expand Up @@ -152,3 +155,11 @@ func getTLSCipherSuiteArg() string {

return fmt.Sprintf("tls-cipher-suites=%s", ciphersList)
}

func getKubeletExtraArgs(serverConfig bootstrapv1.KThreesServerConfig) []string {
kubeletExtraArgs := []string{}
if !serverConfig.DisableExternalCloudProvider {
kubeletExtraArgs = append(kubeletExtraArgs, "cloud-provider=external")
}
return kubeletExtraArgs
}

0 comments on commit 4a936a9

Please sign in to comment.