@@ -11,17 +11,17 @@ import (
1111)
1212
1313// VersionSortMode defines the method to sort a list of tags
14- type VersionSortMode int
14+ type UpdateStrategy int
1515
1616const (
1717 // VersionSortSemVer sorts tags using semver sorting (the default)
18- VersionSortSemVer VersionSortMode = 0
18+ StrategySemVer UpdateStrategy = 0
1919 // VersionSortLatest sorts tags after their creation date
20- VersionSortLatest VersionSortMode = 1
20+ StrategyLatest UpdateStrategy = 1
2121 // VersionSortName sorts tags alphabetically by name
22- VersionSortName VersionSortMode = 2
22+ StrategyName UpdateStrategy = 2
2323 // VersionSortDigest uses latest digest of an image
24- VersionSortDigest VersionSortMode = 3
24+ StrategyDigest UpdateStrategy = 3
2525)
2626
2727// ConstraintMatchMode defines how the constraint should be matched
@@ -42,7 +42,7 @@ type VersionConstraint struct {
4242 MatchFunc MatchFuncFn
4343 MatchArgs interface {}
4444 IgnoreList []string
45- SortMode VersionSortMode
45+ Strategy UpdateStrategy
4646 Options * options.ManifestOptions
4747}
4848
@@ -61,14 +61,14 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
6161 logCtx .AddField ("image" , img .String ())
6262
6363 var availableTags tag.SortableImageTagList
64- switch vc .SortMode {
65- case VersionSortSemVer :
64+ switch vc .Strategy {
65+ case StrategySemVer :
6666 availableTags = tagList .SortBySemVer ()
67- case VersionSortName :
67+ case StrategyName :
6868 availableTags = tagList .SortByName ()
69- case VersionSortLatest :
69+ case StrategyLatest :
7070 availableTags = tagList .SortByDate ()
71- case VersionSortDigest :
71+ case StrategyDigest :
7272 availableTags = tagList .SortByName ()
7373 }
7474
@@ -82,7 +82,7 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
8282 // The given constraint MUST match a semver constraint
8383 var semverConstraint * semver.Constraints
8484 var err error
85- if vc .SortMode == VersionSortSemVer {
85+ if vc .Strategy == StrategySemVer {
8686 // TODO: Shall we really ensure a valid semver on the current tag?
8787 // This prevents updating from a non-semver tag currently.
8888 if img .ImageTag != nil && img .ImageTag .TagName != "" {
@@ -93,7 +93,7 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
9393 }
9494
9595 if vc .Constraint != "" {
96- if vc .SortMode == VersionSortSemVer {
96+ if vc .Strategy == StrategySemVer {
9797 semverConstraint , err = semver .NewConstraint (vc .Constraint )
9898 if err != nil {
9999 logCtx .Errorf ("invalid constraint '%s' given: '%v'" , vc , err )
@@ -107,7 +107,7 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
107107 for _ , tag := range availableTags {
108108 logCtx .Tracef ("Finding out whether to consider %s for being updateable" , tag .TagName )
109109
110- if vc .SortMode == VersionSortSemVer {
110+ if vc .Strategy == StrategySemVer {
111111 // Non-parseable tag does not mean error - just skip it
112112 ver , err := semver .NewVersion (tag .TagName )
113113 if err != nil {
@@ -123,7 +123,7 @@ func (img *ContainerImage) GetNewestVersionFromTags(vc *VersionConstraint, tagLi
123123 continue
124124 }
125125 }
126- } else if vc .SortMode == VersionSortDigest {
126+ } else if vc .Strategy == StrategyDigest {
127127 if tag .TagName != vc .Constraint {
128128 logCtx .Tracef ("%s did not match contraint %s" , tag .TagName , vc .Constraint )
129129 continue
@@ -156,20 +156,40 @@ func (vc *VersionConstraint) IsTagIgnored(tag string) bool {
156156 return false
157157}
158158
159- // IsCacheable returns true if we can safely cache tags for a given sort mode
160- func (vsm VersionSortMode ) IsCacheable () bool {
161- switch vsm {
162- case VersionSortDigest :
159+ // IsCacheable returns true if we can safely cache tags for strategy s
160+ func (s UpdateStrategy ) IsCacheable () bool {
161+ switch s {
162+ case StrategyDigest :
163163 return false
164164 default :
165165 return true
166166 }
167167}
168168
169- // NeedsMetadata returns true if v requires image metadata to work correctly
170- func (vsm VersionSortMode ) NeedsMetadata () bool {
171- switch vsm {
172- case VersionSortLatest :
169+ // NeedsMetadata returns true if strategy s requires image metadata to work correctly
170+ func (s UpdateStrategy ) NeedsMetadata () bool {
171+ switch s {
172+ case StrategyLatest :
173+ return true
174+ default :
175+ return false
176+ }
177+ }
178+
179+ // NeedsVersionConstraint returns true if strategy s requires a version constraint to be defined
180+ func (s UpdateStrategy ) NeedsVersionConstraint () bool {
181+ switch s {
182+ case StrategyDigest :
183+ return true
184+ default :
185+ return false
186+ }
187+ }
188+
189+ // WantsOnlyConstraintTag returns true if strategy s only wants to inspect the tag specified by the constraint
190+ func (s UpdateStrategy ) WantsOnlyConstraintTag () bool {
191+ switch s {
192+ case StrategyDigest :
173193 return true
174194 default :
175195 return false
0 commit comments