Environment variables

Overview

IBM Financial Services Workbench provides the possibility to define any custom environment variables (like DB connection, URLs,...) for your service projects. If a new service project is created you will find an extension-values.yaml file in your Git repository. It's possible to add this file by yourself if it is missing. But you need to use the file name extension-values.yaml and the described file structure.

Add new environment variables

By default, the extension-values.yaml file contains only comments that should explain how the file can be used. To use this feature you need to remove the comments and place your needed environment variables in the file as described later. The service project pipeline will add this additional variables to the Helm chart that gets created via the pipeline.

Note: Within an Application Composition Project these additional values (of the `values.yaml`) can be seen and even be overridden by the "Configure Component" functionality.

The built Helm chart of the service project will react on these values and add the additional environment variables to the deployment of your service project:

  • Supported types of environment variables:

    • secretKeyRef

    • configMapKeyRef

    • keyValue

    • fieldRef

Structure of extension-values.yaml

env:
  variables:
    secretKeyRef:
      - variableName: VARIABLE1
        secretName: k5-service1-variable1-secret
        secretKey: key1
        optional: false
    configMapKeyRef:
      - variableName: VARIABLE2
        configMapName: k5-service1-variable2-cm
        configMapKey: key2
        optional: false
    keyValue:
      - variableName: VARIABLE3
        value: myString
    fieldRef:
      - variableName: VARIABLE4
        apiVersion: v1
        fieldPath: metadata.namespace

Supported type secretKeyRef

KeyDescriptionExample
variableNameName of the environment variableVARIABLE1
secretNameName of the Kubernetes secretk5-service1-variable1-secret
secretKeyName of the Key used in the Kubernetes secretkey1
optionalDefines if the Pod will start if the secret is missingfalse

Supported type configMapKeyRef

KeyDescriptionExample
variableNameName of the environment variableVARIABLE2
configMapNameName of the Kubernetes configmapk5-service1-variable2-cm
configMapKeyName of the Key used in the Kubernetes configmapkey2
optionalDefines if the Pod will start if the configmap is missingfalse

Supported type keyValue

KeyDescriptionExample
variableNameName of the environment variableVARIABLE3
valueValue of the environment variablemyString

Supported type fieldRef

KeyDescriptionExample
variableNameName of the environment variableVARIABLE4
apiVersionAPI Version of the Kubernetes resourcev1
fieldPathPath to the valuemetadata.namespace

Deployment of new environment variables

In your deployed service the environment variables will be added to the deployment of the service project so that they can be used in the implementation, e.g.:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: k5-service1
...
spec:
  containers:
    - env:
        - name: VARIABLE1
          valueFrom:
            secretKeyRef:
              name: k5-service1-variable1-secret
              key: key1
              optional: false
        - name: VARIABLE2
          valueFrom:
            configMapKeyRef:
              name: k5-service1-variable2-cm
              key: key2
              optional: false
        - name: VARIABLE3
          value: myString
        - name: VARIABLE4
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace

Using secrets or ConfigMaps

Attention: If you are using secrets or ConfigMaps for your environment variables you need to create the defined secrets and ConfigMaps manually in your OpenShift namespaces (k5-projects).

Example to create a required secret:

cat <<EOF | oc apply -f -
kind: Secret
apiVersion: v1
metadata:
  name: k5-service1-variable1-secret
spec:
  data:
    key1: bXlWYWx1ZTE=
type: Opaque
EOF

Example to create a required ConfigMap:

cat <<EOF | oc apply -f -
kind: ConfigMap
apiVersion: v1
metadata:
  name: k5-service1-variable2-cm
spec:
  data:
    key2: myValue2
type: Opaque
EOF
Attention: Naming collisions of the ConfigMaps and secrets must be avoided by using unique names (consider applications, services and namespaces).