enable ports based on the config value in the kubernates

  Kiến thức lập trình

I have the following daemonset.yaml my requirement is we need to enable the debug port only if services-debug is set to true.

 apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: your-daemonset
    spec:
      selector:
        matchLabels:
          app: your-app
      template:
        metadata:
          labels:
            app: your-app
        spec:
          containers:
          - name: your-container
            image: your-image
            env:
              - name: SERVICES_DEBUG
                valueFrom:
                  configMapKeyRef:
                    name: test-config
                    key: services-debug
                    optional: true
            ports:
              - name: http-port
                containerPort: 80  # Adjust as needed
                hostPort: 80        # Adjust as needed
               - name: debug-port
                containerPort: 81  # Adjust as needed
                hostPort: 81        # Adjust as needed

i have tried the following option

{{- if eq (index .Values.configMap.pam-config "utaservices-debug") "true" }}
- name: debug-port
  containerPort: {{ .Values.image.debug-port }}
  hostPort: {{ .Values.image.debug-port }}
{{- end }}

but when we use it helm is throwing
Error: parse error at (test/templates/daemonset.yaml:59): bad character U+002D '-'

also tried

{{- if eq (index .Values.configMap "pam-config" "utaservices-debug") "true" }}
- name: debug-port
  containerPort: {{ .Values.image.debug-port }}
  hostPort: {{ .Values.image.debug-port }}
{{- end }}

but giving

templates/daemonset.yaml:59:20: executing "test/templates/daemonset.yaml" at <index .Values.configMap "test-config" "services-debug">: error calling index: index of untyped nil

LEAVE A COMMENT