Managed Templates


#1

I am using Roer to create managed templates with externalized K8 configMaps(using modules) in the deployment stage. While publishing the template, I’m getting the below parse exception(It seems Jinja expressions are not supported). It would be really helpful if someone could help me in resolving this?

error converting YAML to JSON: yaml: line 42: found character that cannot start any token

Please find below for more details.

Template file with hardcoded envVars :

schema: "1"
id: pipelineTemplate
metadata:
  name: Pipeline Template
  description: Sample pipline Template
  owner: test@test.com
  scopes: [global]
configuration:
  concurrentExecutions: {}
  triggers: []
  parameters: []
  notifications: []
  description: ""
variables: []
stages:
- id: deployToDev
  type: deploy
  name: Deploy to Dev
  config:
    clusters:
    - account: dev
      application: PDP
      cloudProvider: kubernetes
      containers:
      - args: []
        command: []
        envVars: |
        - envSource:
            configMapSource:
              configMapName: test-config
              key: API_URL1
          name: API_URL1
        - envSource:
            configMapSource:
              configMapName: test-config
              key: API_URL2
          name: API_URL2

Template file with modules :

schema: "1"
id: pipelineTemplate
metadata:
  name: Pipeline Template
  description: Sample pipline Template
  owner: test@test.com
  scopes: [global]
configuration:
  concurrentExecutions: {}
  triggers: []
  parameters: []
  notifications: []
  description: ""
variables: 
- name: envVars
  type: list
stages:
- id: deployToDev
  type: deploy
  name: Deploy to Dev
  config:
    clusters:
    - account: dev
      application: PDP
      cloudProvider: kubernetes
      containers:
      - args: []
        command: []
        envVars: |
        {% for envVar in envVars %}
        - {% module envVars envVar=envVar %}
        {% endfor %}
modules:
- id: envVars
  usage: Defines the environment variables of a container
  variables:
  - name: envVar
    description: Environment variable
  definition:
    envSource:
      configMapSource:
        configMapName: test-config
        key: envVar
        name: envVar

#2

The YAML is malformed here. Multi-line YAML strings need to be indented one level deeper than the parent line, like so (where the module is being called):

schema: "1"
id: pipelineTemplate
metadata:
  name: Pipeline Template
  description: Sample pipline Template
  owner: test@test.com
  scopes: [global]
configuration:
  concurrentExecutions: {}
  triggers: []
  parameters: []
  notifications: []
  description: ""
variables: 
- name: envVars
  type: list
stages:
- id: deployToDev
  type: deploy
  name: Deploy to Dev
  config:
    clusters:
    - account: dev
      application: PDP
      cloudProvider: kubernetes
      containers:
      - args: []
        command: []
        envVars: |
          {% for envVar in envVars %}
          - {% module envVars envVar=envVar %}
          {% endfor %}
modules:
- id: envVars
  usage: Defines the environment variables of a container
  variables:
  - name: envVar
    description: Environment variable
  definition:
    envSource:
      configMapSource:
        configMapName: test-config
        key: envVar
        name: envVar

I also noticed your envVars variable on the module isn’t actually used anywhere in the definition. But leaving the template with the simple indent change, combined with the following config:

schema: "1"
pipeline:
  application: example
  variables:
    envVars:
    - hello
    - world

Results in the following planned pipeline:

{
  "keepWaitingPipelines": false,
  "limitConcurrent": true,
  "application": "example",
  "parameterConfig": [],
  "name": "Unnamed Execution",
  "stages": [
    {
      "requisiteStageRefIds": [],
      "name": "Deploy to Dev",
      "id": "c4c6adf7-0a40-4027-a9ef-b1c0123b50fe",
      "refId": "deployToDev",
      "type": "deploy",
      "clusters": [
        {
          "account": "dev",
          "application": "PDP",
          "cloudProvider": "kubernetes",
          "containers": [
            {
              "args": [],
              "command": [],
              "envVars": [
                {
                  "envSource": {
                    "configMapSource": {
                      "configMapName": "test-config",
                      "key": "envVar",
                      "name": "envVar"
                    }
                  }
                },
                {
                  "envSource": {
                    "configMapSource": {
                      "configMapName": "test-config",
                      "key": "envVar",
                      "name": "envVar"
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "id": "unknown",
  "notifications": [],
  "trigger": {
    "type": "manual",
    "user": "Metatron User Cert for rz",
    "parameters": {}
  }
}

Do let me know if you have any questions.


#3

@robzienert, It worked with the suggested changes. Thanks for responding.