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

Store: add ImageDirectory() and ImageRunDirectory() #1807

Merged
merged 1 commit into from Jan 24, 2024

Conversation

nalind
Copy link
Member

@nalind nalind commented Jan 23, 2024

Add ImageDirectory() and ImageRunDirectory(), which return the paths of directories which the caller can use to store image-specific data which will be cleaned up automatically when the image is removed or the system is restarted, respectively.

Add ImageDirectory() and ImageRunDirectory(), which return the paths of
directories which the caller can use to store image-specific data which
will be cleaned up automatically when the image is removed or the system
is restarted, respectively.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
@rhatdan
Copy link
Member

rhatdan commented Jan 23, 2024

/approve
LGTM
@giuseppe @saschagrunert @vrothberg @mtrmac PTAL

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

/lgtm

Copy link
Contributor

openshift-ci bot commented Jan 24, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, nalind, rhatdan

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:
  • OWNERS [giuseppe,nalind,rhatdan]

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

@openshift-merge-bot openshift-merge-bot bot merged commit a0eeb07 into containers:main Jan 24, 2024
18 checks passed
@nalind nalind deleted the image-directory branch January 24, 2024 14:38
Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

I know this was merged, please glance at the review anyway.

Comment on lines +3332 to +3336
middleDir := s.graphDriverName + "-images"
gipath := filepath.Join(s.GraphRoot(), middleDir, id, "userdata")
if err := os.MkdirAll(gipath, 0o700); err != nil {
return "", true, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I’d expect the responsibility for creating these directories to be in the same object that is responsible for deleting them — so I guess inside imageStore, and calling imageStore.datadir instead of hard-coding the structure.

(Applies to both.)

// ImageDirectory returns a path of a directory which the caller can
// use to store data, specific to the image, which the library does not
// directly manage. The directory will be deleted when the image is
// deleted.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In both cases, a small warning that the user is responsible for dealing with concurrency (including concurrency with image deletion, deleting the stored files in unpredictable order) might be valuable.

}

middleDir := s.graphDriverName + "-images"
rcpath := filepath.Join(s.RunRoot(), middleDir, id, "userdata")
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Yes the API documents that these directories are not explicitly deleted. A small comment here might help, e.g. for refactoring efforts which don’t naturally end up reading that API documentation.)

}); done {
return res, err
}
if foundImage {
Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAICS this is dead code; done is always set to true on the first iteration of readAllImageStores.

Also this code seems to read all image stores, but in fact only ever reads the first one and terminates; right now that loop could be dropped entirely.

(Applies to both.)

Comment on lines +3329 to +3331
if store.Exists(id) {
foundImage = true
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is surprising, is this right? Besides foundImage being dead, as noted elsewhere, the effect is that for images in an additional store, we create these data directories in the primary store which doesn’t store the image at all.

That might be right (assuming the additional stores are read-only and we simply can’t write them to additional stores — I don’t know what the use case is and whether we need to write this data to read-only images), but then we probably need some new image cleanup code to remove this data in the otherwise-unrelated store when the image is being deleted.

If that was not the intent, I’d expect this to look more like the image part of store.Metadata:

if res, done, err := readAllImageStores … {
    if store.Exists(id) {
        res, err :=return res, true, err
     }
     return N/A, false, nil
}; done {
   return res, err
}
return "", “not found

(Applies to both.)

Comment on lines +408 to +409
// directly manage. The directory will be deleted when the host system
// is restarted.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to commit to this behavior? Or should this allow the directory to be deleted as soon as the image is deleted, even if it isn’t currently implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants