From f8b2e240fdf0b565f31e3de6824f180180f58b97 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Wed, 28 May 2025 20:56:58 +0200 Subject: [PATCH] Add support for custom extraArgs to kine process Enables configuration of datastore-max-open-connections and other datastore specific options which could be essential. Signed-off-by: Marc Hoersken --- docs/configuration.md | 1 + pkg/apis/k0s/v1beta1/storage.go | 3 +++ pkg/apis/k0s/v1beta1/storage_test.go | 13 +++++++++++ pkg/component/controller/kine.go | 34 +++++++++++++++++++--------- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index aa7d0f3f7847..d8865b288d22 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -142,6 +142,7 @@ spec: | `etcd.ca.expiresAfter` | The expiration duration of the CA certificate (default: 87600h) | | `etcd.ca.certificatesExpireAfter` | The expiration duration of the server certificate (default: 8760h) | | `kine.dataSource` | [kine](https://github.com/k3s-io/kine) datasource URL. | +| `kine.extraArgs` | Map of key-values (strings) for any extra arguments to pass down to kine process. Any behavior triggered by these parameters is outside k0s support. | | `etcd.externalCluster` | Configuration when etcd is externally managed, i.e. running on dedicated nodes. See [`spec.storage.etcd.externalCluster`](#specstorageetcdexternalcluster) | #### `spec.storage.etcd.externalCluster` diff --git a/pkg/apis/k0s/v1beta1/storage.go b/pkg/apis/k0s/v1beta1/storage.go index a7e61381deb6..926340754001 100644 --- a/pkg/apis/k0s/v1beta1/storage.go +++ b/pkg/apis/k0s/v1beta1/storage.go @@ -63,6 +63,9 @@ const ( type KineConfig struct { // kine datasource URL DataSource string `json:"dataSource,omitempty"` + + // Map of key-values (strings) for any extra arguments you want to pass down to the kine process + ExtraArgs map[string]string `json:"extraArgs,omitempty"` } // DefaultStorageSpec creates StorageSpec with sane defaults diff --git a/pkg/apis/k0s/v1beta1/storage_test.go b/pkg/apis/k0s/v1beta1/storage_test.go index 59a848e20697..28f8f3531913 100644 --- a/pkg/apis/k0s/v1beta1/storage_test.go +++ b/pkg/apis/k0s/v1beta1/storage_test.go @@ -74,6 +74,19 @@ func TestStorageSpec_IsJoinable(t *testing.T) { }, want: true, }, + { + name: "kine-mysql-extra-args", + storage: StorageSpec{ + Type: "kine", + Kine: &KineConfig{ + DataSource: "mysql://foobar", + ExtraArgs: map[string]string{ + "datastore-max-open-connections": "10", + }, + }, + }, + want: true, + }, { name: "kine-postgres", storage: StorageSpec{ diff --git a/pkg/component/controller/kine.go b/pkg/component/controller/kine.go index 59db023656af..818be76de747 100644 --- a/pkg/component/controller/kine.go +++ b/pkg/component/controller/kine.go @@ -35,6 +35,7 @@ import ( "github.com/sirupsen/logrus" "github.com/k0sproject/k0s/internal/pkg/dir" + "github.com/k0sproject/k0s/internal/pkg/stringmap" "github.com/k0sproject/k0s/internal/pkg/users" "github.com/k0sproject/k0s/pkg/assets" "github.com/k0sproject/k0s/pkg/constant" @@ -113,22 +114,33 @@ func (k *Kine) Init(_ context.Context) error { func (k *Kine) Start(ctx context.Context) error { logrus.Info("Starting kine") + args := stringmap.StringMap{ + "--endpoint": k.Config.DataSource, + // NB: kine doesn't parse URLs properly, so construct potentially + // invalid URLs that are understood by kine. + // https://github.com/k3s-io/kine/blob/v0.13.12/pkg/util/network.go#L5-L13 + "--listen-address": "unix://" + k.K0sVars.KineSocketPath, + // Enable metrics on port 2380. The default is 8080, which clashes with kube-router. + "--metrics-bind-address": ":2380", + } + + // Add custom flags from the config if provided via kine.extraArgs + for name, value := range k.Config.ExtraArgs { + argName := "--" + name + if _, ok := args[argName]; ok { + logrus.Warnf("overriding kine flag with user provided value: %s", argName) + } + args[argName] = value + } + k.supervisor = supervisor.Supervisor{ Name: "kine", BinPath: assets.BinPath("kine", k.K0sVars.BinDir), DataDir: k.K0sVars.DataDir, RunDir: k.K0sVars.RunDir, - Args: []string{ - "--endpoint=" + k.Config.DataSource, - // NB: kine doesn't parse URLs properly, so construct potentially - // invalid URLs that are understood by kine. - // https://github.com/k3s-io/kine/blob/v0.13.12/pkg/util/network.go#L5-L13 - "--listen-address=unix://" + k.K0sVars.KineSocketPath, - // Enable metrics on port 2380. The default is 8080, which clashes with kube-router. - "--metrics-bind-address=:2380", - }, - UID: k.uid, - GID: k.gid, + Args: args.ToArgs(), + UID: k.uid, + GID: k.gid, } return k.supervisor.Supervise()