swarmkit icon indicating copy to clipboard operation
swarmkit copied to clipboard

[Proposal] docker service create template support for Node labels

Open derteufelqwe opened this issue 4 years ago • 4 comments

Currently supported Templates regarding the Nodes Currently only two templates {{ .Node.ID }} and {{ .Node.Hostname }} are supported. This is nice, but labels would put these templates on another level in terms of possibilities.

How could this look The template could be something like {{ .Node.Spec.Labels.[label name] }}. If the label is not found the value "", "null" or "<no value>" (as it's currently done using docker node inspect) should be used.

Summary Dockers templates for service creation should support node labels. The result of the template {{ .Node.Spec.Labels.example_label }} should be the same as the output of docker node inspect -f="{{ .Spec.Labels.example_label }}" node_name.

derteufelqwe avatar Apr 12 '20 12:04 derteufelqwe

Great proposal, and highly anticipated :) Also, as Docker is using Go’s text/template engine, a pipeline can be used for setting a default value if the specific label has null value, for example:

{{ .Node.Spec.Labels.label_name | "default_value" }}

skechboy avatar Jan 08 '22 22:01 skechboy

Any news on this?

Absolutely necessary! For now I have a MariaDB docker config, which has a file included that points to a config file mounted from host to get some specific variables for galera cluster. When I could use node labels it would allow me to avoid host bind mounts for config files.

KevinBLT avatar Jan 24 '22 09:01 KevinBLT

This feels useful for anyone running stateful apps in swarm. I'd be happy to see if this is something I can contribute to. Any pointers where to look specifically (links to files would be enough) @dperny @thaJeztah ?

s4ke avatar Dec 15 '22 15:12 s4ke

@s4ke I think that it simply folder called for template on root of this Git repo where the code related to this one exists.

olljanat avatar Feb 22 '23 22:02 olljanat