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

Use strongly encapsulated types with strict semantics for RemoveImage #7375

Merged
merged 7 commits into from
Oct 13, 2023

Conversation

mtrmac
Copy link
Contributor

@mtrmac mtrmac commented Oct 12, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Split ImageServer.ResolveNames into two well-typed parsers

We will push the heuristics to the callers to make the heuristics explicit, very loud to readers, and most importantly to give callers well-typed data instead of ambiguous strings.

This introduces storage.StorageImageID and storage.RegistryImageReference types, with the intent that users dealing with internal/storage should only use these strongly-typed values, not strings, for image identification/referencing.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

See individual commit messages for details. Overall, this should not actually change behavior of RemoveImage.

This is the beginning of the payoff of the recent API/semantics PRs. I have two similar directly related items queued to follow:

  • Migrate ImageServer.ImageStatus to accept well-typed input (StorageImageID or RegistryImageReference)
  • Migrate PrepareImage/PullImage to accept RegistryImageReference

and that will eliminate (or push to callers) all the heuristic “does it parse this way, that way, another way?” code paths in internal/storage, allowing the pull code to precisely reason about the names and to manipulate them with confidence.

This PR is filed separately (leaving the rules-violating ResolveNames in place) to get the review of the API types and general approach quickly, to surface concerns, if any, earlier.

Cc: @saschagrunert

Does this PR introduce a user-facing change?

None

@mtrmac mtrmac requested a review from mrunalp as a code owner October 12, 2023 20:49
@openshift-ci openshift-ci bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Oct 12, 2023
For now, there are no users; that will change immediately.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
We will push the heuristics to the callers to make the heuristics
explicit, very loud to readers, and most importantly to give callers
well-typed data instead of ambiguous strings.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Stop using ResolveNames, push the heuristic to the caller.

This violates future API rules, that will be fixed momentarily.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
... to use a well-typed value, _and_ to more strictly
differentiate between the "delete" and "untag" behaviors.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
It counts the tags which we are _not_ going to remove.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
... then simplify the code to remove unreachable paths,
simplify tests to remove unreachable error cases.

All the code and test removals are enabled by having strong
guarantees about the nature of the accepted input.

This removes a suspicious "HasPrefix" ambiguity between image
IDs and names; due to the restrictions of what strings
ResolveNames actually accepts, the problematic case was not
actually reachable.

So, this should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #7375 (2fd4073) into main (f54ac5f) will increase coverage by 0.10%.
The diff coverage is 89.77%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7375      +/-   ##
==========================================
+ Coverage   49.23%   49.33%   +0.10%     
==========================================
  Files         136      138       +2     
  Lines       15678    15739      +61     
==========================================
+ Hits         7719     7765      +46     
- Misses       7039     7051      +12     
- Partials      920      923       +3     

@mtrmac
Copy link
Contributor Author

mtrmac commented Oct 13, 2023

/retest

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines +39 to +41
// Actually Kubelet is only ever calling this with full image IDs.
// So we don't really need to accept ID prefixes nor short names;
// or is there another user?!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cri-tools does an ImageStatus before removing the specified image, which leads into a ResolveNames call. So I guess we're fine.

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 13, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mtrmac, saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 13, 2023
@openshift-ci openshift-ci bot merged commit bca7024 into cri-o:main Oct 13, 2023
63 of 64 checks passed
@mtrmac mtrmac deleted the storage-strict-types branch October 13, 2023 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants