From c77ef8a0b8b9de527ca86df5f0008785462268a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Lehmann?= Date: Fri, 1 Jul 2022 16:41:41 +0200 Subject: [PATCH] public ipv4 and ipv6 configuration --- .../cloudprovider/hetzner/README.md | 4 ++++ .../cloudprovider/hetzner/hetzner_manager.go | 22 +++++++++++++++++++ .../hetzner/hetzner_node_group.go | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/cluster-autoscaler/cloudprovider/hetzner/README.md b/cluster-autoscaler/cloudprovider/hetzner/README.md index 5fbad46a8787..765636c441c7 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/README.md +++ b/cluster-autoscaler/cloudprovider/hetzner/README.md @@ -16,6 +16,10 @@ The cluster autoscaler for Hetzner Cloud scales worker nodes. `HCLOUD_SSH_KEY` Default empty , This SSH Key will have access to the fresh created server, @see https://docs.hetzner.cloud/#ssh-keys +`HCLOUD_PUBLIC_IPV4` Default true , Whether the server is created with a public IPv4 address or not, @see https://docs.hetzner.cloud/#primary-ips + +`HCLOUD_PUBLIC_IPV6` Default true , Whether the server is created with a public IPv6 address or not, @see https://docs.hetzner.cloud/#primary-ips + Node groups must be defined with the `--nodes=::::` flag. Multiple flags will create multiple node pools. For example: diff --git a/cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go b/cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go index 9cbf373df73b..f3d223c48c27 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go @@ -47,6 +47,8 @@ type hetznerManager struct { network *hcloud.Network firewall *hcloud.Firewall createTimeout time.Duration + publicIPv4 bool + publicIPv6 bool } func newManager() (*hetznerManager, error) { @@ -72,6 +74,24 @@ func newManager() (*hetznerManager, error) { imageName = "ubuntu-20.04" } + publicIPv4 := true + publicIPv4Str := os.Getenv("HCLOUD_PUBLIC_IPV4") + if publicIPv4Str != "" { + publicIPv4, err = strconv.ParseBool(publicIPv4Str) + if err != nil { + return nil, fmt.Errorf("failed to parse HCLOUD_PUBLIC_IPV4: %s", err) + } + } + + publicIPv6 := true + publicIPv6Str := os.Getenv("HCLOUD_PUBLIC_IPV6") + if publicIPv6Str != "" { + publicIPv6, err = strconv.ParseBool(publicIPv6Str) + if err != nil { + return nil, fmt.Errorf("failed to parse HCLOUD_PUBLIC_IPV6: %s", err) + } + } + // Search for an image ID corresponding to the supplied HCLOUD_IMAGE env // variable. This value can either be an image ID itself (an int), a name // (e.g. "ubuntu-20.04"), or a label selector associated with an image @@ -141,6 +161,8 @@ func newManager() (*hetznerManager, error) { firewall: firewall, createTimeout: createTimeout, apiCallContext: ctx, + publicIPv4: publicIPv4, + publicIPv6: publicIPv6, } m.nodeGroups[drainingNodePoolId] = &hetznerNodeGroup{ diff --git a/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go b/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go index c292109ca89e..b7fe9e7691de 100644 --- a/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go +++ b/cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go @@ -358,6 +358,10 @@ func createServer(n *hetznerNodeGroup) error { Labels: map[string]string{ nodeGroupLabel: n.id, }, + PublicNet: &hcloud.ServerCreatePublicNet{ + EnableIPv4: n.manager.publicIPv4, + EnableIPv6: n.manager.publicIPv6, + }, } if n.manager.sshKey != nil { opts.SSHKeys = []*hcloud.SSHKey{n.manager.sshKey}