-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Image filtering and ordering with semver #1266
Conversation
54caaba
to
7091c03
Compare
Does this supports the Some examples:
|
@stefanprodan it does recognize versions with a |
7091c03
to
67ff574
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a thorough job with some nice refactorings and tidies 💯
I made some comments. Most just offer advice or invite an quick explanation or rebuttal; the only thing I think definitely needs a code change is the accidental change in meaning in policy_cmd.go
.
Gopkg.toml
Outdated
@@ -47,5 +47,5 @@ required = ["k8s.io/code-generator/cmd/client-gen"] | |||
version = "v1.0.0" | |||
|
|||
[[constraint]] | |||
branch = "master" |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
cmd/fluxctl/policy_cmd.go
Outdated
@@ -142,7 +142,7 @@ func calculatePolicyChanges(opts *controllerPolicyOpts) (policy.Update, error) { | |||
Add(policy.LockedUser) | |||
} | |||
if opts.tagAll != "" { | |||
add = add.Set(policy.TagAll, "glob:"+opts.tagAll) | |||
add = add.Set(policy.TagAll, policy.PatternAll.String()) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
policy/pattern_test.go
Outdated
name: "semver", | ||
pattern: "semver:~1", | ||
true: []string{"v1", "1", "1.2", "1.2.3"}, | ||
false: []string{"", "latest", "2.0.0", ""}, |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
name: "all", | ||
pattern: "semver:*", | ||
true: []string{"1", "1.0", "v1.0.3"}, | ||
false: []string{"", "latest", "2.0.1-alpha.1"}, |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
policy/policy.go
Outdated
if services == nil { | ||
return "*" | ||
return PatternAll | ||
} | ||
policies := services[service] |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
update/release.go
Outdated
@@ -231,7 +231,7 @@ func (s ReleaseSpec) calculateImageUpdates(rc ReleaseContext, candidates []*Cont | |||
for _, container := range containers { | |||
currentImageID := container.Image | |||
|
|||
filteredImages := imageRepos.GetRepoImages(currentImageID.Name).Filter("*") | |||
filteredImages := imageRepos.GetRepoImages(currentImageID.Name).Filter(policy.PatternAll) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
daemon/daemon.go
Outdated
return cs.controllers[i].ContainersOrNil() | ||
} | ||
|
||
func (cs clusterContainers) Pattern(i int, container string) policy.Pattern { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
daemon/daemon.go
Outdated
} | ||
|
||
policyResourceMap, _, err := d.getPolicyResourceMap(ctx) | ||
imageRepos, err := update.FetchImageRepos(d.Registry, clusterContainers{controllers: services, policies: policyResourceMap}, d.Logger) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
policy/pattern.go
Outdated
// String returns the prefixed string representation. | ||
String() string | ||
// ImageNewerFunc returns a function to compare image newness. | ||
ImageNewerFunc() image.LessFunc |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@@ -38,24 +38,30 @@ func (r ImageRepos) GetRepoImages(repo image.Name) ImageInfos { | |||
// ImageInfos is a list of image.Info which can be filtered. | |||
type ImageInfos []image.Info |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
440c710
to
3c7570f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great PR, thanks Roli. Nits/suggestions, but if this all compiles/passes/works in practice, I'm happy with it.
cmd/fluxctl/policy_cmd.go
Outdated
@@ -142,7 +142,7 @@ func calculatePolicyChanges(opts *controllerPolicyOpts) (policy.Update, error) { | |||
Add(policy.LockedUser) | |||
} | |||
if opts.tagAll != "" { | |||
add = add.Set(policy.TagAll, policy.PatternAll.String()) | |||
add = add.Set(policy.TagAll, policy.NewPattern(opts.tagAll).String()) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
policy/pattern_test.go
Outdated
false: []string{"", "latest", "2.0.0"}, | ||
}, | ||
{ | ||
name: "semver", |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
update/images.go
Outdated
} | ||
} | ||
filtered.Sort(pattern) | ||
return filtered | ||
} | ||
|
||
func (ii ImageInfos) Sort(pattern policy.Pattern) { | ||
image.Sort(ii, pattern.ImageNewerFunc()) | ||
image.Sort(ii, pattern.Newer) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
} | ||
return filtered | ||
// SortedImageInfos is a list of sorted image.Info | ||
type SortedImageInfos []image.Info |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Currently, containers can be tagged in manifests to filter what image tags are considered when doing automated releases. Filtering is done by specifying a wildcard glob. An optional prefix `glob:` can be used. This PR adds support for tag filters based on [semantic versioning][0] by using the prefix `semver:` instead. Version constraints can be specified that filter images. Since versions have an implicit ordering this also changes the way images are sorted when trying to determine the newest image. For glob filtering this falls back to image creation date. [0]: https://semver.org
3c7570f
to
4c8fabb
Compare
Currently, containers can be tagged in manifests to filter what image
tags are considered when doing automated releases. Filtering is done by
specifying a wildcard glob. An optional prefix
glob:
can be used.This PR adds support for tag filters based on semantic versioning
by using the prefix
semver:
instead. Version constraints can bespecified that filter images. Since versions have an implicit ordering
this also changes the way images are sorted when trying to determine the
newest image. For glob filtering this falls back to image creation date.
Closes #706