springkuberneteskubernetes-helmspring-cloud-gateway

How to resolve invalid character included yaml attributes from kubernetes


I need to dynamically add cors allowedOrigins from value.yaml for kubernetes container. here is my value.yaml

 test:
  cors:
    allowedOrigins: 'https://www.test.com'

And I was trying to override below attribute.

spring:
  application:
    name: something
  cloud:
    gateway:
      globalcors:
        corsConfigurations:
          '[/**]':
            allowedOrigins: 'https://www.host.com'

And i tried to resolve it like this below.

- name: SPRING_CLOUD_GATEWAY_GLOBALCORS_CORSCONFIGURATIONS_[/**]_ALLOWEDORIGINS
  value: {{ .Values.test.cors.allowedOrigins | quote }}

Btw it says that I can't use [/**] this since it is invalid. I'm getting this error

SPRING_CLOUD_GATEWAY_GLOBALCORS_CORSCONFIGURATIONS_[/**]ALLOWEDORIGINS": a valid environment variable name must consist of alphabetic characters, digits, '', '-', or '.', and must not start with a digit (e.g. 'my.env-name', or 'MY_ENV.NAME', or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')

How can I make it work?


Solution

  • I found a better way to solve this. Here is my Value.yaml

    test:
      cors:
        allowedOrigins: 'https://www.test.com'
    

    And this is was in my microservice which I needed to override.

    spring:
      application:
        name: something
      cloud:
        gateway:
          globalcors:
            corsConfigurations:
              '[/**]':
                allowedOrigins: ${GATEWAY_CORS_ALLOWED_ORIGINS:*}
    

    And this is the value mapping in deployment yaml.

    - name: GATEWAY_CORS_ALLOWED_ORIGINS
      value: {{ default "*" (.Values.test.cors.allowedOrigins) | quote }} 
    

    To do this, it helped me the comments I received for this question. So Thanks for the comments.