Skip to content

Commit

Permalink
Add spec.hosts.noTaints to disable default controller+worker taints (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kke authored May 27, 2022
1 parent a2d5fc2 commit 88b097a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ One of:
- `single` - a [single-node cluster](https://docs.k0sproject.io/main/k0s-single-node/) host, the configuration can only contain one host
- `worker` - a worker host

###### `spec.hosts[*].noTaints` <boolean> (optional) (default: `false`)

When `true` and used in conjuction with the `controller+worker` role, the default taints are disabled making regular workloads schedulable on the node. By default, k0s sets a node-role.kubernetes.io/master:NoSchedule taint on controller+worker nodes and only workloads with toleration for it will be scheduled.

###### `spec.hosts[*].uploadBinary` <boolean> (optional) (default: `false`)

When `true`, the k0s binaries for target host will be downloaded and cached on the local host and uploaded to the target.
Expand Down
4 changes: 4 additions & 0 deletions phase/gather_k0s_facts.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func (p *GatherK0sFacts) investigateK0s(h *cluster.Host) error {
}
}

if h.Role == "controller+worker" && !h.NoTaints {
log.Warnf("%s: the controller+worker node will not schedule regular workloads without toleration for node-role.kubernetes.io/master:NoSchedule unless 'noTaints: true' is set", h)
}

if h.Metadata.NeedsUpgrade {
log.Warnf("%s: k0s will be upgraded", h)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Host struct {
Files []*UploadFile `yaml:"files,omitempty"`
OSIDOverride string `yaml:"os,omitempty"`
HostnameOverride string `yaml:"hostname,omitempty"`
NoTaints bool `yaml:"noTaints,omitempty"`
Hooks Hooks `yaml:"hooks,omitempty"`

UploadBinaryPath string `yaml:"-"`
Expand All @@ -58,6 +59,10 @@ func (h *Host) SetDefaults() {
log.Debugf("%s: changed role from '%s' to 'controller+worker' because of --enable-worker installFlag", h, h.Role)
h.Role = "controller+worker"
}

if h.InstallFlags.Get("--no-taints") != "" && h.InstallFlags.GetValue("--no-taints") != "false" {
h.NoTaints = true
}
}

func (h *Host) Validate() error {
Expand All @@ -71,6 +76,7 @@ func (h *Host) Validate() error {
validation.Field(&h.Role, validation.In("controller", "worker", "controller+worker", "single").Error("unknown role "+h.Role)),
validation.Field(&h.PrivateAddress, is.IP),
validation.Field(&h.Files),
validation.Field(&h.NoTaints, validation.When(h.Role != "controller+worker", validation.NotIn(true).Error("noTaints can only be true for controller+worker role"))),
)
}

Expand Down Expand Up @@ -233,6 +239,9 @@ func (h *Host) K0sInstallCommand() string {
case "controller+worker":
role = "controller"
flags.AddUnlessExist("--enable-worker")
if h.NoTaints {
flags.AddUnlessExist("--no-taints")
}
case "single":
role = "controller"
flags.AddUnlessExist("--single")
Expand Down

0 comments on commit 88b097a

Please sign in to comment.