Skip to content

Change worker labels to be a map #5822

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ func (c *command) startWorker(ctx context.Context, nodeName apitypes.NodeName, k
// opts to start the worker. Needs to be a copy so the original token and
// possibly other args won't get messed up.
wc := workercmd.Command(*(*config.CLIOptions)(c))
wc.Labels = append(wc.Labels, fields.OneTermEqualSelector(constant.K0SNodeRoleLabel, "control-plane").String())
wc.Labels[constant.K0SNodeRoleLabel] = "control-plane"
if opts.Mode() == config.ControllerPlusWorkerMode && !opts.NoTaints {
key := path.Join(constant.NodeRoleLabelNamespace, "master")
taint := fields.OneTermEqualSelector(key, ":NoSchedule")
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Flags:
--kube-controller-manager-extra-args string extra args for kube-controller-manager
--kubelet-extra-args string extra args for kubelet
--kubelet-root-dir string Kubelet root directory for k0s
--labels strings Node labels, list of key=value pairs
--labels mapStringString Node labels, list of key=value pairs
-l, --logging stringToString Logging Levels for the different components (default [containerd=info,etcd=info,konnectivity-server=1,kube-apiserver=1,kube-controller-manager=1,kube-scheduler=1,kubelet=1])
--no-taints disable default taints for controller node
--profile string worker profile to use on the node (default "default")
Expand Down
2 changes: 1 addition & 1 deletion cmd/install/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Flags:
--kube-controller-manager-extra-args string extra args for kube-controller-manager
--kubelet-extra-args string extra args for kubelet
--kubelet-root-dir string Kubelet root directory for k0s
--labels strings Node labels, list of key=value pairs
--labels mapStringString Node labels, list of key=value pairs
-l, --logging stringToString Logging Levels for the different components (default [containerd=info,etcd=info,konnectivity-server=1,kube-apiserver=1,kube-controller-manager=1,kube-scheduler=1,kubelet=1])
--no-taints disable default taints for controller node
--profile string worker profile to use on the node (default "default")
Expand Down
5 changes: 3 additions & 2 deletions pkg/component/worker/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
corev1 "k8s.io/api/core/v1"
apitypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation"
cliflag "k8s.io/component-base/cli/flag"
kubeletv1beta1 "k8s.io/kubelet/config/v1beta1"

"github.com/sirupsen/logrus"
Expand All @@ -58,7 +59,7 @@ type Kubelet struct {
StaticPods StaticPods
LogLevel string
ClusterDNS string
Labels []string
Labels map[string]string
Taints []string
ExtraArgs stringmap.StringMap
DualStackEnabled bool
Expand Down Expand Up @@ -140,7 +141,7 @@ func (k *Kubelet) Start(ctx context.Context) error {
}

if len(k.Labels) > 0 {
args["--node-labels"] = strings.Join(k.Labels, ",")
args["--node-labels"] = ((*cliflag.ConfigurationMap)(&k.Labels)).String()
}

if k.DualStackEnabled && k.ExtraArgs["--node-ip"] == "" {
Expand Down
11 changes: 9 additions & 2 deletions pkg/config/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/k0sproject/k0s/pkg/constant"
"github.com/k0sproject/k0s/pkg/k0scloudprovider"

cliflag "k8s.io/component-base/cli/flag"

"github.com/spf13/pflag"
)

Expand Down Expand Up @@ -75,7 +77,7 @@ type WorkerOptions struct {
LogLevels LogLevels
CriSocket string
KubeletExtraArgs string
Labels []string
Labels map[string]string
Taints []string
TokenFile string
TokenArg string
Expand Down Expand Up @@ -243,12 +245,17 @@ func GetWorkerFlags() *pflag.FlagSet {
f.Deprecated = "it has no effect and will be removed in a future release"
})

if workerOpts.Labels == nil {
// cliflag.ConfigurationMap expects the map to be non-nil.
workerOpts.Labels = make(map[string]string)
}

flagset.String("kubelet-root-dir", "", "Kubelet root directory for k0s")
flagset.StringVar(&workerOpts.WorkerProfile, "profile", "default", "worker profile to use on the node")
flagset.BoolVar(&workerOpts.CloudProvider, "enable-cloud-provider", false, "Whether or not to enable cloud provider support in kubelet")
flagset.StringVar(&workerOpts.TokenFile, "token-file", "", "Path to the file containing join-token.")
flagset.VarP((*logLevelsFlag)(&workerOpts.LogLevels), "logging", "l", "Logging Levels for the different components")
flagset.StringSliceVarP(&workerOpts.Labels, "labels", "", []string{}, "Node labels, list of key=value pairs")
flagset.Var((*cliflag.ConfigurationMap)(&workerOpts.Labels), "labels", "Node labels, list of key=value pairs")
flagset.StringSliceVarP(&workerOpts.Taints, "taints", "", []string{}, "Node taints, list of key=value:effect strings")
flagset.StringVar(&workerOpts.KubeletExtraArgs, "kubelet-extra-args", "", "extra args for kubelet")
flagset.StringVar(&workerOpts.IPTablesMode, "iptables-mode", "", "iptables mode (valid values: nft, legacy, auto). default: auto")
Expand Down
Loading