Skip to content

🌱 consolidate image layer handling; move fs utils #1690

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

Merged

Conversation

joelanford
Copy link
Member

@joelanford joelanford commented Feb 2, 2025

Description

Now that we have a monorepo, we can begin consolidating various bits of code that had identical or substantially similar implementations in catalogd and operator-controller.

This PR adds an image utility package, for now with common code that handles applying an image to an unpack directory. Of note is that catalogd and operator-controller had separate sets of filters used when applying the image layers. This PR, extracts the separate filter functions into the image utility library, and then updates the (still mostly duplicate) unpacker implementations to use the new shared code.

In follow-up PRs, we can further de-dup the containers/image unpacker implementations (and any other duplicate code we find).

NOTE: To avoid an import cycle, I needed to also make a new fs utility package for internal/rukpak/source/helpers.go (which are all fs-related helpers). I also took the opportunity to move internal/fsutil/* into the new fs` utility package.

Fixes #1711

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@joelanford joelanford requested a review from a team as a code owner February 2, 2025 20:09
Copy link

netlify bot commented Feb 2, 2025

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit 557c03f
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/67a3cfac7628ed0008df262e
😎 Deploy Preview https://deploy-preview-1690--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

Attention: Patch coverage is 61.45833% with 37 lines in your changes missing coverage. Please review.

Project coverage is 67.58%. Comparing base (46cec30) to head (557c03f).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
internal/util/image/layers.go 57.35% 24 Missing and 5 partials ⚠️
catalogd/internal/source/containers_image.go 54.54% 3 Missing and 2 partials ⚠️
internal/rukpak/source/containers_image.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1690      +/-   ##
==========================================
+ Coverage   67.47%   67.58%   +0.10%     
==========================================
  Files          59       59              
  Lines        5003     4982      -21     
==========================================
- Hits         3376     3367       -9     
+ Misses       1380     1371       -9     
+ Partials      247      244       -3     
Flag Coverage Δ
e2e 53.08% <41.17%> (-0.30%) ⬇️
unit 54.77% <33.33%> (-0.49%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

OwnerWritableDirMode os.FileMode = 0700
OwnerReadOnlyFileMode os.FileMode = 0400
OwnerReadOnlyDirMode os.FileMode = 0500
ownerWritableFileMode os.FileMode = 0700
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should export these and use them in the image utils. Maybe we could even add a comment here to explain why we don't give group perms.

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't see any usage outside of this package, so opted to unexport them. If there's a strong use case that comes up later, we can always export them again. This is all internal, so it doesn't matter either way from a public API standpoint, but it can be nice to keep even internal packages nice and tidy to avoid leaky abstractions.

@perdasilva
Copy link
Contributor

I'm wondering if we should call

if err := i.deleteOtherImages(bundle.Name, canonicalRef.Digest()); err != nil {
		return nil, fmt.Errorf("error deleting old images: %w", err)
}

On every successful run of unpack. E.g. always ensure that the other images previously unpacked are gone, and we don't have some garbage hanging around because the process got killed mid deletion (though I guess the cache clear at pod restart should handle that...)

@joelanford
Copy link
Member Author

/hold

There's a problem we discovered with EnsureEmptyDirectory, when it tries to delete directories with read-only bits set. Need to fix that first, then rebase this.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 3, 2025
@joelanford joelanford marked this pull request as draft February 3, 2025 13:30
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 3, 2025
@joelanford joelanford force-pushed the consolidate-layer-handling branch 3 times, most recently from 257d9d4 to 29dfafc Compare February 4, 2025 06:13
@joelanford joelanford marked this pull request as ready for review February 4, 2025 06:14
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 4, 2025
@joelanford joelanford removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 4, 2025
fsutil "github.com/operator-framework/operator-controller/internal/util/fs"
)

func ForceOwnershipRWX() archive.Filter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we doc the funcs ?

Copy link
Member

Choose a reason for hiding this comment

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

+1 we should add go docs for these functions.

@joelanford
Copy link
Member Author

On every successful run of unpack. E.g. always ensure that the other images previously unpacked are gone, and we don't have some garbage hanging around because the process got killed mid deletion

You're thinking to move it up right after we determine the canonical ref, but before we check to see if we already have the canonical ref cached? I think that makes sense to me. Right now this is only called in the case that we actually pull a new image, but not when we return an existing one.

(though I guess the cache clear at pod restart should handle that...)

Yes, but it's better to keep packages self-contained and avoid relying on hidden side-effects like that. I feel like that is one of OLMv0's downfalls.

return fmt.Errorf("error making unpack directory read-only: %w", err)
}
return nil
}
Copy link
Contributor

@azych azych Feb 5, 2025

Choose a reason for hiding this comment

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

to me all of those wrapper functions above are very specific to the logic required in source and it might be a good idea to defer placing them in an external dedicated util/ package until there is a need to share them, so imho for now it would be better to have them close to where they're being used

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm, my bad - I noticed they are actually shared between op-con and catalogd ;)

Copy link
Contributor

@azych azych left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 5, 2025
@@ -66,6 +66,8 @@ linters-settings:
alias: ctrl
- pkg: github.com/blang/semver/v4
alias: bsemver
- pkg: "^github.com/operator-framework/operator-controller/internal/util/([^/]+)$"
alias: "${1}util"
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

It is a good way to enforce import aliasing

} else if errors.Is(err, fsutil.ErrNotDirectory) {
if err := fsutil.DeleteReadOnlyRecursive(unpackPath); err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a new code i.e. we are deleting the file if it is not a directory, is that right?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was originally in IsDirectoryPresent, but and I both @perdasilva thought that was a terrible idea given the name and location of that helper function. So I renamed that function to GetDirectoryModTime and moved the delete call to the caller side.

@joelanford
Copy link
Member Author

I'm going to hold off on moving deleteOtherImages. I'm thinking about this scenario:

  1. I'm using image foobar:v1. It's unpacked and working great
  2. I decide I want foobar:v2, so I update my image ref.
  3. Oops, for some reason I can't pull that image (typo, auth problem, etc.)
  4. Set my ref back to foobar:v1. Phew still unpacked so I don't have to pull it again.

@joelanford joelanford force-pushed the consolidate-layer-handling branch from 29dfafc to 557c03f Compare February 5, 2025 20:52
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 5, 2025
Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

It seems good for me 👍

@camilamacedo86
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Feb 5, 2025
@joelanford joelanford added this pull request to the merge queue Feb 5, 2025
Merged via the queue into operator-framework:main with commit bf13d14 Feb 6, 2025
21 of 22 checks passed
@joelanford joelanford deleted the consolidate-layer-handling branch February 14, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consolidate image layer handling; move fs utils
5 participants