Bake and deploy manifest errors

Hey,

I have created pipeline which has such steps:

  1. Get webhook with json:
{
	"auth": "---",
	"description": "test description",
	"seed": { 
        "cores":"1",
        "memory":"128",
        "image":"scalecube/scalecube-seed:0.1.13",
        "mainClass":"io.scalecube.seed.SeedRunner",
        "javaOpts":"-Dsome.variable=some_value",
        "programArgs":"key1=value1 key2=value2",
        "env":{ 
            "key1":"value1",
            "key2":"value2"
        }
    }
}
  1. Evaluate variables:

  2. Bake helm package with values.yaml
    3.1

# Global values
global:

  # Release
  ReleaseVersion: v1.0

  # environment
  environment: dev

  # application name
  app: seed

  # node selector
  nodeSelector:
    environment: dev

  # seed settings
  seed:
    mainClass: "${#stage('Generate ENV')['outputs']['SEED_MAIN_CLASS']}"
    javaOpts: "${#stage('Generate ENV')['outputs']['SEED_JAVA_OPTS']}" 
    image: "${#stage('Generate ENV')['outputs']['SEED_IMAGE']}" 
    programArgs: "${#stage('Generate ENV')['outputs']['SEED_PROGRAM_ARGS']}" 
    environment: "${#stage('Generate ENV')['outputs']['SEED_ENVIRONMENT']}"
    cores: "${#stage('Generate ENV')['outputs']['SEED_CORES']}"
    memory: "${#stage('Generate ENV')['outputs']['SEED_MEMORY']}"

3.2
part of kubernetes manifest in helm

     containers:
      - name: seed
        resources:
          requests:
            memory: "{{ .Values.global.seed.memory }}Mi"
            cpu: "{{ .Values.global.seed.cores }}m"
          limits:
            memory: "{{ .Values.global.seed.memory }}Mi"
            cpu: "{{ .Values.global.seed.cores }}m"

        image: {{ .Values.global.seed.image }}

        imagePullPolicy: Always
        env:
{{- range $key, $value := .Values.global.seed.environment | fromJson }}
        - name: {{ $key }}
          value: {{ $value }}
{{- end }}
        - name: PROGRAM_ARGS
          value: "{{ .Values.global.seed.mainClass }} {{ .Values.global.seed.programArgs }}"
        - name: JAVA_OPTS
          value: {{ .Values.global.seed.javaOpts }}

  1. Deploy baked manifest.

On 3 stage i have rendered manifests with:

env:
   - name: Error
     value: invalid character '$' looking for beginning of value

image

And, of course, this is not behavior which I should have.

I expected from spinnaker:

  1. Evaluate SpEL expressions so I could have after baking:
environment: '{"key1":"value1","key2":"value2"}'
  1. Render manifests with helm renderer:
- name: key1
  value: value1
- name: key2
  value: value2

So the question is:
Is it possible to iterate with my description of behavior?
Can it be implemented in future?
Is any additional variants to do this?
I wanted to try Kustomize renderer but documentation is very poor - there is no examples.

Hi, did you check the “Evaluate SpEL expressions in overrides at bake time” option on the Bake stage ?
Looks like the SpELs were passed to the Helm renderer unevaluated

I tried both variants with and without tick. You are right, they were passed to the Helm renderer unevaluated and “Evaluate SpEL expressions in overrides at bake time” didn’t change that behaviour.

Looking again, I think the values file should not have SpELs, you can set them to empty strings or some default values and pass the actual values in using the “overrides” option on the bake stage.

The overrides take key/value entries, the keys would be the “paths” in the values file, e.g “global.seed.mainClass” and the values can then be SpELs. With the “Expression Evaluation” option checked, it should pass in these values just like the “set” flag on helm install/upgrade

I have changed values.yaml and now:

global:
  seed:
    environment: ""

And added:

Now the error is:

Exception ( Create Bake )

Bake failed: Error: render error in "manifest.yml": template: project/templates/manifest.yml:42:60: executing "project/templates/manifest.yml" at : wrong type for value; expected string; got []interface {}

This is manifest.yml

 42 {{- range $key, $value := .Values.global.seed.environment | fromJson }}
 43         - name: {{ $key }}
 44           value: {{ $value }}
 45 {{- end }}

I tested locally with helm only and with values.yml:

global:
  seed:
    environment: '{"key1":"value1","key2":"value2"}'

and it works locally.

It looks like fromJson here is not working correctly:

{{- range $key, $value := .Values.global.seed.environment | fromJson }}

We’re getting close, since the data is coming in as an object, it has been parsed into a map and seed.env (or ['seed']['env']) is now an object (map).

Replace global.seed.environment= ${#stage('Generate ENV')['outputs']['SEED_ENVIRONMENT']} with global.seed.environment = #toJson(${#stage('Generate ENV')['outputs']['SEED_ENVIRONMENT']}) in the overrides.

This should pass the object as string to helm.

If you can modify the template, it could also take .Values.global.seed.environment directly as an object instead of expecting a string and converting it back to an object. This would work with what you have now

I have replaced. Now global.seed.environment equals:

#toJson(${#stage('Generate ENV')['outputs']['SEED_ENVIRONMENT']})

New error appears:

Exception ( Create Bake )

Bake failed: Error: failed parsing --set-string data: key ""key2":"value2"})" has no value

And I have
image
in “Generate ENV” stage

Sorry, there’s a problem in the SpEL, please use this: ${#toJson(#stage('Generate ENV')['outputs']['SEED_ENVIRONMENT'])} for global.seed.environment

The same issue with

${#toJson(#stage('Generate ENV')['outputs']['SEED_ENVIRONMENT'])}

image

Previous “Generate ENV” stage:
image

Looks like SEED_ENVIRONMENT is already string, lets remove the #toJson function

And we get back to:

env:
- name: Error
  value: invalid character '#' looking for beginning of value

image

:grinning:
Something is messing up with the string. Lets skip the SEED_ENVIRONMENT for now and use ${#toJson(trigger['payload']['seed']['env'])} directly

Previous error appeared:

Exception ( Create Bake )

Bake failed: Error: render error in "manifest.yml": template: project/templates/manifest.yml:42:60: executing "project/templates/manifest.yml" at : wrong type for value; expected string; got []interface {}

I appreciate your help, Josiah_Adenegan

Let me try to setup something close to what you have then, looks like “visual” debugging is not working

Yep, something with trigger and manifest with part from first message