What is the problem you're trying to solve
|
// The value of `image.CreatedAt` passed from the caller is discarded here. |
|
// Ideally we should return an error when the value is already set. |
|
// However, as `image.CreatedAt` is defined as a non-pointer `time.Time`, we can't compare it to nil. |
|
// And we can't compare it to `time.Time{}` either, as `time.Time{}` is a proper timestamp (1970-01-01 00:00:00). |
|
if tm := epoch.FromContext(ctx); tm != nil { |
|
image.CreatedAt = tm.UTC() |
|
} else { |
|
image.CreatedAt = time.Now().UTC() |
|
} |
|
image.UpdatedAt = image.CreatedAt |
Currently, Create(ctx, img) does not consume img.CreatedAt value by design.
This issue can be currently worked around by ctx = epoch.WithSourceDateEpoch(ctx, customCreatedAt), but this should be possible without depending on ctx too.
Describe the solution you'd like
Consume the value of img.CreatedAt when it is explicitly set.
This change requires changing the type of CreatedAt form time.Time to *time.Time, or, add another property like CreatedAtIsSet, so as to differentiate "not set" from "1970-01-01 00:00:00".
Additional context
What is the problem you're trying to solve
containerd/metadata/images.go
Lines 148 to 157 in 831b9a9
Currently,
Create(ctx, img)does not consumeimg.CreatedAtvalue by design.This issue can be currently worked around by
ctx = epoch.WithSourceDateEpoch(ctx, customCreatedAt), but this should be possible without depending on ctx too.Describe the solution you'd like
Consume the value of
img.CreatedAtwhen it is explicitly set.This change requires changing the type of
CreatedAtformtime.Timeto*time.Time, or, add another property likeCreatedAtIsSet, so as to differentiate "not set" from "1970-01-01 00:00:00".Additional context
Image.CreatedAt#8225 (comment)