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 "auto" provisioning type. #120

Merged
merged 2 commits into from
Aug 19, 2024
Merged

Add "auto" provisioning type. #120

merged 2 commits into from
Aug 19, 2024

Conversation

jp39
Copy link

@jp39 jp39 commented Aug 2, 2024

Automatically use hostpath if pod is on same host as zfs pool.

This addresses #85. When storage class type is set to auto, automatically create a hostpath volume when the scheduler selects the specified node to run the pod, otherwise fallback to using NFS.

Note this only works when volumeBindingMode is set to WaitForFirstConsumer in the storage class. Otherwise, when set to Immediate, volumes will be pre-provisioned before the scheduler selects a node for the pod consuming the volume, and options.SelectedNode will be unset.

Note that there could be unintended side-effects if multiple pods using the volume claim are scheduled on different nodes, depending on which pods gets scheduled first. If the first pod gets scheduled on the ZFS host, it will automatically use a hostpath volume and node affinity will be set so that other pods will be prevented from running on other nodes. On the other hand, if the second pod gets scheduled on a node which is not the ZFS host, it will use a NFS volume, and subsequent pods will also use NFS, even if scheduled to run on the ZFS host.

Copy link
Owner

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

Hi!
Many thanks in your interest and investing time into this.
Overall implementation looks okay, though there are some smaller improvements.

I haven't tested it yet.

Please also have a look at the test files, in CI they are failing. There is also supposed to be some integration tests, maybe you can use this to verify the intended behavior.

If you don't mind, would you write some documentation in the README? If not, I could add it later on by myself while testing, just let me know.

pkg/provisioner/parameters.go Outdated Show resolved Hide resolved
pkg/provisioner/parameters.go Outdated Show resolved Hide resolved
pkg/provisioner/provision.go Outdated Show resolved Hide resolved
pkg/provisioner/provision.go Outdated Show resolved Hide resolved
pkg/provisioner/provision.go Outdated Show resolved Hide resolved
@ccremer
Copy link
Owner

ccremer commented Aug 2, 2024

Note that there could be unintended side-effects if multiple pods using the volume claim are scheduled on different nodes, depending on which pods gets scheduled first. If the first pod gets scheduled on the ZFS host, it will automatically use a hostpath volume and node affinity will be set so that other pods will be prevented from running on other nodes. On the other hand, if the second pod gets scheduled on a node which is not the ZFS host, it will use a NFS volume, and subsequent pods will also use NFS, even if scheduled to run on the ZFS host.

Hmm, I have some concerns regarding this side effect. It sounds like it'll become effectively much less deterministic regarding which type is used, especially if the first Pod lands on the ZFS host and prevents other Pods from running. This will lead to issues and questions eventually.

In that sense, I don't think naming this method auto is good enough, as people will likely not read its "fineprint" and just use auto without thinking or reading about its side effect.
If you have an idea how to control this side effect, I'm all ears. Otherwise, I'd rather prefer to name it preferHostPathOverNfs or something similar (better name welcome), just something that the user would then have to read the docs before choosing.

@ccremer
Copy link
Owner

ccremer commented Aug 3, 2024

Since I've merged #126 , you should probably rebase your PR.

@jp39 jp39 force-pushed the hostpath-auto branch 3 times, most recently from 9b0e209 to d70e9b7 Compare August 3, 2024 10:55
@jp39
Copy link
Author

jp39 commented Aug 3, 2024

Thanks for your review. I've addressed most of your comments, and I rebased the branch on top of the most recent master. I still need to complete the README file. Also I'm still looking for a good enough name to replace the "auto" type.

Copy link
Owner

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

Thanks for working on it!

Regarding the readme, if applicable I would refer to https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/#schedule-a-pod-using-preferred-node-affinity to better control the side effect

pkg/zfs/zfs.go Outdated Show resolved Hide resolved
@jp39
Copy link
Author

jp39 commented Aug 5, 2024

If you have an idea how to control this side effect, I'm all ears. Otherwise, I'd rather prefer to name it preferHostPathOverNfs or something similar (better name welcome), just something that the user would then have to read the docs before choosing.

My expertise in Kubernetes is actually still fairly limited. But after reading this https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes, it looks like pods running on multiple nodes accessing the same volume is not something that is commonly supported anyway.

I think it would be reasonable to force the NFS volume source to be used instead of HostPath, whenever the volume claim contains the ReadOnlyMany or ReadWriteMany access modes.

Then in this case, maybe it would actually make sense to call this mode "Auto".

What do you think?

@jp39 jp39 force-pushed the hostpath-auto branch 2 times, most recently from 2f4a71e to 825b946 Compare August 5, 2024 10:46
@ccremer
Copy link
Owner

ccremer commented Aug 9, 2024

You have a point regarding the access modes.
yeah, let's call it "auto", but document the behaviour in the Readme.

@jp39
Copy link
Author

jp39 commented Aug 9, 2024

Hi @ccremer, I've added a few words in the README file. Let me know if that suits you. Thanks.

Automatically use hostpath if pod is on same host as zfs pool.

This addresses ccremer#85. When storage class type is set to auto,
automatically create a hostpath volume when the scheduler selects the
specified node to run the pod, otherwise fallback to using NFS.

Note this only works when volumeBindingMode is set to
WaitForFirstConsumer in the storage class. Otherwise, when set to
Immediate, volumes will be pre-provisioned before the scheduler selects a
node for the pod consuming the volume, and options.SelectedNode will be
unset.
@jp39
Copy link
Author

jp39 commented Aug 12, 2024

I also fixed lint errors and failing tests. Thanks.

Copy link
Owner

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

Just a quick question, didn't do a full review yet. I hope I'll get to it soon.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@jp39
Copy link
Author

jp39 commented Aug 18, 2024

Hi, I've added the changes you suggested in a second commit so you can see more easily what's been changed here.

Copy link
Owner

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

Looking good so far, I like it!
Just some small corrections

pkg/provisioner/provision.go Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Force HostPath to be used preemptively instead of letting the scheduler
choose where to place the first pod.

Also add support for ReadWriteOncePod.
@ccremer ccremer merged commit 5884d5b into ccremer:master Aug 19, 2024
6 checks passed
@ccremer
Copy link
Owner

ccremer commented Aug 19, 2024

Thanks for your PR! Merged it

@jp39 jp39 deleted the hostpath-auto branch September 17, 2024 17:43
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