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

Add extra arguments for each k8sd service #485

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
105 changes: 100 additions & 5 deletions docs/src/snap/reference/bootstrap-config-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Determines if the feature should be enabled.
If omitted defaults to `true`

#### cluster-config.dns.cluster-domain

**Type:** `string`<br>
**Required:** `No` <br>

Expand All @@ -59,7 +60,8 @@ Can be used to point to an external dns server when feature is disabled.
**Type:** `list[string]`<br>
**Required:** `No` <br>

Sets the upstream nameservers used to forward queries for out-of-cluster endpoints.
Sets the upstream nameservers used to forward queries for out-of-cluster
endpoints.
If omitted defaults to `/etc/resolv.conf` and uses the nameservers of the node.


Expand All @@ -83,7 +85,8 @@ If omitted defaults to `false`
**Type:** `string`<br>
**Required:** `No` <br>

Sets the name of the secret to be used for providing default encryption to ingresses.
Sets the name of the secret to be used for providing default encryption to
ingresses.

Ingresses can specify another TLS secret in their resource definitions,
in which case the default secret won't be used.
Expand Down Expand Up @@ -117,7 +120,8 @@ If omitted defaults to `false`
**Type:** `list[string]`<br>
**Required:** `No` <br>

Sets the CIDRs used for assigning IP addresses to Kubernetes services with type `LoadBalancer`.
Sets the CIDRs used for assigning IP addresses to Kubernetes services with type
`LoadBalancer`.

#### cluster-config.load-balancer.l2-mode

Expand Down Expand Up @@ -316,7 +320,8 @@ The CA certificate to be used when communicating with the external datastore.
**Type:** `string` <br>
**Required:** `No` <br>

The client certificate to be used when communicating with the external datastore.
The client certificate to be used when communicating with the external
datastore.

### datastore-client-key

Expand Down Expand Up @@ -386,7 +391,8 @@ If omitted defaults to an auto generated key.
**Type:** `string` <br>
**Required:** `No` <br>

The client certificate to be used by kubelet for communicating with the kube-apiserver.
The client certificate to be used by kubelet for communicating with the
kube-apiserver.
If omitted defaults to an auto generated certificate.

### apiserver-kubelet-client-key
Expand Down Expand Up @@ -437,6 +443,79 @@ If omitted defaults to an auto generated certificate.
The key to be used for the kubelet.
If omitted defaults to an auto generated key.

### extra-node-config-files:
bschimke95 marked this conversation as resolved.
Show resolved Hide resolved

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional files that are uploaded `/var/snap/k8s/common/args/conf.d/<filename>`
to a node on bootstrap. These files can them be references by Kubernetes
service arguments.
The format is `map[<filename>]<filecontent>`.

### extra-node-kube-apiserver-args:

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional arguments that are passed to the `kube-apiserver` only for that
specific node. Overwrites default configuration. A parameter that is explicitly
set to `null` is deleted. The format is `map[<--flag-name>]<value>`.

### extra-node-kube-controller-manager-args:

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional arguments that are passed to the `kube-controller-manager` only for
that specific node. Overwrites default configuration. A parameter that is
explicitly set to `null` is deleted. The format is `map[<--flag-name>]<value>`.

### extra-node-kube-scheduler-args:

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional arguments that are passed to the `kube-scheduler` only for that
specific node. Overwrites default configuration. A parameter that is explicitly
set to `null` is deleted. The format is `map[<--flag-name>]<value>`.

### extra-node-kube-proxy-args:

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional arguments that are passed to the `kube-proxy` only for that
specific node. Overwrites default configuration. A parameter that is explicitly
set to `null` is deleted. The format is `map[<--flag-name>]<value>`.

### extra-node-kubelet-args:

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional arguments that are passed to the `kubelet` only for that
specific node. Overwrites default configuration. A parameter that is explicitly
set to `null` is deleted. The format is `map[<--flag-name>]<value>`.

### extra-node-containerd-args:

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional arguments that are passed to `containerd` only for that
specific node. Overwrites default configuration. A parameter that is explicitly
set to `null` is deleted. The format is `map[<--flag-name>]<value>`.

### extra-node-k8s-dqlite-args:

**Type:** `map[string]string` <br>
**Required:** `No` <br>

Additional arguments that are passed to `k8s-dqlite` only for that
specific node. Overwrites default configuration. A parameter that is explicitly
set to `null` is deleted. The format is `map[<--flag-name>]<value>`.

## Example

The following example configures and enables certain features, sets an external
Expand Down Expand Up @@ -478,4 +557,20 @@ k8s-dqlite-port: 9090
datastore-type: k8s-dqlite
extra-sans:
- custom.kubernetes
extra-node-config-files:
bootstrap-extra-file.yaml: extra-args-test-file-content
extra-node-kube-apiserver-args:
--request-timeout: 2m
extra-node-kube-controller-manager-args:
--leader-elect-retry-period: 3s
extra-node-kube-scheduler-args:
--authorization-webhook-cache-authorized-ttl: 11s
extra-node-kube-proxy-args:
--config-sync-period: 14m
extra-node-kubelet-args:
--authentication-token-webhook-cache-ttl: 3m
extra-node-containerd-args:
--log-level: debug
extra-node-k8s-dqlite-args:
--watch-storage-available-size-interval: 6s
```
12 changes: 12 additions & 0 deletions src/k8s/api/v1/bootstrap_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ type BootstrapConfig struct {
KubeletKey *string `json:"kubelet-key,omitempty" yaml:"kubelet-key,omitempty"`
KubeletClientCert *string `json:"kubelet-client-crt,omitempty" yaml:"kubelet-client-crt,omitempty"`
KubeletClientKey *string `json:"kubelet-client-key,omitempty" yaml:"kubelet-client-key,omitempty"`

// ExtraNodeConfigFiles will be written to /var/snap/k8s/common/args/conf.d
ExtraNodeConfigFiles map[string]string `json:"extra-node-config-files,omitempty" yaml:"extra-node-config-files,omitempty"`

// Extra args to add to individual services (set any arg to null to delete)
ExtraNodeKubeAPIServerArgs map[string]*string `json:"extra-node-kube-apiserver-args,omitempty" yaml:"extra-node-kube-apiserver-args,omitempty"`
ExtraNodeKubeControllerManagerArgs map[string]*string `json:"extra-node-kube-controller-manager-args,omitempty" yaml:"extra-node-kube-controller-manager-args,omitempty"`
ExtraNodeKubeSchedulerArgs map[string]*string `json:"extra-node-kube-scheduler-args,omitempty" yaml:"extra-node-kube-scheduler-args,omitempty"`
ExtraNodeKubeProxyArgs map[string]*string `json:"extra-node-kube-proxy-args,omitempty" yaml:"extra-node-kube-proxy-args,omitempty"`
ExtraNodeKubeletArgs map[string]*string `json:"extra-node-kubelet-args,omitempty" yaml:"extra-node-kubelet-args,omitempty"`
ExtraNodeContainerdArgs map[string]*string `json:"extra-node-containerd-args,omitempty" yaml:"extra-node-containerd-args,omitempty"`
ExtraNodeK8sDqliteArgs map[string]*string `json:"extra-node-k8s-dqlite-args,omitempty" yaml:"extra-node-k8s-dqlite-args,omitempty"`
}

func (b *BootstrapConfig) GetDatastoreType() string { return getField(b.DatastoreType) }
Expand Down
22 changes: 15 additions & 7 deletions src/k8s/api/v1/bootstrap_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ func TestBootstrapConfigToMicrocluster(t *testing.T) {
},
CloudProvider: utils.Pointer("external"),
},
PodCIDR: utils.Pointer("10.100.0.0/16"),
ServiceCIDR: utils.Pointer("10.200.0.0/16"),
DisableRBAC: utils.Pointer(false),
SecurePort: utils.Pointer(6443),
K8sDqlitePort: utils.Pointer(9090),
DatastoreType: utils.Pointer("k8s-dqlite"),
ExtraSANs: []string{"custom.kubernetes"},
PodCIDR: utils.Pointer("10.100.0.0/16"),
ServiceCIDR: utils.Pointer("10.200.0.0/16"),
DisableRBAC: utils.Pointer(false),
SecurePort: utils.Pointer(6443),
K8sDqlitePort: utils.Pointer(9090),
DatastoreType: utils.Pointer("k8s-dqlite"),
ExtraSANs: []string{"custom.kubernetes"},
ExtraNodeConfigFiles: map[string]string{"extra-node-config-file": "file-content"},
ExtraNodeKubeAPIServerArgs: map[string]*string{"--extra-kube-apiserver-arg": utils.Pointer("extra-kube-apiserver-value")},
ExtraNodeKubeControllerManagerArgs: map[string]*string{"--extra-kube-controller-manager-arg": utils.Pointer("extra-kube-controller-manager-value")},
ExtraNodeKubeSchedulerArgs: map[string]*string{"--extra-kube-scheduler-arg": utils.Pointer("extra-kube-scheduler-value")},
ExtraNodeKubeProxyArgs: map[string]*string{"--extra-kube-proxy-arg": utils.Pointer("extra-kube-proxy-value")},
ExtraNodeKubeletArgs: map[string]*string{"--extra-kubelet-arg": utils.Pointer("extra-kubelet-value")},
ExtraNodeContainerdArgs: map[string]*string{"--extra-containerd-arg": utils.Pointer("extra-containerd-value")},
ExtraNodeK8sDqliteArgs: map[string]*string{"--extra-k8s-dqlite-arg": utils.Pointer("extra-k8s-dqlite-value")},
}

microclusterConfig, err := cfg.ToMicrocluster()
Expand Down
21 changes: 21 additions & 0 deletions src/k8s/api/v1/join_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ type ControlPlaneNodeJoinConfig struct {
KubeletKey *string `json:"kubelet-key,omitempty" yaml:"kubelet-key,omitempty"`
KubeletClientCert *string `json:"kubelet-client-crt,omitempty" yaml:"kubelet-client-crt,omitempty"`
KubeletClientKey *string `json:"kubelet-client-key,omitempty" yaml:"kubelet-client-key,omitempty"`

// ExtraNodeConfigFiles will be written to /var/snap/k8s/common/args/conf.d
ExtraNodeConfigFiles map[string]string `json:"extra-node-config-files,omitempty" yaml:"extra-node-config-files,omitempty"`

// Extra args to add to individual services (set any arg to null to delete)
ExtraNodeKubeAPIServerArgs map[string]*string `json:"extra-node-kube-apiserver-args,omitempty" yaml:"extra-node-kube-apiserver-args,omitempty"`
ExtraNodeKubeControllerManagerArgs map[string]*string `json:"extra-node-kube-controller-manager-args,omitempty" yaml:"extra-node-kube-controller-manager-args,omitempty"`
ExtraNodeKubeSchedulerArgs map[string]*string `json:"extra-node-kube-scheduler-args,omitempty" yaml:"extra-node-kube-scheduler-args,omitempty"`
ExtraNodeKubeProxyArgs map[string]*string `json:"extra-node-kube-proxy-args,omitempty" yaml:"extra-node-kube-proxy-args,omitempty"`
ExtraNodeKubeletArgs map[string]*string `json:"extra-node-kubelet-args,omitempty" yaml:"extra-node-kubelet-args,omitempty"`
ExtraNodeContainerdArgs map[string]*string `json:"extra-node-containerd-args,omitempty" yaml:"extra-node-containerd-args,omitempty"`
ExtraNodeK8sDqliteArgs map[string]*string `json:"extra-node-k8s-dqlite-args,omitempty" yaml:"extra-node-k8s-dqlite-args,omitempty"`
}

type WorkerNodeJoinConfig struct {
Expand All @@ -34,6 +46,15 @@ type WorkerNodeJoinConfig struct {
KubeletClientKey *string `json:"kubelet-client-key,omitempty" yaml:"kubelet-client-key,omitempty"`
KubeProxyClientCert *string `json:"kube-proxy-client-crt,omitempty" yaml:"kube-proxy-client-crt,omitempty"`
KubeProxyClientKey *string `json:"kube-proxy-client-key,omitempty" yaml:"kube-proxy-client-key,omitempty"`

// ExtraNodeConfigFiles will be written to /var/snap/k8s/common/args/conf.d
ExtraNodeConfigFiles map[string]string `json:"extra-node-config-files,omitempty" yaml:"extra-node-config-files,omitempty"`

// Extra args to add to individual services (set any arg to null to delete)
ExtraNodeKubeProxyArgs map[string]*string `json:"extra-node-kube-proxy-args,omitempty" yaml:"extra-node-kube-proxy-args,omitempty"`
ExtraNodeKubeletArgs map[string]*string `json:"extra-node-kubelet-args,omitempty" yaml:"extra-node-kubelet-args,omitempty"`
ExtraNodeContainerdArgs map[string]*string `json:"extra-node-containerd-args,omitempty" yaml:"extra-node-containerd-args,omitempty"`
ExtraNodeK8sAPIServerProxyArgs map[string]*string `json:"extra-node-k8s-apiserver-proxy-args,omitempty" yaml:"extra-node-k8s-apiserver-proxy-args,omitempty"`
}

func (c *ControlPlaneNodeJoinConfig) GetFrontProxyClientCert() string {
Expand Down
24 changes: 16 additions & 8 deletions src/k8s/cmd/k8s/k8s_bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,22 @@ var testCases = []testCase{
},
CloudProvider: utils.Pointer("external"),
},
ControlPlaneTaints: []string{"node-role.kubernetes.io/control-plane:NoSchedule"},
PodCIDR: utils.Pointer("10.100.0.0/16"),
ServiceCIDR: utils.Pointer("10.200.0.0/16"),
DisableRBAC: utils.Pointer(false),
SecurePort: utils.Pointer(6443),
K8sDqlitePort: utils.Pointer(9090),
DatastoreType: utils.Pointer("k8s-dqlite"),
ExtraSANs: []string{"custom.kubernetes"},
ControlPlaneTaints: []string{"node-role.kubernetes.io/control-plane:NoSchedule"},
PodCIDR: utils.Pointer("10.100.0.0/16"),
ServiceCIDR: utils.Pointer("10.200.0.0/16"),
DisableRBAC: utils.Pointer(false),
SecurePort: utils.Pointer(6443),
K8sDqlitePort: utils.Pointer(9090),
DatastoreType: utils.Pointer("k8s-dqlite"),
ExtraSANs: []string{"custom.kubernetes"},
ExtraNodeConfigFiles: map[string]string{"extra-node-config-file.yaml": "test-file-content"},
ExtraNodeKubeAPIServerArgs: map[string]*string{"--extra-kube-apiserver-arg": utils.Pointer("extra-kube-apiserver-value")},
ExtraNodeKubeControllerManagerArgs: map[string]*string{"--extra-kube-controller-manager-arg": utils.Pointer("extra-kube-controller-manager-value")},
ExtraNodeKubeSchedulerArgs: map[string]*string{"--extra-kube-scheduler-arg": utils.Pointer("extra-kube-scheduler-value")},
ExtraNodeKubeProxyArgs: map[string]*string{"--extra-kube-proxy-arg": utils.Pointer("extra-kube-proxy-value")},
ExtraNodeKubeletArgs: map[string]*string{"--extra-kubelet-arg": utils.Pointer("extra-kubelet-value")},
ExtraNodeContainerdArgs: map[string]*string{"--extra-containerd-arg": utils.Pointer("extra-containerd-value")},
ExtraNodeK8sDqliteArgs: map[string]*string{"--extra-k8s-dqlite-arg": utils.Pointer("extra-k8s-dqlite-value")},
},
},
{
Expand Down
16 changes: 16 additions & 0 deletions src/k8s/cmd/k8s/testdata/bootstrap-config-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ k8s-dqlite-port: 9090
datastore-type: k8s-dqlite
extra-sans:
- custom.kubernetes
extra-node-config-files:
extra-node-config-file.yaml: test-file-content
extra-node-kube-apiserver-args:
--extra-kube-apiserver-arg: extra-kube-apiserver-value
extra-node-kube-controller-manager-args:
--extra-kube-controller-manager-arg: extra-kube-controller-manager-value
extra-node-kube-scheduler-args:
--extra-kube-scheduler-arg: extra-kube-scheduler-value
extra-node-kube-proxy-args:
--extra-kube-proxy-arg: extra-kube-proxy-value
extra-node-kubelet-args:
--extra-kubelet-arg: extra-kubelet-value
extra-node-containerd-args:
--extra-containerd-arg: extra-containerd-value
extra-node-k8s-dqlite-args:
--extra-k8s-dqlite-arg: extra-k8s-dqlite-value
25 changes: 0 additions & 25 deletions src/k8s/pkg/k8sd/app/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package app
import (
"context"
"fmt"
"net"
"path"

"github.com/canonical/k8s/pkg/k8sd/pki"
"github.com/canonical/k8s/pkg/k8sd/setup"
"github.com/canonical/k8s/pkg/k8sd/types"
"github.com/canonical/k8s/pkg/snap"
snaputil "github.com/canonical/k8s/pkg/snap/util"
"github.com/canonical/microcluster/state"
Expand All @@ -35,29 +33,6 @@ func setupKubeconfigs(s *state.State, kubeConfigDir string, securePort int, pki

}

func setupControlPlaneServices(snap snap.Snap, s *state.State, cfg types.ClusterConfig, nodeIP net.IP) error {
// Configure services
if err := setup.Containerd(snap, nil); err != nil {
return fmt.Errorf("failed to configure containerd: %w", err)
}
if err := setup.KubeletControlPlane(snap, s.Name(), nodeIP, cfg.Kubelet.GetClusterDNS(), cfg.Kubelet.GetClusterDomain(), cfg.Kubelet.GetCloudProvider(), cfg.Kubelet.GetControlPlaneTaints()); err != nil {
return fmt.Errorf("failed to configure kubelet: %w", err)
}
if err := setup.KubeProxy(s.Context, snap, s.Name(), cfg.Network.GetPodCIDR()); err != nil {
return fmt.Errorf("failed to configure kube-proxy: %w", err)
}
if err := setup.KubeControllerManager(snap); err != nil {
return fmt.Errorf("failed to configure kube-controller-manager: %w", err)
}
if err := setup.KubeScheduler(snap); err != nil {
return fmt.Errorf("failed to configure kube-scheduler: %w", err)
}
if err := setup.KubeAPIServer(snap, cfg.Network.GetServiceCIDR(), s.Address().Path("1.0", "kubernetes", "auth", "webhook").String(), true, cfg.Datastore, cfg.APIServer.GetAuthorizationMode()); err != nil {
return fmt.Errorf("failed to configure kube-apiserver: %w", err)
}
return nil
}

func startControlPlaneServices(ctx context.Context, snap snap.Snap, datastore string) error {
// Start services
switch datastore {
Expand Down
Loading
Loading