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

make drain option configuable #725

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
5 changes: 4 additions & 1 deletion phase/reset_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (p *ResetControllers) Run() error {
Metadata: cluster.HostMetadata{
Hostname: h.Metadata.Hostname,
},
}); err != nil {
},
"120",
"5m",
); err != nil {
log.Warnf("%s: failed to drain node: %s", h, err.Error())
}
}
Expand Down
4 changes: 2 additions & 2 deletions phase/reset_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *ResetWorkers) Run() error {
Metadata: cluster.HostMetadata{
Hostname: h.Metadata.Hostname,
},
}); err != nil {
}, "120", "5m"); err != nil {
log.Warnf("%s: failed to drain node: %s", h, err.Error())
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func (p *ResetWorkers) Run() error {
log.Warnf("%s: failed to remove existing configuration %s: %s", h, h.Configurer.K0sConfigPath(), dErr)
}
log.Debugf("%s: removing config completed", h)

if len(h.Environment) > 0 {
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())
Expand Down
16 changes: 15 additions & 1 deletion phase/upgrade_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,21 @@ func (p *UpgradeWorkers) drainWorker(h *cluster.Host) error {
return nil
}
log.Debugf("%s: drain", h)
if err := p.leader.DrainNode(h); err != nil {
upgradeSettings := p.Config.Spec.UpgradeSettings
if upgradeSettings == nil {
upgradeSettings = &cluster.UpgradeSettings{}
}

gracePeriod := upgradeSettings.DrainGracePeriod
if gracePeriod == "" {
gracePeriod = "120"
}
timeout := upgradeSettings.DrainTimeout
if timeout == "" {
timeout = "5m"
}

if err := p.leader.DrainNode(h, gracePeriod, timeout); err != nil {
return fmt.Errorf("drain node: %w", err)
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ func (h *Host) K0sDataDir() string {
}

// DrainNode drains the given node
func (h *Host) DrainNode(node *Host) error {
return h.Exec(h.Configurer.KubectlCmdf(h, h.K0sDataDir(), "drain --grace-period=120 --force --timeout=5m --ignore-daemonsets --delete-emptydir-data %s", node.Metadata.Hostname), exec.Sudo(h))
func (h *Host) DrainNode(node *Host, gracePeriod string, timeout string) error {
return h.Exec(h.Configurer.KubectlCmdf(h, h.K0sDataDir(), "drain --grace-period=%s --force --timeout=%s --ignore-daemonsets --delete-emptydir-data %s", gracePeriod, timeout, node.Metadata.Hostname), exec.Sudo(h))
}

// CordonNode marks the node unschedulable
Expand Down
11 changes: 9 additions & 2 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ import (

// Spec defines cluster config spec section
type Spec struct {
Hosts Hosts `yaml:"hosts,omitempty"`
K0s *K0s `yaml:"k0s,omitempty"`
Hosts Hosts `yaml:"hosts,omitempty"`
K0s *K0s `yaml:"k0s,omitempty"`
UpgradeSettings *UpgradeSettings `yaml:"upgrade,omitempty"`

k0sLeader *Host
}

type UpgradeSettings struct {
DrainGracePeriod string `yaml:"drainGracePeriod,omitempty"`
DrainTimeout string `yaml:"drainTimeout,omitempty"`
}

// UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml
func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error {
type spec Spec
ys := (*spec)(s)
ys.K0s = &K0s{}
ys.UpgradeSettings = &UpgradeSettings{}

if err := unmarshal(ys); err != nil {
return err
Expand Down
Loading