Skip to content
This repository was archived by the owner on Sep 18, 2020. It is now read-only.

Commit 16fc7ff

Browse files
authored
Merge pull request #170 from RIAG-Digital/feature/rebootWindow
Feature/reboot window
2 parents d3bfdea + cda5e86 commit 16fc7ff

File tree

8 files changed

+497
-3
lines changed

8 files changed

+497
-3
lines changed

cmd/update-operator/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var (
1919
afterRebootAnnotations flagutil.StringSliceFlag
2020
kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig file. Default to the in-cluster config if not provided.")
2121
autoLabelContainerLinux = flag.Bool("auto-label-container-linux", false, "Auto-label Container Linux nodes with agent=true (convenience)")
22+
rebootWindowStart = flag.String("reboot-window-start", "", "Day of week ('Sun', 'Mon', ...; optional) and time of day at which the reboot window starts. E.g. 'Mon 14:00', '11:00'")
23+
rebootWindowLength = flag.String("reboot-window-length", "", "Length of the reboot window. E.g. '1h30m'")
2224
printVersion = flag.Bool("version", false, "Print version and exit")
2325
// deprecated
2426
analyticsEnabled optValue
@@ -70,6 +72,8 @@ func main() {
7072
AgentImageRepo: *agentImageRepo,
7173
BeforeRebootAnnotations: beforeRebootAnnotations,
7274
AfterRebootAnnotations: afterRebootAnnotations,
75+
RebootWindowStart: *rebootWindowStart,
76+
RebootWindowLength: *rebootWindowLength,
7377
})
7478
if err != nil {
7579
glog.Fatalf("Failed to initialize %s: %v", os.Args[0], err)

doc/reboot-windows.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Reboot windows
2+
The CLUO `update-operator` can be configured to only reboot nodes during certain timeframes.
3+
Pre-reboot checks are prevented from running as well.
4+
5+
## Configuring update-operator
6+
7+
The reboot window is configured through the the flags `--reboot-window-start`
8+
and `--reboot-window-length`, or through the environment variables
9+
`UPDATE_OPERATOR_REBOOT_WINDOW_START` and `UPDATE_OPERATOR_REBOOT_WINDOW_LENGTH`.
10+
11+
Here is an example configuration:
12+
13+
```
14+
/bin/update-operator \
15+
--reboot-window-start=14:00 \
16+
--reboot-window-length=1h
17+
```
18+
19+
This would configure `update-operator` to only reboot between 2pm and 3pm. Optionally,
20+
a day of week may be specified for the start of the window:
21+
22+
```
23+
/bin/update-operator \
24+
--reboot-window-start="Thu 23:00" \
25+
--reboot-window-length=1h30m
26+
```
27+
28+
This would configure `update-operator` to only reboot the system on Thursday after 11pm,
29+
or on Friday before 12:30am.
30+
31+
Currently, the only supported values for the day of week are short day names,
32+
e.g. `Sun`, `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, and `Sat`, but the day of week can
33+
be upper or lower case. The time of day must be specified in 24-hour time format.
34+
The window length is expressed as input to go's [time.ParseDuration][time.ParseDuration]
35+
function.
36+
37+
[time.ParseDuration]: http://godoc.org/time#ParseDuration

glide.lock

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import:
1010
version: v3
1111
subpackages:
1212
- flagutil
13+
- package: github.com/coreos/locksmith
14+
version: ef4279232ecdd23b7a3e3092747367b413da6e6b
15+
subpackages:
16+
- pkg/timeutil
1317
- package: github.com/davecgh/go-spew
1418
version: 782f4967f2dc4564575ca782fe2d04090b5faca8
1519
subpackages:

pkg/operator/operator.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/coreos/container-linux-update-operator/pkg/constants"
2323
"github.com/coreos/container-linux-update-operator/pkg/k8sutil"
24+
"github.com/coreos/locksmith/pkg/timeutil"
2425
)
2526

2627
const (
@@ -102,6 +103,9 @@ type Kontroller struct {
102103
// auto-label Container Linux nodes for migration compatability
103104
autoLabelContainerLinux bool
104105

106+
// reboot window
107+
rebootWindow *timeutil.Periodic
108+
105109
// Deprecated
106110
manageAgent bool
107111
agentImageRepo string
@@ -116,6 +120,9 @@ type Config struct {
116120
// annotations to look for before and after reboots
117121
BeforeRebootAnnotations []string
118122
AfterRebootAnnotations []string
123+
// reboot window
124+
RebootWindowStart string
125+
RebootWindowLength string
119126
// Deprecated
120127
ManageAgent bool
121128
AgentImageRepo string
@@ -159,6 +166,16 @@ func New(config Config) (*Kontroller, error) {
159166
return nil, fmt.Errorf("unable to determine operator namespace: please ensure POD_NAMESPACE environment variable is set")
160167
}
161168

169+
var rebootWindow *timeutil.Periodic
170+
if config.RebootWindowStart != "" && config.RebootWindowLength != "" {
171+
rw, err := timeutil.ParsePeriodic(config.RebootWindowStart, config.RebootWindowLength)
172+
if err != nil {
173+
return nil, fmt.Errorf("Error parsing reboot window: %s", err)
174+
}
175+
176+
rebootWindow = rw
177+
}
178+
162179
return &Kontroller{
163180
kc: kc,
164181
nc: nc,
@@ -171,6 +188,7 @@ func New(config Config) (*Kontroller, error) {
171188
autoLabelContainerLinux: config.AutoLabelContainerLinux,
172189
manageAgent: config.ManageAgent,
173190
agentImageRepo: config.AgentImageRepo,
191+
rebootWindow: rebootWindow,
174192
}, nil
175193
}
176194

@@ -424,7 +442,8 @@ func (k *Kontroller) checkAfterReboot() error {
424442
// before-reboot=true label. This is considered the beginning of the reboot
425443
// process from the perspective of the update-operator. It will only mark
426444
// nodes with this label up to the maximum number of concurrently rebootable
427-
// nodes as configured with the maxRebootingNodes constant.
445+
// nodes as configured with the maxRebootingNodes constant. It also checks if
446+
// we are inside the reboot window.
428447
// It cleans up the before-reboot annotations before it applies the label, in
429448
// case there are any left over from the last reboot.
430449
// If there is an error getting the list of nodes or updating any of them, an
@@ -435,6 +454,17 @@ func (k *Kontroller) markBeforeReboot() error {
435454
return fmt.Errorf("Failed listing nodes: %v", err)
436455
}
437456

457+
// check if a reboot window is configured
458+
if k.rebootWindow != nil {
459+
// get previous occurrence relative to now
460+
period := k.rebootWindow.Previous(time.Now())
461+
// check if we are inside the reboot window
462+
if !(period.End.After(time.Now())) {
463+
glog.V(4).Info("We are outside the reboot window; not labeling rebootable nodes for now")
464+
return nil
465+
}
466+
}
467+
438468
// find nodes which are still rebooting
439469
rebootingNodes := k8sutil.FilterNodesByAnnotation(nodelist.Items, stillRebootingSelector)
440470
// nodes running before and after reboot checks are still considered to be "rebooting" to us

vendor/github.com/coreos/locksmith/LICENSE

Lines changed: 202 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/coreos/locksmith/NOTICE

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)