siderolabs / image-factory

A service to generate Talos boot assets
Mozilla Public License 2.0
60 stars 16 forks source link

Schematic ID is too long for assigning to a node label #126

Closed onedr0p closed 3 months ago

onedr0p commented 3 months ago

Hi 👋🏼

I was trying to add the schematic ID to the node labels but the schematic ID is too long for Kubernetes, the current schematic ID length is 64 while kubernetes only allows for a length of 63.

error applying new configuration: 1 error occurred:
        * k8s-0: rpc error: code = InvalidArgument desc = 1 error occurred:
        * invalid machine node labels: 1 error occurred:
        * label value length exceeds limit of 63: "d715f723f882b1e1e8063f1b89f237dcc0e3bd000f9f970243af59c8baae0100"

This help with automation and determining which node has what schematic ID, it would be nice to reduce this ID length to something that can fit into a node label by changing the hashing algorithm.

smira commented 3 months ago

We can't "shorten" the schematic ID, but you can re-encode it to fit into the limit of 63 characters if you want to.

As it's sha256 which is hex-encoded, the actual size is 32 bytes, so you could do e.g. base64(unhex(schematicID)) and it will use less characters.

onedr0p commented 3 months ago

That makes sense but unfortunately it wouldn't fit my use case as I use the schematic id defined in one place and it needs to cover being used in the factory URL as well as the node label. Would there be a way to have factory accept this shortened value you mentioned as an alias to the real value on the backend?


For anyone coming across this issue I've worked around this in my use-case by storing the first 32 characters in a part-0 label and the remaining 32 characters in a part-1 label.

Since both Flux and my local env uses drone/envsubst, I can do some len evaluations.

https://github.com/onedr0p/home-ops/blob/eb8a95781abc420efec674f10c65400f444345a4/kubernetes/main/bootstrap/talos/assets/k8s-0.secret.sops.yaml#L108L109

smira commented 3 months ago

Would there be a way to have factory accept this shortened value you mentioned as an alias to the real value on the backend?

No.

But there will be other improvements to help with schematics. The machine schematic can be retrieved via talosctl get extensions without the need to go ever into Kubernetes API.