Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metadata.labels lost its flexibility #48

Closed
kkaempf opened this issue Jul 14, 2022 · 14 comments
Closed

metadata.labels lost its flexibility #48

kkaempf opened this issue Jul 14, 2022 · 14 comments
Assignees

Comments

@kkaempf
Copy link
Contributor

kkaempf commented Jul 14, 2022

Andrew's (successful) run with Jacob's code had

  machineInventoryLabels:
    clusterName: test
  machineName: m-${System Information/Manufacturer}-${System Information/Product Name}-${SystemInformation/UUID}

in its machineRegistration

However, with the current elemental-operator, the line above gets rejected with

│ time="2022-07-14T12:55:56Z" level=error msg="error creating machine inventory: MachineInventory.elemental.cattle.io \"m-qemu-standard-pc-q35-ich9-2009-not-specified\" is invalid: [metadata.labels: Invalid value: \"m-${SystemInformation/Manufacturer}-${System Information/Product Name}-${SystemInformation/UUID}\": must be no more than 63 characters

in the elemental-operator log in the management cluster.

Even shortening it to

 machineName: m-${SystemInformation/UUID}

still doesn't work

time="2022-07-14T15:25:10Z" level=error msg="error creating machine inventory: MachineInventory.elemental.cattle.io \"m-qemu-standard-pc-q35-ich9-2009-not-specified\" is invalid: metadata.labels: Invalid value: \"m-${SystemInformation/UUID}\": 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])?')" 
@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

63 characters limit is an upstream limitation:

https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

Labels are key/value pairs. Valid label keys have two segments: an optional prefix and name, separated by a slash (/). The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between. The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots (.), not longer than 253 characters in total, followed by a slash (/).```

@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

The issue may actually be that the ${System Information/Manufacturer} stuff is not being resolved to actual data

@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

@kkaempf was smbios disabled for this? I dont know about it but seems like that content should be resolved to the actual data, but if smbios is disabled, maybe that data is not available and its not interpreted properly?

@kkaempf
Copy link
Contributor Author

kkaempf commented Jul 15, 2022

It already fails when I kubectl apply it !

@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

looks like the machine name was resolved but somehow is being copied into the labels and that fails, as is not resolved?

│ time="2022-07-14T12:55:56Z" level=error msg="error creating machine inventory: MachineInventory.elemental.cattle.io \"m-qemu-standard-pc-q35-ich9-2009-not-specified\" is invalid: [metadata.labels: Invalid value: \"m-${SystemInformation/Manufacturer}-${System Information/Product Name}-${SystemInformation/UUID}\": must be no more than 63 characters

@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

ok, seems that we dont support smbios substitution for labels as you can see here: https://github.com/rancher/elemental-operator/blob/main/pkg/server/register.go#L130

Only the name is parsed via the smbios stuff. Labels are copied as-is.

@kkaempf Can you post the full machineinventory.yaml ? There is no reason the labels would contain anything from the name unless racher/k8s/operator does some mangling and copies the machineName into the labels somehow, but nothing that I can see.

It already fails when I kubectl apply it !

There should be no reason for that, machineName is a string which has no limit, I just applied the same yaml locally without issues. Please post the yaml file being applied because there may be something wrong with it

@kkaempf
Copy link
Contributor Author

kkaempf commented Jul 15, 2022

apiVersion: elemental.cattle.io/v1beta1
kind: MachineRegistration
metadata:
  name: test-nodes
  namespace: fleet-default
spec:
  install:
    reboot: true
    password: 'password'
    device: /dev/nvme0n1
  machineInventoryLabels:
    clusterName: test
  machineName: m-${System Information/Manufacturer}-${System Information/Product Name}-${System Information/UUID}

@kkaempf
Copy link
Contributor Author

kkaempf commented Jul 15, 2022

This is the file I try to kubectl apply (and fail)

@kkaempf
Copy link
Contributor Author

kkaempf commented Jul 15, 2022

Argh. Not sure where I failed. Tried it again and it works 🤦🏻

@kkaempf kkaempf closed this as completed Jul 15, 2022
@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

Im wondering if there was an error on the yaml and it took the machineName as a machineInventoryLabels instead of its own key. I mean, if you add two spaces to it, it turns into part of the machineInventoryLabels so...

@Itxaka Itxaka self-assigned this Jul 15, 2022
@kkaempf
Copy link
Contributor Author

kkaempf commented Jul 15, 2022

Hmm, I have to reopen this. I know that the yaml is correct. Rancher UI shows me

spec:
  config:
    elemental:
      install:
        debug: true
        device: /dev/sda
        password: password
        reboot: true
      registration: {}
      system_agent: {}
  machineInventoryLabels:
    cluster-name: store-123
    machine-name: m-${System Information/Manufacturer}-${System Information/Product
      Name}-${System Information/UUID}

But the operator log on the management cluster complains

time="2022-07-15T16:43:42Z" level=error msg="error creating machine inventory: MachineInventory.elemental.cattle.io \"m-qemu-standard-pc-q35-ich9-2009-not-specified\" is invalid: [metada │
│ ta.labels: Invalid value: \"m-${System Information/Manufacturer}-${System Information/Product Name}-${System Information/UUID}\": must be no more than 63 characters, metadata.labels: Inv │
│ alid value: \"m-${System Information/Manufacturer}-${System Information/Product Name}-${System Information/UUID}\": a valid label must be an empty string or consist of alphanumeric chara │
│ cters, '-', '_' 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])?')]"  

What am I missing ?

@kkaempf kkaempf reopened this Jul 15, 2022
@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

You are not missing anything. In fact it's the other way around. You are passing the machineName as a machineInventoryLabel so it's getting parsed as a label and that doesn't interpolate anything, it stores what you pass literally.

Try to remove two spaces in front of your machineName.

@Itxaka
Copy link
Contributor

Itxaka commented Jul 15, 2022

Proper yaml:

spec:
  config:
    elemental:
      install:
        debug: true
        device: /dev/sda
        password: password
        reboot: true
      registration: {}
      system_agent: {}
  machine-name: m-${System Information/Manufacturer}-${System Information/Product
      Name}-${System Information/UUID}
  machineInventoryLabels:
    cluster-name: store-123

@kkaempf
Copy link
Contributor Author

kkaempf commented Jul 17, 2022

Thanks, confirmed working

@kkaempf kkaempf closed this as completed Jul 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants