PE-6055 fix: use string slice instead of string for k3s args (#106)

* fix: use string slice instead of string for k3s args

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* fix: test

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

---------

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>
This commit is contained in:
Nianyu Shen 2025-01-30 19:54:25 -08:00 committed by GitHub
parent 965a113cbd
commit 701adfd4a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 123 additions and 93 deletions

View File

@ -37,6 +37,7 @@ BUILD_GOLANG:
ARG BIN
ARG SRC
ENV CGO_ENABLED=0
ARG VERSION
ENV GO_LDFLAGS=" -X github.com/kairos-io/provider-k3s/pkg/version.Version=${VERSION} -w -s"
RUN go-build-static.sh -a -o ${BIN} ./${SRC}
SAVE ARTIFACT ${BIN} ${BIN} AS LOCAL build/${BIN}
@ -60,8 +61,10 @@ lint:
RUN golangci-lint run
build-provider:
DO +VERSION
ARG VERSION=$(cat VERSION)
FROM +go-deps
DO +BUILD_GOLANG --BIN=agent-provider-k3s --SRC=main.go
DO +BUILD_GOLANG --BIN=agent-provider-k3s --SRC=main.go --VERSION=$VERSION
build-provider-package:
DO +VERSION

View File

@ -1,50 +1,50 @@
package api
type K3sAgentConfig struct {
ConfigFile string `json:"config,omitempty" yaml:"config,omitempty"`
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`
V int `json:"v,omitempty" yaml:"v,omitempty"`
VModule string `json:"vmodule,omitempty" yaml:"vmodule,omitempty"`
Log string `json:"log,omitempty" yaml:"log,omitempty"`
AlsoLogToStderr bool `json:"alsologtostderr,omitempty" yaml:"alsologtostderr,omitempty"`
Token string `json:"token,omitempty" yaml:"token,omitempty"`
TokenFile string `json:"token-file,omitempty" yaml:"token-file,omitempty"`
Server string `json:"server,omitempty" yaml:"server,omitempty"`
DataDir string `json:"data-dir,omitempty" yaml:"data-dir,omitempty"`
NodeName string `json:"node-name,omitempty" yaml:"node-name,omitempty"`
WithNodeID bool `json:"with-node-id,omitempty" yaml:"with-node-id,omitempty"`
NodeLabels string `json:"node-label,omitempty" yaml:"node-label,omitempty"`
NodeTaints string `json:"node-taint,omitempty" yaml:"node-taint,omitempty"`
ImageCredentialProviderBinDir string `json:"image-credential-provider-bin-dir,omitempty" yaml:"image-credential-provider-bin-dir,omitempty"`
ImageCredentialProviderConfig string `json:"image-credential-provider-config,omitempty" yaml:"image-credential-provider-config,omitempty"`
EnableSELinux bool `json:"selinux,omitempty" yaml:"selinux,omitempty"`
LBServerPort int `json:"lb-server-port,omitempty" yaml:"lb-server-port,omitempty"`
ProtectKernelDefaults bool `json:"protect-kernel-defaults,omitempty" yaml:"protect-kernel-defaults,omitempty"`
ContainerRuntimeEndpoint string `json:"container-runtime-endpoint,omitempty" yaml:"container-runtime-endpoint,omitempty"`
DefaultRuntime string `json:"default-runtime,omitempty" yaml:"default-runtime,omitempty"`
ImageServiceEndpoint string `json:"image-service-endpoint,omitempty" yaml:"image-service-endpoint,omitempty"`
PauseImage string `json:"pause-image,omitempty" yaml:"pause-image,omitempty"`
Snapshotter string `json:"snapshotter,omitempty" yaml:"snapshotter,omitempty"`
PrivateRegistry string `json:"private-registry,omitempty" yaml:"private-registry,omitempty"`
DisableDefaultRegistryEndpoint bool `json:"disable-default-registry-endpoint,omitempty" yaml:"disable-default-registry-endpoint,omitempty"`
NonrootDevices bool `json:"nonroot-devices,omitempty" yaml:"nonroot-devices,omitempty"`
AirgapExtraRegistry string `json:"airgap-extra-registry,omitempty" yaml:"airgap-extra-registry,omitempty"`
NodeIP string `json:"node-ip,omitempty" yaml:"node-ip,omitempty"`
BindAddress string `json:"bind-address,omitempty" yaml:"bind-address,omitempty"`
NodeExternalIP string `json:"node-external-ip,omitempty" yaml:"node-external-ip,omitempty"`
NodeInternalDNS string `json:"node-internal-dns,omitempty" yaml:"node-internal-dns,omitempty"`
NodeExternalDNS string `json:"node-external-dns,omitempty" yaml:"node-external-dns,omitempty"`
ResolvConf string `json:"resolv-conf,omitempty" yaml:"resolv-conf,omitempty"`
FlannelIface string `json:"flannel-iface,omitempty" yaml:"flannel-iface,omitempty"`
FlannelConf string `json:"flannel-conf,omitempty" yaml:"flannel-conf,omitempty"`
FlannelCniConfFile string `json:"flannel-cni-conf,omitempty" yaml:"flannel-cni-conf,omitempty"`
KubeletArg string `json:"kubelet-arg,omitempty" yaml:"kubelet-arg,omitempty"`
KubeProxyArg string `json:"kube-proxy-arg,omitempty" yaml:"kube-proxy-arg,omitempty"`
EnablePProf bool `json:"enable-pprof,omitempty" yaml:"enable-pprof,omitempty"`
Rootless bool `json:"rootless,omitempty" yaml:"rootless,omitempty"`
PreferBundledBin bool `json:"prefer-bundled-bin,omitempty" yaml:"prefer-bundled-bin,omitempty"`
Docker bool `json:"docker,omitempty" yaml:"docker,omitempty"`
VPNAuth string `json:"vpn-auth,omitempty" yaml:"vpn-auth,omitempty"`
VPNAuthFile string `json:"vpn-auth-file,omitempty" yaml:"vpn-auth-file,omitempty"`
DisableApiServerLB bool `json:"disable-apiserver-lb,omitempty" yaml:"disable-apiserver-lb,omitempty"`
ConfigFile string `json:"config,omitempty" yaml:"config,omitempty"`
Debug bool `json:"debug,omitempty" yaml:"debug,omitempty"`
V int `json:"v,omitempty" yaml:"v,omitempty"`
VModule string `json:"vmodule,omitempty" yaml:"vmodule,omitempty"`
Log string `json:"log,omitempty" yaml:"log,omitempty"`
AlsoLogToStderr bool `json:"alsologtostderr,omitempty" yaml:"alsologtostderr,omitempty"`
Token string `json:"token,omitempty" yaml:"token,omitempty"`
TokenFile string `json:"token-file,omitempty" yaml:"token-file,omitempty"`
Server string `json:"server,omitempty" yaml:"server,omitempty"`
DataDir string `json:"data-dir,omitempty" yaml:"data-dir,omitempty"`
NodeName string `json:"node-name,omitempty" yaml:"node-name,omitempty"`
WithNodeID bool `json:"with-node-id,omitempty" yaml:"with-node-id,omitempty"`
NodeLabels []string `json:"node-label,omitempty" yaml:"node-label,omitempty"`
NodeTaints []string `json:"node-taint,omitempty" yaml:"node-taint,omitempty"`
ImageCredentialProviderBinDir string `json:"image-credential-provider-bin-dir,omitempty" yaml:"image-credential-provider-bin-dir,omitempty"`
ImageCredentialProviderConfig string `json:"image-credential-provider-config,omitempty" yaml:"image-credential-provider-config,omitempty"`
EnableSELinux bool `json:"selinux,omitempty" yaml:"selinux,omitempty"`
LBServerPort int `json:"lb-server-port,omitempty" yaml:"lb-server-port,omitempty"`
ProtectKernelDefaults bool `json:"protect-kernel-defaults,omitempty" yaml:"protect-kernel-defaults,omitempty"`
ContainerRuntimeEndpoint string `json:"container-runtime-endpoint,omitempty" yaml:"container-runtime-endpoint,omitempty"`
DefaultRuntime string `json:"default-runtime,omitempty" yaml:"default-runtime,omitempty"`
ImageServiceEndpoint string `json:"image-service-endpoint,omitempty" yaml:"image-service-endpoint,omitempty"`
PauseImage string `json:"pause-image,omitempty" yaml:"pause-image,omitempty"`
Snapshotter string `json:"snapshotter,omitempty" yaml:"snapshotter,omitempty"`
PrivateRegistry string `json:"private-registry,omitempty" yaml:"private-registry,omitempty"`
DisableDefaultRegistryEndpoint bool `json:"disable-default-registry-endpoint,omitempty" yaml:"disable-default-registry-endpoint,omitempty"`
NonrootDevices bool `json:"nonroot-devices,omitempty" yaml:"nonroot-devices,omitempty"`
AirgapExtraRegistry []string `json:"airgap-extra-registry,omitempty" yaml:"airgap-extra-registry,omitempty"`
NodeIP []string `json:"node-ip,omitempty" yaml:"node-ip,omitempty"`
BindAddress string `json:"bind-address,omitempty" yaml:"bind-address,omitempty"`
NodeExternalIP []string `json:"node-external-ip,omitempty" yaml:"node-external-ip,omitempty"`
NodeInternalDNS []string `json:"node-internal-dns,omitempty" yaml:"node-internal-dns,omitempty"`
NodeExternalDNS []string `json:"node-external-dns,omitempty" yaml:"node-external-dns,omitempty"`
ResolvConf string `json:"resolv-conf,omitempty" yaml:"resolv-conf,omitempty"`
FlannelIface string `json:"flannel-iface,omitempty" yaml:"flannel-iface,omitempty"`
FlannelConf string `json:"flannel-conf,omitempty" yaml:"flannel-conf,omitempty"`
FlannelCniConfFile string `json:"flannel-cni-conf,omitempty" yaml:"flannel-cni-conf,omitempty"`
KubeletArg []string `json:"kubelet-arg,omitempty" yaml:"kubelet-arg,omitempty"`
KubeProxyArg []string `json:"kube-proxy-arg,omitempty" yaml:"kube-proxy-arg,omitempty"`
EnablePProf bool `json:"enable-pprof,omitempty" yaml:"enable-pprof,omitempty"`
Rootless bool `json:"rootless,omitempty" yaml:"rootless,omitempty"`
PreferBundledBin bool `json:"prefer-bundled-bin,omitempty" yaml:"prefer-bundled-bin,omitempty"`
Docker bool `json:"docker,omitempty" yaml:"docker,omitempty"`
VPNAuth string `json:"vpn-auth,omitempty" yaml:"vpn-auth,omitempty"`
VPNAuthFile string `json:"vpn-auth-file,omitempty" yaml:"vpn-auth-file,omitempty"`
DisableApiServerLB bool `json:"disable-apiserver-lb,omitempty" yaml:"disable-apiserver-lb,omitempty"`
}

View File

@ -2,6 +2,30 @@ package api
import "time"
var StringListKeys = []string{
"tls-san",
"cluster-cidr",
"service-cidr",
"cluster-dns",
"node-label",
"node-taint",
"kube-apiserver-arg",
"etcd-arg",
"kube-controller-manager-arg",
"kube-scheduler-arg",
"kube-cloud-controller-manager-arg",
"disable",
"airgap-extra-registry",
"node-ip",
"node-external-ip",
"node-internal-dns",
"node-external-dns",
"kubelet-arg",
"kube-proxy-arg",
"kube-controller-arg",
"kube-cloud-controller-arg",
}
type K3sServerConfig struct {
ConfigFile string `json:"config,omitempty" yaml:"config,omitempty"`
Debug bool `yaml:"debug,omitempty" json:"debug,omitempty"`
@ -16,13 +40,13 @@ type K3sServerConfig struct {
ApiServerBindAddress string `yaml:"apiserver-bind-address,omitempty" json:"apiserver-bind-address,omitempty"`
AdvertiseAddress string `yaml:"advertise-address,omitempty" json:"advertise-address,omitempty"`
AdvertisePort int `yaml:"advertise-port,omitempty" json:"advertise-port,omitempty"`
TLSSan string `yaml:"tls-san,omitempty" json:"tls-san,omitempty"`
TLSSan []string `yaml:"tls-san,omitempty" json:"tls-san,omitempty"`
TLSSanSecurity bool `yaml:"tls-san-security,omitempty" json:"tls-san-security,omitempty"`
DataDir string `yaml:"data-dir,omitempty" json:"data-dir,omitempty"`
ClusterCIDR string `yaml:"cluster-cidr,omitempty" json:"cluster-cidr,omitempty"`
ServiceCIDR string `yaml:"service-cidr,omitempty" json:"service-cidr,omitempty"`
ClusterCIDR []string `yaml:"cluster-cidr,omitempty" json:"cluster-cidr,omitempty"`
ServiceCIDR []string `yaml:"service-cidr,omitempty" json:"service-cidr,omitempty"`
ServiceNodePortRange string `yaml:"service-node-port-range,omitempty" json:"service-node-port-range,omitempty"`
ClusterDNS string `yaml:"cluster-dns,omitempty" json:"cluster-dns,omitempty"`
ClusterDNS []string `yaml:"cluster-dns,omitempty" json:"cluster-dns,omitempty"`
ClusterDomain string `yaml:"cluster-domain,omitempty" json:"cluster-domain,omitempty"`
FlannelBackend string `yaml:"flannel-backend,omitempty" json:"flannel-backend,omitempty"`
FlannelIPv6Masq bool `yaml:"flannel-ipv6-masq,omitempty" json:"flannel-ipv6-masq,omitempty"`
@ -41,11 +65,11 @@ type K3sServerConfig struct {
ClusterInit bool `yaml:"cluster-init,omitempty" json:"cluster-init,omitempty"`
ClusterReset bool `yaml:"cluster-reset,omitempty" json:"cluster-reset,omitempty"`
ClusterResetRestorePath string `yaml:"cluster-reset-restore-path,omitempty" json:"cluster-reset-restore-path,omitempty"`
KubeApiServerArg string `yaml:"kube-apiserver-arg,omitempty" json:"kube-apiserver-arg,omitempty"`
EtcdArg string `yaml:"etcd-arg,omitempty" json:"etcd-arg,omitempty"`
KubeControllerManagerArg string `yaml:"kube-controller-manager-arg,omitempty" json:"kube-controller-manager-arg,omitempty"`
KubeSchedulerArg string `yaml:"kube-scheduler-arg,omitempty" json:"kube-scheduler-arg,omitempty"`
KubeCloudControllerManagerArg string `yaml:"kube-cloud-controller-manager-arg,omitempty" json:"kube-cloud-controller-manager-arg,omitempty"`
KubeApiServerArg []string `yaml:"kube-apiserver-arg,omitempty" json:"kube-apiserver-arg,omitempty"`
EtcdArg []string `yaml:"etcd-arg,omitempty" json:"etcd-arg,omitempty"`
KubeControllerManagerArg []string `yaml:"kube-controller-manager-arg,omitempty" json:"kube-controller-manager-arg,omitempty"`
KubeSchedulerArg []string `yaml:"kube-scheduler-arg,omitempty" json:"kube-scheduler-arg,omitempty"`
KubeCloudControllerManagerArg []string `yaml:"kube-cloud-controller-manager-arg,omitempty" json:"kube-cloud-controller-manager-arg,omitempty"`
KineTLS bool `yaml:"kine-tls,omitempty" json:"kine-tls,omitempty"`
DatastoreEndpoint string `yaml:"datastore-endpoint,omitempty" json:"datastore-endpoint,omitempty"`
DatastoreCaFile string `yaml:"datastore-cafile,omitempty" json:"datastore-cafile,omitempty"`
@ -72,7 +96,7 @@ type K3sServerConfig struct {
EtcdS3Insecure bool `json:"etcd-s3-insecure,omitempty" yaml:"etcd-s3-insecure,omitempty"`
EtcdS3Timeout time.Duration `json:"etcd-s3-timeout,omitempty" yaml:"etcd-s3-timeout,omitempty"`
DefaultLocalStoragePath string `yaml:"default-local-storage-path,omitempty" json:"default-local-storage-path,omitempty"`
Disable string `json:"disable,omitempty" yaml:"disable,omitempty"`
Disable []string `json:"disable,omitempty" yaml:"disable,omitempty"`
DisableScheduler bool `json:"disable-scheduler,omitempty" yaml:"disable-scheduler,omitempty"`
DisableCloudController bool `json:"disable-cloud-controller,omitempty" yaml:"disable-cloud-controller,omitempty"`
DisableKubeProxy bool `json:"disable-kube-proxy,omitempty" yaml:"disable-kube-proxy,omitempty"`
@ -85,8 +109,8 @@ type K3sServerConfig struct {
SupervisorMetrics bool `json:"supervisor-metrics,omitempty" yaml:"supervisor-metrics,omitempty"`
NodeName string `yaml:"node-name,omitempty" json:"node-name,omitempty"`
WithNodeID bool `json:"with-node-id,omitempty" yaml:"with-node-id,omitempty"`
NodeLabel string `yaml:"node-label,omitempty" json:"node-label,omitempty"`
NodeTaint string `yaml:"node-taint,omitempty" json:"node-taint,omitempty"`
NodeLabel []string `yaml:"node-label,omitempty" json:"node-label,omitempty"`
NodeTaint []string `yaml:"node-taint,omitempty" json:"node-taint,omitempty"`
ImageCredentialProviderBinDir string `json:"image-credential-provider-bin-dir,omitempty" yaml:"image-credential-provider-bin-dir,omitempty"`
ImageCredentialProviderConfig string `json:"image-credential-provider-config,omitempty" yaml:"image-credential-provider-config,omitempty"`
Docker bool `json:"docker,omitempty" yaml:"docker,omitempty"`
@ -99,19 +123,19 @@ type K3sServerConfig struct {
Snapshotter string `json:"snapshotter,omitempty" yaml:"snapshotter,omitempty"`
PrivateRegistry string `json:"private-registry,omitempty" yaml:"private-registry,omitempty"`
SystemDefaultRegistry string `yaml:"system-default-registry,omitempty" json:"system-default-registry,omitempty"`
AirgapExtraRegistry string `json:"airgap-extra-registry,omitempty" yaml:"airgap-extra-registry,omitempty"`
NodeIP string `yaml:"node-ip,omitempty" json:"node-ip,omitempty"`
NodeExternalIP string `yaml:"node-external-ip,omitempty" json:"node-external-ip,omitempty"`
NodeInternalDNS string `json:"node-internal-dns,omitempty" yaml:"node-internal-dns,omitempty"`
NodeExternalDNS string `json:"node-external-dns,omitempty" yaml:"node-external-dns,omitempty"`
AirgapExtraRegistry []string `json:"airgap-extra-registry,omitempty" yaml:"airgap-extra-registry,omitempty"`
NodeIP []string `yaml:"node-ip,omitempty" json:"node-ip,omitempty"`
NodeExternalIP []string `yaml:"node-external-ip,omitempty" json:"node-external-ip,omitempty"`
NodeInternalDNS []string `json:"node-internal-dns,omitempty" yaml:"node-internal-dns,omitempty"`
NodeExternalDNS []string `json:"node-external-dns,omitempty" yaml:"node-external-dns,omitempty"`
ResolvConf string `yaml:"resolv-conf,omitempty" json:"resolv-conf,omitempty"`
FlannelIface string `json:"flannel-iface,omitempty" yaml:"flannel-iface,omitempty"`
FlannelConf string `json:"flannel-conf,omitempty" yaml:"flannel-conf,omitempty"`
FlannelCniConfFile string `json:"flannel-cni-conf,omitempty" yaml:"flannel-cni-conf,omitempty"`
VPNAuth string `json:"vpn-auth,omitempty" yaml:"vpn-auth,omitempty"`
VPNAuthFile string `json:"vpn-auth-file,omitempty" yaml:"vpn-auth-file,omitempty"`
KubeletArg string `json:"kubelet-arg,omitempty" yaml:"kubelet-arg,omitempty"`
KubeProxyArg string `json:"kube-proxy-arg,omitempty" yaml:"kube-proxy-arg,omitempty"`
KubeletArg []string `json:"kubelet-arg,omitempty" yaml:"kubelet-arg,omitempty"`
KubeProxyArg []string `json:"kube-proxy-arg,omitempty" yaml:"kube-proxy-arg,omitempty"`
ProtectKernelDefaults bool `json:"protect-kernel-defaults,omitempty" yaml:"protect-kernel-defaults,omitempty"`
SecretsEncryption bool `yaml:"secrets-encryption,omitempty" json:"secrets-encryption,omitempty"`
EnablePProf bool `yaml:"enable-pprof,omitempty" json:"enable-pprof,omitempty"`
@ -120,6 +144,6 @@ type K3sServerConfig struct {
EnableSELinux bool `json:"selinux,omitempty" yaml:"selinux,omitempty"`
LBServerPort int `json:"lb-server-port,omitempty" yaml:"lb-server-port,omitempty"`
DisableAgent bool `json:"disable-agent,omitempty" yaml:"disable-agent,omitempty"`
KubeControllerArg string `json:"kube-controller-arg,omitempty" yaml:"kube-controller-arg,omitempty"`
KubeCloudControllerArg string `json:"kube-cloud-controller-arg,omitempty" yaml:"kube-cloud-controller-arg,omitempty"`
KubeControllerArg []string `json:"kube-controller-arg,omitempty" yaml:"kube-controller-arg,omitempty"`
KubeCloudControllerArg []string `json:"kube-cloud-controller-arg,omitempty" yaml:"kube-cloud-controller-arg,omitempty"`
}

View File

@ -3,6 +3,7 @@ package provider
import (
"encoding/json"
"fmt"
"slices"
"net"
"path/filepath"
@ -74,7 +75,7 @@ func parseOptions(cluster clusterplugin.Cluster) ([]byte, []byte, []byte) {
if cluster.Role == clusterplugin.RoleControlPlane {
k3sConfig.Server = fmt.Sprintf("https://%s:6443", cluster.ControlPlaneHost)
}
k3sConfig.TLSSan = cluster.ControlPlaneHost
k3sConfig.TLSSan = []string{cluster.ControlPlaneHost}
// Data received from upstream contains config for both control plane and worker. Thus, for control plane,
// config is being filtered via unmarshal into server config.
var serverCfg api.K3sServerConfig
@ -299,21 +300,21 @@ func getClusterRootPath(cluster clusterplugin.Cluster) string {
func decodeOptions(in map[string]interface{}) map[string]interface{} {
out := make(map[string]interface{})
for k, v := range in {
out[k] = decodeOption(v)
out[k] = decodeOption(k, v)
}
return out
}
func decodeOption(in interface{}) interface{} {
func decodeOption(k string, in interface{}) interface{} {
switch in := in.(type) {
case []interface{}:
var out []string
for _, v := range in {
out = append(out, decodeOption(v).(string))
case string:
split := strings.Split(in, ",")
if len(split) > 1 {
return split
} else if slices.Contains(api.StringListKeys, k) {
return []string{in}
}
return strings.Join(out, ",")
case []string:
return strings.Join(in, ",")
return in
}
return in
}

View File

@ -32,7 +32,7 @@ func Test_parseOptions(t *testing.T) {
ControlPlaneHost: "localhost",
Role: "init",
},
expectedOptions: []byte(`{"tls-san":"localhost","token":"token","cluster-init":true}`),
expectedOptions: []byte(`{"tls-san":["localhost"],"token":"token","cluster-init":true}`),
expectedProxyOptions: []byte(`null`),
expectedUserOptions: []byte(`{}`),
},
@ -47,7 +47,7 @@ func Test_parseOptions(t *testing.T) {
"datastore-endpoint": "localhost:2379",
},
},
expectedOptions: []byte(`{"cluster-init":false,"tls-san":"localhost","token":"token","datastore-endpoint":"localhost:2379"}`),
expectedOptions: []byte(`{"cluster-init":false,"tls-san":["localhost"],"token":"token","datastore-endpoint":"localhost:2379"}`),
expectedProxyOptions: []byte(`null`),
expectedUserOptions: []byte(`{}`),
},
@ -58,7 +58,7 @@ func Test_parseOptions(t *testing.T) {
ControlPlaneHost: "localhost",
Role: "controlplane",
},
expectedOptions: []byte(`{"tls-san":"localhost","token":"token","server":"https://localhost:6443"}`),
expectedOptions: []byte(`{"tls-san":["localhost"],"token":"token","server":"https://localhost:6443"}`),
expectedProxyOptions: []byte(`null`),
expectedUserOptions: []byte(`{}`),
},
@ -82,7 +82,7 @@ func Test_parseOptions(t *testing.T) {
Options: `disable-apiserver-lb: true
enable-pprof: true`,
},
expectedOptions: []byte(`{"tls-san":"localhost","token":"token","server":"https://localhost:6443"}`),
expectedOptions: []byte(`{"tls-san":["localhost"],"token":"token","server":"https://localhost:6443"}`),
expectedProxyOptions: []byte(`{"disable-apiserver-lb":true,"enable-pprof":true}`),
expectedUserOptions: []byte(`{"enable-pprof":true}`),
},
@ -142,7 +142,7 @@ func Test_decodeOptions(t *testing.T) {
},
},
want: map[string]interface{}{
"test": "xyz,zyx",
"test": []string{"xyz", "zyx"},
},
},
{
@ -153,7 +153,7 @@ func Test_decodeOptions(t *testing.T) {
},
},
want: map[string]interface{}{
"test": "xyz,zyx",
"test": []interface{}{"xyz", "zyx"},
},
},
{
@ -165,23 +165,25 @@ func Test_decodeOptions(t *testing.T) {
},
},
want: map[string]interface{}{
"test": "xyz,zyx",
"test2": "abc,cba",
"test": []interface{}{"xyz", "zyx"},
"test2": []string{"abc", "cba"},
},
},
{
name: "One list of interfaces and one list of strings",
name: "One string and one comma separated string",
args: args{
in: map[string]interface{}{
"test": []interface{}{"xyz", "zyx"},
"test2": []string{"abc", "cba"},
"test3": []interface{}{[]interface{}{"lmn", "pqr"}, "fed"},
"test": "xyz,zyx",
"test2": []string{"abc", "cba"},
"test3": "xyz",
"cluster-cidr": "192.168.0.1/24",
},
},
want: map[string]interface{}{
"test": "xyz,zyx",
"test2": "abc,cba",
"test3": "lmn,pqr,fed",
"test": []string{"xyz", "zyx"},
"test2": []string{"abc", "cba"},
"test3": "xyz",
"cluster-cidr": []string{"192.168.0.1/24"},
},
},
}