add support for kubernetes service discovery #262

Merged
lx merged 1 commits from audron/garage:feature/kubernetes_service_discovery into main 2022-03-14 09:47:36 +00:00
Contributor

This commit adds support to discover garage instances running in
kubernetes.

Once enabled by setting kubernetes_namespace and
kubernetes_service_name garage will create a Custom Resources
garagenodes.deuxfleurs.fr with nodes public key as the resource name.
and IP and Port information as spec in the namespace configured by
kubernetes_namespace.

For discovering nodes the resources are filtered with the optionally set
kubernetes_service_name which sets a label
garage.deuxfleurs.fr/service on the resources.

This allows to separate multiple garage deployments in a single
namespace.

the kubernetes_skip_crd variable allows to disable the creation of the
CRD by garage itself. The user must deploy this manually.

The new dependencies on kube and pnet i had to pin on an older version
because you are currently using rust 1.55 for building, which is too old
to support rust edition 2021, and these projects got bumped to edition
2021 in newer versions. They can be updated once the rust version was updated.

This commit adds support to discover garage instances running in kubernetes. Once enabled by setting `kubernetes_namespace` and `kubernetes_service_name` garage will create a Custom Resources `garagenodes.deuxfleurs.fr` with nodes public key as the resource name. and IP and Port information as spec in the namespace configured by `kubernetes_namespace`. For discovering nodes the resources are filtered with the optionally set `kubernetes_service_name` which sets a label `garage.deuxfleurs.fr/service` on the resources. This allows to separate multiple garage deployments in a single namespace. the `kubernetes_skip_crd` variable allows to disable the creation of the CRD by garage itself. The user must deploy this manually. The new dependencies on `kube` and `pnet` i had to pin on an older version because you are currently using rust 1.55 for building, which is too old to support rust edition 2021, and these projects got bumped to edition 2021 in newer versions. They can be updated once the rust version was updated.
lx requested changes 2022-03-07 10:24:47 +00:00
lx left a comment
Owner

Thanks for the great work! Remember to run cargo fmt to reformat your code according to standard style guidelines, and to check that cargo clippy does not return any warning. Will merge when this + the two little comments below are addressed.

Thanks for the great work! Remember to run `cargo fmt` to reformat your code according to standard style guidelines, and to check that `cargo clippy` does not return any warning. Will merge when this + the two little comments below are addressed.
@ -298,0 +326,4 @@
.ips
.first()
.unwrap()
.ip();
Owner

This should be put in a separate utility function to be also used in the function that advertises to Consul, it would be really helpful!

This should be put in a separate utility function to be also used in the function that advertises to Consul, it would be really helpful!
audron marked this conversation as resolved
@ -298,0 +328,4 @@
.unwrap()
.ip();
SocketAddr::new(default_ip, 3901)
Owner

The port isn't always 3901, it should be derived from the .port() of the RPC bind addr that is set in the configuration file.

The port isn't always 3901, it should be derived from the `.port()` of the RPC bind addr that is set in the configuration file.
audron marked this conversation as resolved
trinity-1686a reviewed 2022-03-07 15:07:46 +00:00
@ -33,0 +33,4 @@
# rust edition 2021
kube = { version = "0.62", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.13", features = ["v1_22"] }
schemars = "0.8"

could you add the following line please?

openssl = { version = "0.10", features = ["vendored"] }

Garage tries to be cross-compilation friendly, and by default kube seems to use system openssl, which poses problem. Adding this feature flag makes compilation a bit slower as it requires compiling openssl, but makes cross-compilation possible.

could you add the following line please? ```toml openssl = { version = "0.10", features = ["vendored"] } ``` Garage tries to be cross-compilation friendly, and by default kube seems to use system openssl, which poses problem. Adding this feature flag makes compilation a bit slower as it requires compiling openssl, but makes cross-compilation possible.
Author
Contributor

kube also has rustls support, but i couldn't make it work for whatever reason rn.
I added your suggestion.

kube also has rustls support, but i couldn't make it work for whatever reason rn. I added your suggestion.
audron marked this conversation as resolved
Owner

Fixes #241

Fixes #241
audron force-pushed feature/kubernetes_service_discovery from e8f9086fd1 to 2732ec5bb2 2022-03-12 11:35:30 +00:00 Compare
audron force-pushed feature/kubernetes_service_discovery from 2732ec5bb2 to 9c43679798 2022-03-12 11:38:42 +00:00 Compare
audron force-pushed feature/kubernetes_service_discovery from 9c43679798 to 0d619176c2 2022-03-12 11:46:34 +00:00 Compare
audron force-pushed feature/kubernetes_service_discovery from fd5f26a504 to 9d44127245 2022-03-12 12:06:28 +00:00 Compare
Owner

LGTM

LGTM
lx merged commit 9d44127245 into main 2022-03-14 09:47:35 +00:00
Sign in to join this conversation.
No description provided.