Skip to content

Commit

Permalink
Use node specific public IP settings
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwickenden committed Mar 31, 2023
1 parent 042a789 commit f11e11c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func BuildHetzner(_ config.AutoscalingOptions, do cloudprovider.NodeGroupDiscove

// Get this node's cloud-init
var cloudInitBase64 string
nodeCloudInitVar := fmt.Sprintf("HCLOUD_CLOUD_INIT_%s", spec.name)
nodeCloudInitVar := fmt.Sprintf("HCLOUD_%s_CLOUD_INIT", strings.ToUpper(spec.name))
if nodeSpecificCloudInit, ok := os.LookupEnv(nodeCloudInitVar); ok {
cloudInitBase64 = nodeSpecificCloudInit
} else {
Expand All @@ -228,6 +228,43 @@ func BuildHetzner(_ config.AutoscalingOptions, do cloudprovider.NodeGroupDiscove

manager.cloudInit[spec.name] = string(cloudInit)

// Get this node's public IP setting
publicIPv4 := true
var publicIPv4Str string
nodePublicIPv4Var := fmt.Sprintf("HCLOUD_%s_PUBLIC_IPV4", strings.ToUpper(spec.name))
if nodeSpecificPublicIPv4, ok := os.LookupEnv(nodePublicIPv4Var); ok {
publicIPv4Str = nodeSpecificPublicIPv4
} else {
publicIPv4Str = os.Getenv("HCLOUD_PUBLIC_IPV4")
}

if publicIPv4Str != "" {
publicIPv4, err = strconv.ParseBool(publicIPv4Str)
if err != nil {
klog.Fatalf("failed to parse HCLOUD_PUBLIC_IPV4 or %s: %s", nodePublicIPv4Var, err)
}
}

manager.publicIPv4[spec.name] = publicIPv4

publicIPv6 := true
var publicIPv6Str string
nodePublicIPv6Var := fmt.Sprintf("HCLOUD_%s_PUBLIC_IPV6", strings.ToUpper(spec.name))
if nodeSpecificPublicIPv6, ok := os.LookupEnv(nodePublicIPv6Var); ok {
publicIPv6Str = nodeSpecificPublicIPv6
} else {
publicIPv6Str = os.Getenv("HCLOUD_PUBLIC_IPV6")
}

if publicIPv6Str != "" {
publicIPv6, err = strconv.ParseBool(publicIPv6Str)
if err != nil {
klog.Fatalf("failed to parse HCLOUD_PUBLIC_IPV6 or %s: %s", nodePublicIPv6Var, err)
}
}

manager.publicIPv6[spec.name] = publicIPv6

manager.nodeGroups[spec.name] = &hetznerNodeGroup{
manager: manager,
id: spec.name,
Expand Down
24 changes: 2 additions & 22 deletions cluster-autoscaler/cloudprovider/hetzner/hetzner_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type hetznerManager struct {
network *hcloud.Network
firewall *hcloud.Firewall
createTimeout time.Duration
publicIPv4 bool
publicIPv6 bool
publicIPv4 map[string]bool
publicIPv6 map[string]bool
cachedServerType *serverTypeCache
cachedServers *serversCache
}
Expand All @@ -76,24 +76,6 @@ 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 @@ -162,8 +144,6 @@ func newManager() (*hetznerManager, error) {
firewall: firewall,
createTimeout: createTimeout,
apiCallContext: ctx,
publicIPv4: publicIPv4,
publicIPv6: publicIPv6,
cachedServerType: newServerTypeCache(ctx, client),
cachedServers: newServersCache(ctx, client),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ func createServer(n *hetznerNodeGroup) error {
nodeGroupLabel: n.id,
},
PublicNet: &hcloud.ServerCreatePublicNet{
EnableIPv4: n.manager.publicIPv4,
EnableIPv6: n.manager.publicIPv6,
EnableIPv4: n.manager.publicIPv4[n.id],
EnableIPv6: n.manager.publicIPv6[n.id],
},
}
if n.manager.sshKey != nil {
Expand Down

0 comments on commit f11e11c

Please sign in to comment.