Skip to content

Commit

Permalink
feat: predict LabelArchStable for new hetzner nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
apricote committed Apr 12, 2023
1 parent 6525fe3 commit c3399dc
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions cluster-autoscaler/cloudprovider/hetzner/hetzner_node_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ func (n *hetznerNodeGroup) TemplateNodeInfo() (*schedulerframework.NodeInfo, err
},
}
node.Status.Allocatable = node.Status.Capacity
node.Labels = cloudprovider.JoinStringMaps(node.Labels, buildNodeGroupLabels(n))
node.Status.Conditions = cloudprovider.BuildReadyConditions()

nodeGroupLabels, err := buildNodeGroupLabels(n)
if err != nil {
return nil, err
}
node.Labels = cloudprovider.JoinStringMaps(node.Labels, nodeGroupLabels)

nodeInfo := schedulerframework.NewNodeInfo(cloudprovider.BuildKubeProxy(n.id))
nodeInfo.SetNode(&node)

Expand Down Expand Up @@ -313,13 +318,19 @@ func newNodeName(n *hetznerNodeGroup) string {
return fmt.Sprintf("%s-%x", n.id, rand.Int63())
}

func buildNodeGroupLabels(n *hetznerNodeGroup) map[string]string {
func buildNodeGroupLabels(n *hetznerNodeGroup) (map[string]string, error) {
archLabel, err := instanceTypeArch(n.manager, n.instanceType)
if err != nil {
return nil, err
}

return map[string]string{
apiv1.LabelInstanceType: n.instanceType,
apiv1.LabelZoneRegionStable: n.region,
apiv1.LabelTopologyRegion: n.region,
apiv1.LabelArchStable: archLabel,
"csi.hetzner.cloud/location": n.region,
nodeGroupLabel: n.id,
}
}, nil
}

func getMachineTypeResourceList(m *hetznerManager, instanceType string) (apiv1.ResourceList, error) {
Expand Down Expand Up @@ -352,6 +363,22 @@ func serverTypeAvailable(manager *hetznerManager, instanceType string, region st
return false, nil
}

func instanceTypeArch(manager *hetznerManager, instanceType string) (string, error) {
serverType, err := manager.cachedServerType.getServerType(instanceType)
if err != nil {
return "", err
}

switch serverType.Architecture {
case hcloud.ArchitectureARM:
return "arm64", nil
case hcloud.ArchitectureX86:
return "amd64", nil
default:
return "amd64", nil
}
}

func createServer(n *hetznerNodeGroup) error {
StartAfterCreate := true
opts := hcloud.ServerCreateOpts{
Expand Down

3 comments on commit c3399dc

@ifeulner
Copy link

@ifeulner ifeulner commented on c3399dc Apr 17, 2023

Choose a reason for hiding this comment

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

@apricote thanks for supporting the multiple architectures - do you know when this will be officially released? And for which kubernetes versions?

@apricote
Copy link
Member Author

Choose a reason for hiding this comment

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

@apricote thanks for supporting the multiple architectures - do you know when this will be officially released? And for which kubernetes versions?

I don't really know about the cluster-autoscaler release process. Based on past releases I think this should make it into the v1.27 release in the next weeks

@apricote
Copy link
Member Author

Choose a reason for hiding this comment

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

Please sign in to comment.