hetznercloud / hcloud-cloud-controller-manager

Kubernetes cloud-controller-manager for Hetzner Cloud
Apache License 2.0
740 stars 118 forks source link

feat(service): Specify private ip for loadbalancer #724

Closed lhp-nemlig closed 2 months ago

lhp-nemlig commented 3 months ago

Allows users to specify the IPv4 of the load balancer in the private network via the annotation "load-balancer.hetzner.cloud/private-ipv4"

Removes network logic from main load balancer creation, since the API does not support specifying the IP address there, and moves network logic to exclusively happen in AttachToNetwork and DetachFromNetwork.

I also added an extra LoadBalancer refresh in the main reconciliation loop, since changing the IP address of an SVC object causes network detach and subsequent attach, which in turn needs to cause the targets to be re-added to loadbalancer if they were private network targets.

Unit tests pass and i have tested this in a few scenarios on a cluster of my own.

apricote commented 2 months ago

Just to make sure we are on the same page:

Instead of assigning a random/next IP to the Load Balancer in the private Network, you want to explicitly set the IP that the Load Balancer should have (through an annotation).

Did I understand you correctly?

lhp-nemlig commented 2 months ago

Yes that is correct, and this PR accomplishes that.

If explicitly setting an IP was not possible, reserving a set of IP's for VM's would be impossible as the load balancers could randomly make use of them.

apricote commented 2 months ago

E2E tests are successful.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 85.71429% with 4 lines in your changes missing coverage. Please review.

Project coverage is 71.81%. Comparing base (8d29153) to head (17a1f0c). Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
hcloud/load_balancers.go 66.66% 1 Missing and 1 partial :warning:
internal/hcops/load_balancer.go 90.90% 1 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #724 +/- ## ========================================== - Coverage 72.11% 71.81% -0.30% ========================================== Files 31 30 -1 Lines 2639 2473 -166 ========================================== - Hits 1903 1776 -127 + Misses 550 524 -26 + Partials 186 173 -13 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.