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

Commit 41d86ae

Browse files
committed
implement reboot window, using timeutil/periodic from locksmith
1 parent d3bfdea commit 41d86ae

File tree

7 files changed

+460
-3
lines changed

7 files changed

+460
-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)

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)