_mongodb.tpl 4.3 KB

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