mirror of
https://github.com/kubereboot/kured.git
synced 2026-08-23 21:36:33 +00:00
Replaced --annotationTTL with --lockTTL and made it work correctly
This commit is contained in:
+9
-11
@@ -33,6 +33,7 @@ var (
|
||||
dsNamespace string
|
||||
dsName string
|
||||
lockAnnotation string
|
||||
lockTTL time.Duration
|
||||
prometheusURL string
|
||||
alertFilter *regexp.Regexp
|
||||
rebootSentinel string
|
||||
@@ -46,8 +47,6 @@ var (
|
||||
rebootEnd string
|
||||
timezone string
|
||||
|
||||
annotationTTL time.Duration
|
||||
|
||||
// Metrics
|
||||
rebootRequiredGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Subsystem: "kured",
|
||||
@@ -74,6 +73,8 @@ func main() {
|
||||
"name of daemonset on which to place lock")
|
||||
rootCmd.PersistentFlags().StringVar(&lockAnnotation, "lock-annotation", "weave.works/kured-node-lock",
|
||||
"annotation in which to record locking node")
|
||||
rootCmd.PersistentFlags().DurationVar(&lockTTL, "lock-ttl", 0,
|
||||
"expire lock annotation after this duration (default: 0, disabled)")
|
||||
rootCmd.PersistentFlags().StringVar(&prometheusURL, "prometheus-url", "",
|
||||
"Prometheus instance to probe for active alerts")
|
||||
rootCmd.PersistentFlags().Var(®expValue{&alertFilter}, "alert-filter-regexp",
|
||||
@@ -100,9 +101,6 @@ func main() {
|
||||
rootCmd.PersistentFlags().StringVar(&timezone, "time-zone", "UTC",
|
||||
"use this timezone for schedule inputs")
|
||||
|
||||
rootCmd.PersistentFlags().DurationVar(&annotationTTL, "annotation-ttl", 0,
|
||||
"force clean annotation after this ammount of time (default 0, disabled)")
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -349,16 +347,16 @@ func root(cmd *cobra.Command, args []string) {
|
||||
|
||||
log.Infof("Node ID: %s", nodeID)
|
||||
log.Infof("Lock Annotation: %s/%s:%s", dsNamespace, dsName, lockAnnotation)
|
||||
if lockTTL > 0 {
|
||||
log.Infof("Lock TTL set, lock will expire after: %v", lockTTL)
|
||||
} else {
|
||||
log.Info("Lock TTL not set, lock will remain until being released")
|
||||
}
|
||||
log.Infof("Reboot Sentinel: %s every %v", rebootSentinel, period)
|
||||
log.Infof("Blocking Pod Selectors: %v", podSelectors)
|
||||
log.Infof("Reboot on: %v", window)
|
||||
if annotationTTL > 0 {
|
||||
log.Infof("Force annotation cleanup after: %v", annotationTTL)
|
||||
} else {
|
||||
log.Info("Force annotation cleanup disabled.")
|
||||
}
|
||||
|
||||
go rebootAsRequired(nodeID, window, annotationTTL)
|
||||
go rebootAsRequired(nodeID, window, lockTTL)
|
||||
go maintainRebootRequiredMetric(nodeID)
|
||||
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
@@ -44,11 +44,9 @@ func (dsl *DaemonSetLock) Acquire(metadata interface{}, TTL time.Duration) (acqu
|
||||
return false, "", err
|
||||
}
|
||||
|
||||
if ttlExpired(value.Created, value.TTL) {
|
||||
return true, value.NodeID, nil
|
||||
if !ttlExpired(value.Created, value.TTL) {
|
||||
return value.NodeID == dsl.nodeID, value.NodeID, nil
|
||||
}
|
||||
|
||||
return value.NodeID == dsl.nodeID, value.NodeID, nil
|
||||
}
|
||||
|
||||
if ds.ObjectMeta.Annotations == nil {
|
||||
@@ -88,11 +86,9 @@ func (dsl *DaemonSetLock) Test(metadata interface{}) (holding bool, err error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if ttlExpired(value.Created, value.TTL) {
|
||||
return true, nil
|
||||
if !ttlExpired(value.Created, value.TTL) {
|
||||
return value.NodeID == dsl.nodeID, nil
|
||||
}
|
||||
|
||||
return value.NodeID == dsl.nodeID, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
@@ -111,7 +107,8 @@ func (dsl *DaemonSetLock) Release() error {
|
||||
if err := json.Unmarshal([]byte(valueString), &value); err != nil {
|
||||
return err
|
||||
}
|
||||
if value.NodeID != dsl.nodeID && !ttlExpired(value.Created, value.TTL) {
|
||||
|
||||
if value.NodeID != dsl.nodeID {
|
||||
return fmt.Errorf("Not lock holder: %v", value.NodeID)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user