How to set annotations for a helm install

1/7/2020

I am trying to install the chart stable/efs-provisioner and I would like to apply an annotation so that the deployment is correctly tagged in datadog.

Datadog requires the annotation: ad.datadoghq.com/tags: '{"env": "staging"}'

I have tried various incantations of the following, but I keep getting the error below.

$ helm install efs-provisioner stable/efs-provisioner \
  --set efsProvisioner.efsFileSystemId=fs-a1b2c3d4 \ 
  --set efsProvisioner.awsRegion=us-east-1 \
  --set annotations."ad\.datadoghq\.com/tags"="{\'env\': \'staging\'}"

Error:

Error: YAML parse error on efs-provisioner/templates/storageclass.yaml: 
error unmarshaling JSON: while decoding JSON: 
json: cannot unmarshal array into Go struct field .metadata.annotations of type string
-- GrokSrc
go
kubernetes-helm

1 Answer

1/7/2020

Assuming you'd like the output to look like the following:

$ helm template efs-provisioner stable/efs-provisioner <flags> \
  | grep -m 1 -C 4 datadog
    chart: efs-provisioner-0.10.0
    release: "efs-provisioner"
    heritage: "Helm"
  annotations:
    ad.datadoghq.com/tags: '{"env": "staging"}'

you need to escape the { and and use \" instead of \':

$ helm template efs-provisioner stable/efs-provisioner \
  --set efsProvisioner.efsFileSystemId=fs-a1b2c3d4 \
  --set efsProvisioner.awsRegion=us-east-1 \
  --set annotations."ad\.datadoghq\.com/tags"="\{\"env\": \"staging\"\}" 
-- Amit Kumar Gupta
Source: StackOverflow