Skip to content

Commit

Permalink
public ipv4 and ipv6 configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Jul 1, 2022
1 parent 6801507 commit c77ef8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cluster-autoscaler/cloudprovider/hetzner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<min-servers>:<max-servers>:<instance-type>:<region>:<name>` flag.

Multiple flags will create multiple node pools. For example:
Expand Down
22 changes: 22 additions & 0 deletions cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type hetznerManager struct {
network *hcloud.Network
firewall *hcloud.Firewall
createTimeout time.Duration
publicIPv4 bool
publicIPv6 bool
}

func newManager() (*hetznerManager, error) {
Expand All @@ -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
Expand Down Expand Up @@ -141,6 +161,8 @@ func newManager() (*hetznerManager, error) {
firewall: firewall,
createTimeout: createTimeout,
apiCallContext: ctx,
publicIPv4: publicIPv4,
publicIPv6: publicIPv6,
}

m.nodeGroups[drainingNodePoolId] = &hetznerNodeGroup{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit c77ef8a

Please sign in to comment.