template-v2-from-secret.yaml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. {% raw %}
  2. # define your template in a config map
  3. apiVersion: v1
  4. kind: ConfigMap
  5. metadata:
  6. name: grafana-config-tpl
  7. data:
  8. config.yaml: |
  9. datasources:
  10. - name: Graphite
  11. type: graphite
  12. access: proxy
  13. url: "{{ .uri }}"
  14. password: "{{ .password }}"
  15. user: "{{ .user }}"
  16. templated: |
  17. # key and value templated
  18. my-application-{{ .user}}: {{ .password | b64enc }}
  19. # conditional keys
  20. {{- if hasPrefix "oci://" .uri }}
  21. enableOCI: true
  22. {{- else }}
  23. enableOCI: false
  24. {{- end }}
  25. # Fixed values
  26. application-type: grafana
  27. annotations: |
  28. #dynamic timestamp generation
  29. last-synced-for-user/{{ .user }}: {{ now }}
  30. ---
  31. apiVersion: external-secrets.io/v1
  32. kind: ExternalSecret
  33. metadata:
  34. name: my-template-example
  35. spec:
  36. # ...
  37. target:
  38. name: secret-to-be-created
  39. template:
  40. engineVersion: v2
  41. templateFrom:
  42. - target: Data
  43. configMap:
  44. # name of the configmap to pull in
  45. name: grafana-config-tpl
  46. # here you define the keys that should be used as template
  47. items:
  48. - key: config.yaml
  49. templateAs: Values
  50. - key: templated
  51. templateAs: KeysAndValues
  52. - target: Annotations
  53. configMap:
  54. # name of the configmap to pull in
  55. name: grafana-config-tpl
  56. # here you define the keys that should be used as template
  57. items:
  58. - key: annotations
  59. templateAs: KeysAndValues
  60. data:
  61. - secretKey: user
  62. remoteRef:
  63. key: /grafana/user
  64. - secretKey: password
  65. remoteRef:
  66. key: /grafana/password
  67. - secretKey: uri
  68. remoteRef:
  69. key: /grafana/uri
  70. {% endraw %}