Skip to content

Commit

Permalink
Use current time for ctime/mtime-based CloudInit Conds
Browse files Browse the repository at this point in the history
The only reason the createAt or modifiedAt variables would be
zero seconds from the epoch is if the Stat call failed for an
expected and potentially normal reason (file does not exist)
or an unexpected reason (permission denied, etc).

In either case, the current timestamp is when we first noticed the Cond
change into such a state, so use the current timestamp regardless.

Signed-off-by: Connor Kuehl <[email protected]>
  • Loading branch information
Connor Kuehl authored and connorkuehl committed Apr 18, 2024
1 parent f90a398 commit d0d28e3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/controller/cloudinit/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const (
eventReasonReconcile = "CloudInitFileModified"
eventActionRemove = "RemoveFile"
eventReasonRemove = "CloudInitNotApplicable"

// This is mainly used for detecting a "zero value" for timestamps
// in a call to stat, where 0 means it has been 0 seconds since the
// unix epoch.
epoch int64 = 0
)

type controller struct {
Expand Down Expand Up @@ -176,6 +181,14 @@ func (c *controller) updateStatus(node *corev1.Node, cloudInitObj *cloudinitv1.C
}

now := time.Now()

if createdAt.Unix() == epoch {
createdAt = now
}
if modifiedAt.Unix() == epoch {
modifiedAt = now
}

for i := range conds {
cond := &conds[i]
prev := oldConds[cond.Type]
Expand Down

0 comments on commit d0d28e3

Please sign in to comment.