Skip to content

Commit f41d0d4

Browse files
committed
make drain option configuable
1 parent 5de84fb commit f41d0d4

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

phase/reset_controllers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ func (p *ResetControllers) Run() error {
5757
Metadata: cluster.HostMetadata{
5858
Hostname: h.Metadata.Hostname,
5959
},
60-
}); err != nil {
60+
},
61+
"120",
62+
"5m",
63+
); err != nil {
6164
log.Warnf("%s: failed to drain node: %s", h, err.Error())
6265
}
6366
}

phase/reset_workers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (p *ResetWorkers) Run() error {
5656
Metadata: cluster.HostMetadata{
5757
Hostname: h.Metadata.Hostname,
5858
},
59-
}); err != nil {
59+
}, "120", "5m"); err != nil {
6060
log.Warnf("%s: failed to drain node: %s", h, err.Error())
6161
}
6262
}
@@ -99,7 +99,7 @@ func (p *ResetWorkers) Run() error {
9999
log.Warnf("%s: failed to remove existing configuration %s: %s", h, h.Configurer.K0sConfigPath(), dErr)
100100
}
101101
log.Debugf("%s: removing config completed", h)
102-
102+
103103
if len(h.Environment) > 0 {
104104
if err := h.Configurer.CleanupServiceEnvironment(h, h.K0sServiceName()); err != nil {
105105
log.Warnf("%s: failed to clean up service environment: %s", h, err.Error())

phase/upgrade_workers.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,21 @@ func (p *UpgradeWorkers) drainWorker(h *cluster.Host) error {
136136
return nil
137137
}
138138
log.Debugf("%s: drain", h)
139-
if err := p.leader.DrainNode(h); err != nil {
139+
upgradeSettings := p.Config.Spec.UpgradeSettings
140+
if upgradeSettings == nil {
141+
upgradeSettings = &cluster.UpgradeSettings{}
142+
}
143+
144+
gracePeriod := upgradeSettings.DrainGracePeriod
145+
if gracePeriod == "" {
146+
gracePeriod = "30"
147+
}
148+
timeout := upgradeSettings.DrainTimeout
149+
if timeout == "" {
150+
timeout = "5m"
151+
}
152+
153+
if err := p.leader.DrainNode(h, gracePeriod, timeout); err != nil {
140154
return fmt.Errorf("drain node: %w", err)
141155
}
142156
return nil

pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ func (h *Host) K0sDataDir() string {
417417
}
418418

419419
// DrainNode drains the given node
420-
func (h *Host) DrainNode(node *Host) error {
421-
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))
420+
func (h *Host) DrainNode(node *Host, gracePeriod string, timeout string) error {
421+
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))
422422
}
423423

424424
// CordonNode marks the node unschedulable

pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/spec.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ import (
99

1010
// Spec defines cluster config spec section
1111
type Spec struct {
12-
Hosts Hosts `yaml:"hosts,omitempty"`
13-
K0s *K0s `yaml:"k0s,omitempty"`
12+
Hosts Hosts `yaml:"hosts,omitempty"`
13+
K0s *K0s `yaml:"k0s,omitempty"`
14+
UpgradeSettings *UpgradeSettings `yaml:"upgrade,omitempty"`
1415

1516
k0sLeader *Host
1617
}
1718

19+
type UpgradeSettings struct {
20+
DrainGracePeriod string `yaml:"drainGracePeriod,omitempty"`
21+
DrainTimeout string `yaml:"drainTimeout,omitempty"`
22+
}
23+
1824
// UnmarshalYAML sets in some sane defaults when unmarshaling the data from yaml
1925
func (s *Spec) UnmarshalYAML(unmarshal func(interface{}) error) error {
2026
type spec Spec
2127
ys := (*spec)(s)
2228
ys.K0s = &K0s{}
29+
ys.UpgradeSettings = &UpgradeSettings{}
2330

2431
if err := unmarshal(ys); err != nil {
2532
return err

0 commit comments

Comments
 (0)