### What happened?

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.test-config "services-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 "test-config" "services-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`

### What did you expect to happen?

it should procced without any errors

### How can we reproduce it (as minimally and precisely as possible)?

crated a config map and key which contains the hyphen in it. 

Try to use the configmap key in the if condition.

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version
Client Version: v1.29.0+rke2r1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.0+rke2r1
```

</details>


### Cloud provider

<details>

</details>


### OS version

<details>

```console
# On Linux:
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$ uname -a
Linux pamutil46-32 6.1.73+pam01 #1 SMP PREEMPT_DYNAMIC Thu Jan 18 10:16:13 PST 2024 x86_64 GNU/Linux

```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>

</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>

enable ports based on the config value in the kubernates
This is a GitHub Issue
repo:kubernetes
owner:kubernetes
Title : enable ports based on the config value in the kubernates
Issue date:

--- start body ---
### What happened?

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.test-config "services-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 "test-config" "services-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`

### What did you expect to happen?

it should procced without any errors

### How can we reproduce it (as minimally and precisely as possible)?

crated a config map and key which contains the hyphen in it. 

Try to use the configmap key in the if condition.

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version
Client Version: v1.29.0+rke2r1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.0+rke2r1
```

</details>


### Cloud provider

<details>

</details>


### OS version

<details>

```console
# On Linux:
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
$ uname -a
Linux pamutil46-32 6.1.73+pam01 #1 SMP PREEMPT_DYNAMIC Thu Jan 18 10:16:13 PST 2024 x86_64 GNU/Linux

```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>

</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>

--- end body ---
