Helm chart template: Require that values (in values.yaml) for nodeSelector exists as labels on nodes

2/16/2022

I was trying to make sure that users configuring nodeSelector values in a chart will fill in labels that actually match the ones on the nodes in the kubernetes cluster and was wondering if anyone knows a way to do this?

My initial idea was to use something in style with

{{ required "nodeSelector needs to be set to a label of one of the nodes" (has .Values.nodeSelector (lookup "v1" "nodes" "--show-labels" "")) }}

This would, in theory, require that the nodeSelector values exist in the map of labels.

Would "looping" over the values and using eq be better? Or any other smart ideas?

The first obvious problem here was that nodeSelector values are defined key: value for example:

nodeSelector:
  product: monitoring

While Node labels are written as key=value.

The second obvious problem is that I get an error telling me I cant use the has function on type map. Is there a way to convert a map to a list in a neat way or another solution to this?

Really appreciate any feedback, so just write! :)

-- Cladnic
go-templates
helm-templates
kubernetes
kubernetes-helm

0 Answers