Skip to content

feat: add hetzner cloud provider - #167

Open
Thunderbottom wants to merge 7 commits into
hashicorp:masterfrom
Thunderbottom:hcloud-provider
Open

feat: add hetzner cloud provider#167
Thunderbottom wants to merge 7 commits into
hashicorp:masterfrom
Thunderbottom:hcloud-provider

Conversation

@Thunderbottom

Copy link
Copy Markdown

adds a provider for hetzner cloud that does:

  • filter instances by label selector and datacenter location
  • fetch public/private IP address based on provided address type
  • checks for associated floating IPs in case of blocked public/private IP addresses
  • accepts API token as environment variable: HCLOUD_TOKEN

Enhancement over: #159
Closes: #73

@hashicorp-cla

hashicorp-cla commented Feb 15, 2021

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread provider/hcloud/hcloud_discover.go Outdated
Comment thread provider/hcloud/hcloud_discover.go Outdated
Comment thread provider/hcloud/hcloud_discover_test.go

@VoyTechnology VoyTechnology left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

@svenstaro

Copy link
Copy Markdown

Could we get this merged?

@laukaichung

laukaichung commented Apr 6, 2021

Copy link
Copy Markdown

While waiting for it to be merged, is there any way for now to automatically get a list of private IPs for the retry_join field without hardcoding a list of IPs? I'm planning to run a consul cluster on Hetzner Cloud with private network. It seems that GetPrivateIPs from go-sockaddr, e,g retry_join={{ GetPrivateIPs }} would work but I''m not sure how to use it in the config.

@dnephin

dnephin commented Apr 6, 2021

Copy link
Copy Markdown
Contributor

I don't think there is any support for that yet, but hashicorp/consul#9100 is a proposal that should make it possible.

@vitamindit

Copy link
Copy Markdown

While waiting for it to be merged, is there any way for now to automatically get a list of private IPs for the retry_join field without hardcoding a list of IPs? ...

I'm waiting for it too :) ... here is my approach:

You get private IP addresses once the server is assigned to a network or subnet.

Then you should use e.g. the hcloud server-info API. This will return the available servers including their private IP addresses for available interfaces.

From this server-info response you can then construct the list of desired private cluster IP addresses.

@KevinGimbel

Copy link
Copy Markdown

What's blocking this PR from being merged? I'm currently evaluating Consul for work and I'd love to use/try the auto-discovery feature as part of this PoC.

@gardion

gardion commented Jun 17, 2021

Copy link
Copy Markdown

Please merge, it would massively help adopting Consul for our platform.

@tomschlenkhoff

Copy link
Copy Markdown

Any help needed? Any blockers left? If not please (with sugar on top) merge, would be a boost for Consul/Hetzner adoption in Germany/EU.

@Thunderbottom

Copy link
Copy Markdown
Author

I believe there's no blockers, although the repo hasn't been updated since last year. So I'm not sure if it'll be merged any time soon.

ronaldburns added a commit to HBGames/go-discover that referenced this pull request Feb 27, 2022
commit 7623bb6
Author: Chinmay D. Pai <chinmaydpai@gmail.com>
Date:   Tue Feb 16 03:56:04 2021 +0530

    doc: add documentation for hcloud

    Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>

commit 297a1f5
Author: Chinmay D. Pai <chinmaydpai@gmail.com>
Date:   Tue Feb 16 03:54:08 2021 +0530

    ci: add tests for hcloud provider

    * add terraform files for hcloud server setup
    * add tests for public IPv4, IPv6, and private IPv4
    * add test to check for location filter
    * add circleci entry for hcloud provider

    Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>

commit 49c8fb3
Author: Chinmay D. Pai <chinmaydpai@gmail.com>
Date:   Tue Feb 16 03:51:44 2021 +0530

    feat: add hcloud to providers map and update go modules

    * adds hcloud provider to providers map
    * adds go module entry for hcloud, updates go mod sum

    Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>

commit 0ea43fc
Author: Chinmay D. Pai <chinmaydpai@gmail.com>
Date:   Tue Feb 16 03:43:18 2021 +0530

    feat: add hetzner cloud (hcloud) provider

    adds a provider for hetzner cloud that does:

    * filter instances by label selector and datacenter location
    * fetch public/private IP address based on provided address type
    * checks for associated floating IPs in case of blocked public/private IP addresses
    * accepts API token as environment variable: HCLOUD_TOKEN

    Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
Comment thread provider/hcloud/hcloud_discover.go Outdated
@ronaldburns

ronaldburns commented Feb 27, 2022

Copy link
Copy Markdown

This is a feature we need for our infrastructure. It doesn't appear like it's going to be committed anytime soon.
We've forked this and made a fix or two.

go-discover
consul

If you'd like to immediately use this implementation, binaries have been added for the latest releases.

Consul 1.11.3 (hcloud)

Consul 1.11.4 (hcloud)

Consul 1.12.0-beta1 (hcloud)

@devnet-io

Copy link
Copy Markdown

What are the blockers on getting this merged? This will be very useful for my org. Happy to assist with what is needed.

@KrakenMare

Copy link
Copy Markdown

Echoing the above. It would be fantastic to see this merged or insight into what is needed for a merge.

@pugnacity

Copy link
Copy Markdown

any news here?

@marco-m

marco-m commented Nov 3, 2022

Copy link
Copy Markdown

Hello @dnephin, @riddhi89, @alvin-huang,
we were almost there with #159 :-), then after a while @Thunderbottom dared to summon the skeleton (just past-Halloween pun) and did this second attempt.
I understand very well that you are fully loaded, but if you could spare a moment to review this PR many of us would be happy. Thanks again!
@Thunderbottom would you have time to resolve the conflicts, to ease the work of the HashiCorp reviewers? Merci!

Comment thread test/tf/hcloud/versions.tf Outdated
Comment thread go.mod Outdated
@acaloiaro

Copy link
Copy Markdown

FYI @Thunderbottom I can't imagine you're enthusiastic to do more work on this PR since it hasn't been re-reviewed yet, but in case you are -- a merge conflict has occurred.

@Thunderbottom

Copy link
Copy Markdown
Author

Hi, haven't gotten the time to check GitHub that often anymore. I have fixed all the issues and rebased to the latest master. let me know if anything else needs to be done.

@svenstaro

Copy link
Copy Markdown

@riddhi89 Any chance we could get this merged?

@uni0nist

uni0nist commented Jul 8, 2023

Copy link
Copy Markdown

Any updates?

adds a provider for hetzner cloud that does:

* filter instances by label selector and datacenter location
* fetch public/private IP address based on provided address type
* checks for associated floating IPs in case of blocked public/private IP addresses
* accepts API token as environment variable: HCLOUD_TOKEN

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* adds hcloud provider to providers map
* adds go module entry for hcloud, updates go mod sum

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* add terraform files for hcloud server setup
* add tests for public IPv4, IPv6, and private IPv4
* add test to check for location filter
* add circleci entry for hcloud provider

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
Chinmay D. Pai added 3 commits July 9, 2023 16:25
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
Signed-off-by: Chinmay D. Pai <chinmay.pai@zerodha.com>
Signed-off-by: Chinmay D. Pai <chinmay.pai@zerodha.com>
Signed-off-by: Chinmay D. Pai <chinmay.pai@zerodha.com>
@uni0nist

Copy link
Copy Markdown

Hello! @alvin-huang any chance you could review this PR? Or do you have somebody else from HashiCorp to suggest? I really want to see Hetzner Cloud in go-discovery so that Сonsul and Nomad could use auto-join. Thanks!

@acaloiaro

acaloiaro commented Jul 12, 2023

Copy link
Copy Markdown

@Neyury If you're desperate to use @Thunderbottom's patch, you can do what I did and fork nomad and add a replace to its go.mod as I've done here: hashicorp/nomad@332c3e4

Then my server.server_join stanza looks like:

  server_join {
    retry_join = [ "provider=hcloud label_selector=nomad-server apiToken=${hetzner_compute_access_token}" ]
  }

Note: You'll want to label your nomad server compute nodes with nomad-server to use the above.

I've been running a hetzner nomad cluster this way for over 6 months. I do recommend pinning your fork to a tagged version of nomad, however.

I have a 1.4.x nomad build with patched go-discover here: https://github.com/acaloiaro/nomad/releases/tag/v1.4.x

You really should not use binaries from unknown strangers on the internet. But feel free to use it in a dev/test environment if you feel that it's sufficiently isolated from the rest of your infrastructure

@tagirb

tagirb commented Jul 14, 2023 via email

Copy link
Copy Markdown

@apricote apricote left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Julian here from the @hetznercloud Integrations team. This looks fine regarding the usage of hcloud-go, I can not speak about go-discover.

Happy to help if you got any questions.

Comment thread provider/hcloud/hcloud_discover.go Outdated
Co-authored-by: Julian Tölle <julian.toelle97@gmail.com>
@acaloiaro

acaloiaro commented Aug 25, 2023

Copy link
Copy Markdown

Hashicorp are "semi-actively moving our repos to https://github.com/hashicorp/go-netaddr".

I emailed a member of their team to learn about the status of this repository. Those are the words of one individual, but you can see from the project activity that the project is not under heavy development.

Anyone waiting for this or other features to land in go-discover should probably not hold their breath about them being added to go-discover. It sounds like this project has become too brittle and difficult to maintain, motivating the migration to go-netaddr. An understandable move given this project's dependencies.

With that said, I don't see how go-netaddr replaces go-discover's cloud host-aware functionality. go-netaddr seems like a nice complement to, but not replacement for go-discover.

@kaspergrubbe

Copy link
Copy Markdown

Hello from 2024, I also hit this in my own setup, and would have loved for go-discover to support hcloud.

@tomgroenwoldt

Copy link
Copy Markdown

Hello from 2025. Is this still considered to be merged?

My current workaround for anyone interested:

# /etc/consul.d/consul.hcl
...
retry_join = [ XXX ]
...

Then, cloud-init runs hcloud to find out about all servers with a given label and substitutes the XXX with their IPs:

# Extract IPs of labeled servers from table and separate them by commas.
output=$(hcloud server list -o noheader -o columns=private_net -l nomad-server=true | sed 's/ *(<your_network_name>)//g' | sed 's/^/"/;s/$/"/' | tr '\n' ',' | sed 's/,$//')
sed -i "s/XXX/$output/" /etc/consul.d/consul.hcl

This leads to:

# /etc/consul.d/consul.hcl
...
retry_join = [ "10.0.0.3","10.0.0.2","10.0.0.4","10.0.0.5" ]
...

While this works for now I'd really like to use the auto discover feature of consul. Thanks for the work!

@kaspergrubbe

Copy link
Copy Markdown

Now that we're sharing workarounds, I am adding the IP of my servers to a DNS A-record:

resource "aws_route53_record" "consulglue" {
  zone_id = ""
  name    = "consulglue.example.com"
  type    = "A"
  ttl     = 300
  records = compact([for x in flatten(cluster-servers.devices[*].addresses) : can(regex(":", x)) ? "" : x])
}

And I use that in Consul like:

  "retry_join": ["consulglue.example.com"]

But it is isn't a great solution as it introduces race-conditions, the cloud-init solution is very clever :)

@acaloiaro

acaloiaro commented Jan 6, 2025

Copy link
Copy Markdown

FYI I refactored Nomad's retry_join to support go-netaddrs in 2023 (hashicorp/nomad#18745) since I think it's clear that go-discover is now in maintenance mode. Through go-netaddrs, Nomad now supports auto-discovery for many more providers.

That work should probably be ported over to consul in favor of trying to make go-discover work for any new or updated use cases.

The following comment of mine earlier in this thread was wrong

With that said, I don't see how go-netaddr replaces go-discover's cloud host-aware functionality. go-netaddr seems like a nice complement to, but not replacement for go-discover.

Go-netaddrs should succeed go-discover, as it's not feasible to add an unbounded number of depenencies to go-discover in order to support new providers and/or use cases.

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.

Add support for Hetzner