opensearch-project / helm-charts

:wheel_of_dharma: A community repository for Helm Charts of OpenSearch Project.
https://opensearch.org/docs/latest/opensearch/install/helm/
Apache License 2.0
173 stars 234 forks source link

[Enhancement][opensearch/opensearch-dashboards] Make possible to give string to extraObjects #428

Closed kevinleturc closed 1 year ago

kevinleturc commented 1 year ago

Is your feature request related to a problem? Please describe. I'm using the chart to deploy OpenSearch with additional extraObjects, but I can't include template in these objects.

This is because the extraManifests.yml descriptor converts the given object to yaml and { (or other reserved characters) are not allowed if not escaped. This is not an issue for simple string such as object name, as we can quote them, but it is when you try to include template such as opensearch.labels as you can't quote such include.

You can find below an example that leads to the error: error converting YAML to JSON: yaml: line XX: did not find expected key

extraObjects:
  - apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: {{ template "opensearch.uname" . }}
      labels:
        {{- include "opensearch.labels" . | nindent 4 }}
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          {{- include "opensearch.selectorLabels" . | nindent 6 }}

Describe the solution you'd like One way to make this working is to give the whole object as a string, this is what Bitnami is using in their charts, see https://github.com/bitnami/charts/blob/main/bitnami/common/templates/_tplvalues.tpl. By improving this part, we will be able to give the object as string and template it with the tpl function, the object will look like that:

extraObjects:
  - |
    apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: {{ template "opensearch.uname" . }}
      labels:
        {{- include "opensearch.labels" . | nindent 4 }}
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          {{- include "opensearch.selectorLabels" . | nindent 6 }}

Describe alternatives you've considered Currently, to be able to deploy my object I'm listing all labels and quoting template calls such as below:

extraObjects:
  - apiVersion: policy/v1
    kind: PodDisruptionBudget
    metadata:
      name: '{{ template "opensearch.uname" . }}'
      labels:
        app.kubernetes.io/name: '{{ include "opensearch.name" . }}'
        app.kubernetes.io/instance: '{{ .Release.Name }}'
        app.kubernetes.io/managed-by: '{{ .Release.Service }}'
        app.kubernetes.io/component: '{{ include "opensearch.uname" . }}'
    spec:
      minAvailable: 1
      selector:
        matchLabels:
          app.kubernetes.io/name: '{{ include "opensearch.name" . }}'
          app.kubernetes.io/instance: '{{ .Release.Name }}'

Additional context I'm using the opensearch 1.x chart, would it be possible to backport the change?

jordarlu commented 1 year ago

@prudhvigodithi , pls have a review and comment ..thanks

TheAlgo commented 1 year ago

Closing the issue as the PR is merged now. Thanks @kevinleturc for your contribution.