syself / hetzner-cloud-controller-manager

Kubernetes cloud-controller-manager for Hetzner Cloud & Hetzner Robot. Enables the usage of Hetzner Dedicated Servers and Hetzner Cloud Servers
Apache License 2.0
10 stars 7 forks source link

Invalid characters in labele instance-type #38

Closed sasho4ek07 closed 3 months ago

sasho4ek07 commented 3 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

guettli commented 3 months ago

@sasho4ek07 thank you very much for the issue and the fix. I will create a PR tomorrow. I will use your code and additionally strip leading and trailing dot, dash, underscore.

janiskemper commented 3 months ago

@sasho4ek07 I'm curious in your use case ;) Dell is rather uncommon for Hetzner. Are you using Cluster API?

sasho4ek07 commented 3 months ago

@sasho4ek07 I'm curious in your use case ;) Dell is rather uncommon for Hetzner. Are you using Cluster API?

Hi, yes, I using Cluster API Provider Hetzner

batistein commented 3 months ago

@sasho4ek07 I guess you run a larger professional use case? we would be really interested to learn more about how you use this open source project, what your experiences are, and would love to get more feedback. Since we are operating a managed Kubernetes offering on top of caph, we are always eager to learn more from our open source users. If you would like to help us improve this project and give us feedback, it would be great if you could spare 30 minutes of your time. You can just pick a slot, just add this url to the notes field so we can assign the right person and you do not end up in a sales call ;) Here the link: https://syself.com/demo