_mongodb.tpl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {{/* vim: set filetype=mustache: */}}
  2. {{/*
  3. Validate MongoDB® required passwords are not empty.
  4. Usage:
  5. {{ include "common.validations.values.mongodb.passwords" (dict "secret" "secretName" "subchart" false "context" $) }}
  6. Params:
  7. - secret - String - Required. Name of the secret where MongoDB® values are stored, e.g: "mongodb-passwords-secret"
  8. - subchart - Boolean - Optional. Whether MongoDB® is used as subchart or not. Default: false
  9. */}}
  10. {{- define "common.validations.values.mongodb.passwords" -}}
  11. {{- $existingSecret := include "common.mongodb.values.auth.existingSecret" . -}}
  12. {{- $enabled := include "common.mongodb.values.enabled" . -}}
  13. {{- $authPrefix := include "common.mongodb.values.key.auth" . -}}
  14. {{- $architecture := include "common.mongodb.values.architecture" . -}}
  15. {{- $valueKeyRootPassword := printf "%s.rootPassword" $authPrefix -}}
  16. {{- $valueKeyUsername := printf "%s.username" $authPrefix -}}
  17. {{- $valueKeyDatabase := printf "%s.database" $authPrefix -}}
  18. {{- $valueKeyPassword := printf "%s.password" $authPrefix -}}
  19. {{- $valueKeyReplicaSetKey := printf "%s.replicaSetKey" $authPrefix -}}
  20. {{- $valueKeyAuthEnabled := printf "%s.enabled" $authPrefix -}}
  21. {{- $authEnabled := include "common.utils.getValueFromKey" (dict "key" $valueKeyAuthEnabled "context" .context) -}}
  22. {{- if and (or (not $existingSecret) (eq $existingSecret "\"\"")) (eq $enabled "true") (eq $authEnabled "true") -}}
  23. {{- $requiredPasswords := list -}}
  24. {{- $requiredRootPassword := dict "valueKey" $valueKeyRootPassword "secret" .secret "field" "mongodb-root-password" -}}
  25. {{- $requiredPasswords = append $requiredPasswords $requiredRootPassword -}}
  26. {{- $valueUsername := include "common.utils.getValueFromKey" (dict "key" $valueKeyUsername "context" .context) }}
  27. {{- $valueDatabase := include "common.utils.getValueFromKey" (dict "key" $valueKeyDatabase "context" .context) }}
  28. {{- if and $valueUsername $valueDatabase -}}
  29. {{- $requiredPassword := dict "valueKey" $valueKeyPassword "secret" .secret "field" "mongodb-password" -}}
  30. {{- $requiredPasswords = append $requiredPasswords $requiredPassword -}}
  31. {{- end -}}
  32. {{- if (eq $architecture "replicaset") -}}
  33. {{- $requiredReplicaSetKey := dict "valueKey" $valueKeyReplicaSetKey "secret" .secret "field" "mongodb-replica-set-key" -}}
  34. {{- $requiredPasswords = append $requiredPasswords $requiredReplicaSetKey -}}
  35. {{- end -}}
  36. {{- include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" .context) -}}
  37. {{- end -}}
  38. {{- end -}}
  39. {{/*
  40. Auxiliary function to get the right value for existingSecret.
  41. Usage:
  42. {{ include "common.mongodb.values.auth.existingSecret" (dict "context" $) }}
  43. Params:
  44. - subchart - Boolean - Optional. Whether MongoDb is used as subchart or not. Default: false
  45. */}}
  46. {{- define "common.mongodb.values.auth.existingSecret" -}}
  47. {{- if .subchart -}}
  48. {{- .context.Values.mongodb.auth.existingSecret | quote -}}
  49. {{- else -}}
  50. {{- .context.Values.auth.existingSecret | quote -}}
  51. {{- end -}}
  52. {{- end -}}
  53. {{/*
  54. Auxiliary function to get the right value for enabled mongodb.
  55. Usage:
  56. {{ include "common.mongodb.values.enabled" (dict "context" $) }}
  57. */}}
  58. {{- define "common.mongodb.values.enabled" -}}
  59. {{- if .subchart -}}
  60. {{- printf "%v" .context.Values.mongodb.enabled -}}
  61. {{- else -}}
  62. {{- printf "%v" (not .context.Values.enabled) -}}
  63. {{- end -}}
  64. {{- end -}}
  65. {{/*
  66. Auxiliary function to get the right value for the key auth
  67. Usage:
  68. {{ include "common.mongodb.values.key.auth" (dict "subchart" "true" "context" $) }}
  69. Params:
  70. - subchart - Boolean - Optional. Whether MongoDB® is used as subchart or not. Default: false
  71. */}}
  72. {{- define "common.mongodb.values.key.auth" -}}
  73. {{- if .subchart -}}
  74. mongodb.auth
  75. {{- else -}}
  76. auth
  77. {{- end -}}
  78. {{- end -}}
  79. {{/*
  80. Auxiliary function to get the right value for architecture
  81. Usage:
  82. {{ include "common.mongodb.values.architecture" (dict "subchart" "true" "context" $) }}
  83. Params:
  84. - subchart - Boolean - Optional. Whether MongoDB® is used as subchart or not. Default: false
  85. */}}
  86. {{- define "common.mongodb.values.architecture" -}}
  87. {{- if .subchart -}}
  88. {{- .context.Values.mongodb.architecture -}}
  89. {{- else -}}
  90. {{- .context.Values.architecture -}}
  91. {{- end -}}
  92. {{- end -}}