hetznercloud / hcloud-cloud-controller-manager

Kubernetes cloud-controller-manager for Hetzner Cloud
Apache License 2.0
736 stars 118 forks source link

Invalid characters in labele instance-type #645

Closed sasho4ek07 closed 1 week ago

sasho4ek07 commented 5 months ago

TL;DR

When trying to initialize a node on a bare metal host with a Dell PowerEdge™ type, an error occurs when setting the label: "instance-type"

Expected behavior

Node initialization without error

Observed behavior

When trying to initialize a node on a bare metal host with a Dell PowerEdge™ type, an error occurs when setting the label "instance-type". Since it contains the symbol ™, which is unacceptable for labels.

Minimal working example

it is necessary to remove invalid characters when obtaining instance-type from server data

func getInstanceTypeOfRobotServer(bmServer *models.Server) string {
    if bmServer == nil {
        panic("getInstanceTypeOfRobotServer called with nil server")
    }
    return regexp.MustCompile(`[^a-zA-Z0-9_.-]+`).ReplaceAllString(strings.ReplaceAll(bmServer.Product, " ", "-"), "")
}

Log output

E0521 09:46:06.971841       1 node_controller.go:240] error syncing 'bm-test-cluster-md-1-2djh8-mzbtq': Node "bm-test-cluster-md-1-2djh8-mzbtq" is invalid: metadata.labels: Invalid value: "Dell-PowerEdge™-R660-DX293": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?'), requeuing

Additional information

No response

apricote commented 4 months ago

Your suggested code looks good. Do you want to open a PR yourself? I would like to see: