Skip to content

Commit 8f72830

Browse files
committed
fix: add fallback to CreationTimestamp in getJobCreationTimestamp
Signed-off-by: Kyori Sakao <[email protected]>
1 parent d74cf82 commit 8f72830

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

internal/job/createfinbackup/createfinbackup.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func (c *CreateFinBackup) Perform() error {
7070
}
7171

7272
// getJobCreationTimestamp retrieves the Job creation timestamp from the
73-
// batch.kubernetes.io/cronjob-scheduled-timestamp annotation
73+
// batch.kubernetes.io/cronjob-scheduled-timestamp annotation.
74+
// If the annotation is not found, it falls back to the Job's CreationTimestamp.
7475
func (c *CreateFinBackup) getJobCreationTimestamp(ctx context.Context) (time.Time, error) {
7576
job := &batchv1.Job{}
7677
if err := c.client.Get(ctx, types.NamespacedName{Namespace: c.jobNamespace, Name: c.jobName}, job); err != nil {
@@ -79,18 +80,13 @@ func (c *CreateFinBackup) getJobCreationTimestamp(ctx context.Context) (time.Tim
7980

8081
tsStr, ok := job.Annotations["batch.kubernetes.io/cronjob-scheduled-timestamp"]
8182
if !ok {
82-
return time.Time{}, fmt.Errorf(
83-
"job %s/%s missing annotation batch.kubernetes.io/cronjob-scheduled-timestamp",
84-
c.jobNamespace,
85-
c.jobName,
86-
)
83+
return job.CreationTimestamp.Time, nil
8784
}
8885

8986
jobCreatedAt, err := time.Parse(time.RFC3339, tsStr)
9087
if err != nil {
9188
return time.Time{}, fmt.Errorf("invalid batch.kubernetes.io/cronjob-scheduled-timestamp: %w", err)
9289
}
93-
9490
return jobCreatedAt, nil
9591
}
9692

0 commit comments

Comments
 (0)