shayanmalinda
shayanmalinda

Reputation: 2267

Locally testing OS environmental variables in Ballerina

When using Ballerina configurables we can use a config.toml to maintain the configurations and compile the service without any issue.

If I need to use a os:getEnv("variable") in Ballerina, is there a way to mount this file in local environment and compile the service?

Thank you.

Upvotes: 0

Views: 81

Answers (1)

Lakshan Weerasinghe
Lakshan Weerasinghe

Reputation: 329

You can build the kubernetes artifact using bal build --cloud=k8s command. Then you can find the created artifacts in the target/kubernets directory. In there you can find a yaml file and inside the yaml file you can see a yaml document with kind Deployment. In there you have to add the environment variable that need to refer from a mounted secret.

apiVersion: "apps/v1"
kind: "Deployment"
...
spec:
    ...
    spec:
      containers:
      - image: "os_secret:latest"
        ...
        env:
          - name: MY_ENV_VARIABLE
            valueFrom:
              secretKeyRef:
                name: my-secret
                key: env-variable
         ...

And you have to add the secret at the end of the yaml file as below.

...
---
apiVersion: v1
kind: Secret
metadata:
  name: my-secret
type: Opaque
data:
  env-variable: <Base64 encoded value>

By updating the Deployment and adding the Secret you test this locally.

Upvotes: 0

Related Questions