Skip to content

Commit

Permalink
Add suggestions from code review
Browse files Browse the repository at this point in the history
 - only warn on misconfiguration
 - use `node.Annotations` not `node.GetAnnotations()`
 - explicitly check `annotate-node` value before reading an annotation

Signed-off-by: leonnicolas <[email protected]>
  • Loading branch information
leonnicolas committed Mar 1, 2024
1 parent 12e3818 commit 3fb674f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/kured/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const (
KuredRebootInProgressAnnotation string = "weave.works/kured-reboot-in-progress"
// KuredMostRecentRebootNeededAnnotation is the canonical string value for the kured most-recent-reboot-needed annotation
KuredMostRecentRebootNeededAnnotation string = "weave.works/kured-most-recent-reboot-needed"
// KuredMostRecentRebootNeededAnnotation is the canonical string value for the kured last-successful-reboot annotation
// KuredLastSuccessfulRebootAnnotation is the canonical string value for the kured last-successful-reboot annotation
KuredLastSuccessfulRebootAnnotation string = "weave.works/kured-last-successful-reboot"
// EnvPrefix The environment variable prefix of all environment variables bound to our command line flags.
EnvPrefix = "KURED"
Expand Down Expand Up @@ -272,7 +272,7 @@ func flagCheck(cmd *cobra.Command, args []string) {
log.Warnf("pre-reboot-node-labels keys and post-reboot-node-labels keys do not match. This may result in unexpected behaviour.")
}
if !annotateNodes && minRebootPeriod != 0 {
log.Fatal("Cannot use --min-reboot-period without --annotate-nodes")
log.Warn("Cannot use --min-reboot-period without --annotate-nodes. This will ignore the min-reboot-period value")
}
}

Expand Down Expand Up @@ -828,7 +828,10 @@ func lastSuccessfulRebootWithinMinRebootPeriod(node *v1.Node) bool {
if minRebootPeriod == 0 {
return false
}
if v, ok := node.GetAnnotations()[KuredLastSuccessfulRebootAnnotation]; ok {
if !annotateNodes {
return false
}
if v, ok := node.Annotations[KuredLastSuccessfulRebootAnnotation]; ok {
t, err := time.Parse(time.RFC3339, v)
if err != nil {
log.Warnf("failed to parse time %q in annotation %q: %s", v, KuredLastSuccessfulRebootAnnotation, err.Error())
Expand Down

0 comments on commit 3fb674f

Please sign in to comment.