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

Add aws-s3-csi-mounter component #291

Merged
merged 8 commits into from
Nov 22, 2024
Merged

Add aws-s3-csi-mounter component #291

merged 8 commits into from
Nov 22, 2024

Conversation

unexge
Copy link
Contributor

@unexge unexge commented Nov 11, 2024

This is part of #279.

This new component, aws-s3-csi-mounter, will be the entry point for the container running Mountpoint. It will be responsible for receiving mount options and FUSE file descriptor and spawning Mountpoint process until completion.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -0,0 +1,25 @@
// Package assert provides utilities for making assertions during tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any widely accepted testing repository that has assert equal/not equals we can use instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/stretchr/testify is the most common one as far as I know. I think some part of Go community discourages assert libraries. I'm not against it – I just didn't wanted to pull a big package for simple assertions. We also depend on https://github.com/onsi/gomega in our integration tests as it's used in Kubernetes testing framework.

I think I can create an issue to standardizing all assertions to one package in the codebase.

)

var mountSockPath = flag.String("mount-sock-path", "/sock/mount.sock", "Path of the Unix socket to receive mount options from.")
var mountSockRecvTimeout = flag.Duration("mount-sock-recv-timeout", 2*time.Minute, "Timeout for receiving mount options from passed Unix socket.")
Copy link
Contributor

Choose a reason for hiding this comment

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

2 minutes is a long time. Why this number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kinda arbitrary. This is the time this component will wait until the CSI Driver Node Pod sends mount options to it. I didn't wanted to make it short and cause retry loop. I don't expect it to wait until the whole timeout duration unless we have a bug in one of our components.


// parseUnixRights parses given socket control message to extract passed file descriptors.
func parseUnixRights(buf []byte) ([]int, error) {
socketControlMessages, err := syscall.ParseSocketControlMessage(buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what this is meant to do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as the comment suggests "... parses given socket control message to extract passed file descriptors.". Maybe I can add references to "Ancillary messages" and "SCM_RIGHTS" from https://man7.org/linux/man-pages/man7/unix.7.html.


// Recv receives passed mount options via `Send` function through given `sockPath`.
func Recv(ctx context.Context, sockPath string) (Options, error) {
l, err := net.Listen("unix", sockPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

I've not looked through the protocol for this - is it documented anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean the first parameter to net.Listen? If so, see https://pkg.go.dev/net#Listen

Copy link
Contributor

Choose a reason for hiding this comment

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

I was more meaning the protocol for send/receive, but I can now see it's just json serialising some structure, which seems fine


// WaitForUnixSocket waits for the duration of `timeout` until `path` exists by checking it every `interval`.
// It returns `ErrUnixSocketNotExists` if the socket won't appear within the timeout, otherwise it returns nil.
func WaitForUnixSocket(timeout time.Duration, interval time.Duration, path string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Would it be more efficient to use something like https://github.com/fsnotify/fsnotify to receive a notification from the OS that the file exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would, but since this is not in the data path, and we don't need low-latency, I think it would complicate this function as well. Do you think we need it?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair, no need for it now and we can think about it later if we discover it's something we want

Copy link
Contributor

@muddyfish muddyfish left a comment

Choose a reason for hiding this comment

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

Looks good to me, only thoughts are that we might want to check for the -f flag as well as the --foreground one

// By default Mountpoint runs in a detached mode. Here we want to monitor it by relaying its output,
// and also we want to wait until it terminates. We're passing `--foreground` to achieve this.
const foreground = "--foreground"
if !slices.Contains(args, foreground) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also check for the presence of -f here as well


// Recv receives passed mount options via `Send` function through given `sockPath`.
func Recv(ctx context.Context, sockPath string) (Options, error) {
l, err := net.Listen("unix", sockPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was more meaning the protocol for send/receive, but I can now see it's just json serialising some structure, which seems fine


// WaitForUnixSocket waits for the duration of `timeout` until `path` exists by checking it every `interval`.
// It returns `ErrUnixSocketNotExists` if the socket won't appear within the timeout, otherwise it returns nil.
func WaitForUnixSocket(timeout time.Duration, interval time.Duration, path string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair, no need for it now and we can think about it later if we discover it's something we want

@unexge unexge merged commit 51a758d into main Nov 22, 2024
17 checks passed
@unexge unexge deleted the unexge/podmounter branch November 22, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants