Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expression filtering #73

Closed
squaremo opened this issue Jan 11, 2021 · 2 comments · Fixed by #75
Closed

Regular expression filtering #73

squaremo opened this issue Jan 11, 2021 · 2 comments · Fixed by #75
Assignees
Labels
enhancement New feature or request

Comments

@squaremo
Copy link
Member

squaremo commented Jan 11, 2021

Sometimes people want to partition their container image repo and use only a subset of the images. For example, by giving all the images destined for a dev environment a prefix dev-.

To give those people a way to filter for the desired subset of images, we can let them supply a regular expression in their ImagePolicy spec, and consider only the tags that match the regular expression.

They may also want to use only a portion of the tag for sorting, e.g., if the sort order is CalVer but there is a prefix, like dev-2021-01-11.build-1. Therefore it's useful to be able to sort using a particular capture group from the regular expression, or more generally, a replacement expression.

Why not globbing?

Globs are simpler to understand -- dev-* -- but suffer from a couple of problems:

  1. Libraries don't support captures, so the second requirement above would be tricky;
  2. They are not as general as regular expressions, e.g., it's not possible to filter for things that are CalVer-tagged.

If we implemented globs, we would very likely be asked to also implement regexp -- this is what happened for Flux v1. In the context of image tags, which don't have path separators (so no ** glob pattern), it is not difficult to construct a regular expression that's equivalent to a glob: dev-.* for dev-* and so on.

Place in the API

#58 (comment) and the comment following it #58 (comment) suggest that filtering is independent of the ordering. It can either appear in each policy:

spec:
  policy:
    semver:
      range: 1.x
      filterRegex: 'dev-v(.*)'
      sortOn: '\1'

or it can appear alongside the policy:

spec:
  filterRegex: 'dev-v(.*)'
  sortOn: '\1'
  policy:
    semver:
      range: 1.x

There's a sense in which the filtering takes place before the policy (e.g., extract the version portion of the tag before checking the semver range), so the latter feels closer to how people might think about it.

@squaremo
Copy link
Member Author

squaremo commented Jan 11, 2021

sortOn isn't quite right -- maybe (in whichever bit of structure):

filter:
  pattern: 'dev-(.*)'
  extract: '\1'

where .filter is optional; and, when filter is supplied,.extract is optional with the extracted value being the whole tag when it's missing.

@stefanprodan
Copy link
Member

+1 on extract

@squaremo squaremo added the enhancement New feature or request label Jan 11, 2021
@relu relu self-assigned this Jan 11, 2021
relu added a commit that referenced this issue Jan 11, 2021
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <[email protected]>
relu added a commit that referenced this issue Jan 11, 2021
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <[email protected]>
relu added a commit that referenced this issue Jan 11, 2021
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <[email protected]>
relu added a commit that referenced this issue Jan 13, 2021
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <[email protected]>
relu added a commit that referenced this issue Jan 13, 2021
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <[email protected]>
relu added a commit that referenced this issue Jan 13, 2021
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <[email protected]>
relu added a commit that referenced this issue Jan 13, 2021
Tag regex filtering allows the user to filter tags based on a regular
expression pattern and enables tag version extraction through capture
group replacement reference.

Fixes #73

Signed-off-by: Aurel Canciu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants