@@ -34,8 +34,7 @@ import (
3434const ociPrefix = "oci://"
3535
3636type taskRecord struct {
37- Ref string `json:"ref"`
38- EffectiveOn time.Time `json:"effective_on"`
37+ Ref string `json:"ref"`
3938 // ExpiresOn should be omitted if there isn't a value. Not using a pointer means it will always
4039 // have a value, e.g. 0001-01-01T00:00:00Z.
4140 ExpiresOn * time.Time `json:"expires_on,omitempty"`
@@ -111,14 +110,14 @@ func Track(ctx context.Context, urls []string, input []byte, prune bool, freshen
111110
112111 imageUrls , gitUrls := groupUrls (urls )
113112
114- days := oneDay * time . Duration ( inEffectDays )
115- effectiveOn := time . Now (). Add ( days ). UTC (). Round ( oneDay )
113+ // Note: inEffectDays parameter is kept for backward compatibility but no longer used
114+ // Records now use creation timestamps instead of future effective dates
116115
117- if err := t .trackImageReferences (ctx , imageUrls , freshen , effectiveOn ); err != nil {
116+ if err := t .trackImageReferences (ctx , imageUrls , freshen ); err != nil {
118117 return nil , err
119118 }
120119
121- if err := t .trackGitReferences (ctx , gitUrls , freshen , effectiveOn ); err != nil {
120+ if err := t .trackGitReferences (ctx , gitUrls , freshen ); err != nil {
122121 return nil , err
123122 }
124123
@@ -143,7 +142,7 @@ func groupUrls(urls []string) ([]string, []string) {
143142 return imgs , gits
144143}
145144
146- func (t * Tracker ) trackImageReferences (ctx context.Context , urls []string , freshen bool , effectiveOn time. Time ) error {
145+ func (t * Tracker ) trackImageReferences (ctx context.Context , urls []string , freshen bool ) error {
147146 refs , err := image .ParseAndResolveAll (ctx , urls , name .StrictValidation )
148147 if err != nil {
149148 return err
@@ -168,18 +167,17 @@ func (t *Tracker) trackImageReferences(ctx context.Context, urls []string, fresh
168167
169168 if hasTask {
170169 t .addTrustedTaskRecord (ociPrefix , taskRecord {
171- Ref : ref .Digest ,
172- Tag : ref .Tag ,
173- EffectiveOn : effectiveOn ,
174- Repository : ref .Repository ,
170+ Ref : ref .Digest ,
171+ Tag : ref .Tag ,
172+ Repository : ref .Repository ,
175173 })
176174 }
177175 }
178176
179177 return nil
180178}
181179
182- func (t * Tracker ) trackGitReferences (ctx context.Context , urls []string , freshen bool , effectiveOn time. Time ) error {
180+ func (t * Tracker ) trackGitReferences (ctx context.Context , urls []string , freshen bool ) error {
183181 if freshen {
184182 log .Debug ("Freshen is enabled" )
185183
@@ -224,9 +222,8 @@ func (t *Tracker) trackGitReferences(ctx context.Context, urls []string, freshen
224222 }
225223
226224 t .addTrustedTaskRecord ("" , taskRecord {
227- Repository : fmt .Sprintf ("%s//%s" , repository , path ),
228- Ref : rev ,
229- EffectiveOn : effectiveOn ,
225+ Repository : fmt .Sprintf ("%s//%s" , repository , path ),
226+ Ref : rev ,
230227 })
231228 }
232229
@@ -263,9 +260,7 @@ func (t *Tracker) filterBundles(prune bool) {
263260
264261// filterRecords reduces the list of records by removing superfluous entries.
265262// It removes records that have the same reference in a certain group. If prune is
266- // true, it skips any record that is no longer acceptable. Any record with an
267- // EffectiveOn date in the future, and the record with the most recent
268- // EffectiveOn date *not* in the future are considered acceptable.
263+ // true, it removes records that have already expired based on their expires_on date.
269264func filterRecords (records []taskRecord , prune bool ) []taskRecord {
270265 now := time .Now ().UTC ()
271266
@@ -290,17 +285,10 @@ func filterRecords(records []taskRecord, prune bool) []taskRecord {
290285
291286 var relevant []taskRecord
292287 if prune {
293- // skip tracks when records should start to be pruned.
294- skip := false
295288 for _ , r := range unique {
296- if skip {
297- continue
298- }
299- relevant = append (relevant , r )
300- if ! skip {
301- if now .After (r .EffectiveOn ) {
302- skip = true
303- }
289+ // Keep records that haven't expired yet, or records with no expiration date
290+ if r .ExpiresOn == nil || now .Before (* r .ExpiresOn ) {
291+ relevant = append (relevant , r )
304292 }
305293 }
306294 } else {
@@ -314,20 +302,23 @@ func filterRecords(records []taskRecord, prune bool) []taskRecord {
314302 return relevant
315303}
316304
317- // setExpiration sets the expires_on attribute on records. The expires_on value for record N is the
318- // effective_on value of the n-1 record. The first record on the list does not contain an expires_on
319- // value since there is no newer record that invalidates it in the future.
320- // TODO: Probably need to compute the expires_on value without requiring the "effective_on" value so
321- // we don't have to always require both values. But this may be required during some transition
322- // period.
305+ // setExpiration sets the expires_on attribute on records using a duration-based approach.
306+ // Each record expires after a configurable duration (e.g., 60 days) from when it's added.
307+ // The most recent record (index 0) gets no expiration date, making it the current active record.
323308func (t * Tracker ) setExpiration () {
309+ expirationDuration := 60 * oneDay // 60 days default, could be configurable
310+ now := time .Now ().UTC ().Round (oneDay ) // Round to day boundary like original effective_on logic
311+
324312 for _ , records := range t .TrustedTasks {
325- var expiration * time.Time
326313 for i := range records {
327- if expiration != nil {
328- records [i ].ExpiresOn = expiration
314+ if i == 0 {
315+ // Most recent record doesn't expire
316+ records [i ].ExpiresOn = nil
317+ } else {
318+ // Older records expire after the duration
319+ expiresOn := now .Add (expirationDuration )
320+ records [i ].ExpiresOn = & expiresOn
329321 }
330- expiration = & records [i ].EffectiveOn
331322 }
332323 }
333324}
0 commit comments