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

added fixed reboot time for single node #566

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 22 additions & 6 deletions cmd/kured/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ var (
postRebootNodeLabels []string
nodeID string

rebootDays []string
rebootStart string
rebootEnd string
timezone string
annotateNodes bool

rebootDays []string
rebootStart string
rebootEnd string
timezone string
annotateNodes bool
scheduleRebootTime string
scheduleRebootNode string
// Metrics
rebootRequiredGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Subsystem: "kured",
Expand Down Expand Up @@ -133,6 +134,8 @@ func NewRootCommand() *cobra.Command {
"delay reboot for this duration (default: 0, disabled)")
rootCmd.PersistentFlags().DurationVar(&period, "period", time.Minute*60,
"sentinel check period")
rootCmd.PersistentFlags().StringVar(&scheduleRebootTime, "schedule-reboot-time", "", "schedule reboot for this time")
rootCmd.PersistentFlags().StringVar(&scheduleRebootNode, "schedule-reboot-node", "", "schedule reboot for this node")
rootCmd.PersistentFlags().StringVar(&dsNamespace, "ds-namespace", "kube-system",
"namespace containing daemonset on which to place lock")
rootCmd.PersistentFlags().StringVar(&dsName, "ds-name", "kured",
Expand Down Expand Up @@ -680,6 +683,19 @@ func rebootAsRequired(nodeID string, rebootCommand []string, sentinelCommand []s
continue
}

rebootTime, _ := timewindow.ParseInputTime(stripQuotes(scheduleRebootTime))
timeDiff := time.Until(rebootTime)
if timeDiff < 0*time.Second {
timeDiff *= -1
}

if !rebootTime.IsZero() && scheduleRebootNode == os.Getenv("KURED_NODE_ID") && timeDiff <= period {
log.Printf("Reboot time for node: %s was scheduled at: %s\n", nodeID, stripQuotes(scheduleRebootTime))
log.Warnf("Sentinel command is about to be changed one single time on node: %s\n", nodeID)
sentinelCommand = buildHostCommand(1, []string{"test", "."})
time.Sleep(period + 1*time.Second)
}

if !rebootRequired(sentinelCommand) {
log.Infof("Reboot not required")
preferNoScheduleTaint.Disable()
Expand Down
12 changes: 12 additions & 0 deletions pkg/timewindow/timewindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ type TimeWindow struct {
endTime time.Time
}

func ParseInputTime(schedTime string) (t time.Time, err error) {
timeFormats := []string{"Jan-02-06 15:04:05", "Jan-02-06 15:04:05 GMT+1", "January 2, 2006 15:04:05", "January 2, 2006 15:04:05 GMT+1", "01/02/06 15:04:05", "01/02/06 15:04:05 GMT+1",
"01/02/06 15:04:05 MST", "January 2, 2006 15:04:05 MST", time.Layout, time.ANSIC, time.UnixDate, time.RubyDate, time.RFC822, time.RFC822Z, time.RFC850,
time.RFC1123, time.RFC1123Z, time.RFC3339, time.RFC3339Nano, time.Kitchen}
for _, value := range timeFormats {
if t, err = time.Parse(value, schedTime); err == nil {
return
}
}
return
}

// New creates a TimeWindow instance based on string inputs specifying a schedule.
func New(days []string, startTime, endTime, location string) (*TimeWindow, error) {
tw := &TimeWindow{}
Expand Down