Pass Mongodb Atlas Operator env vars from travis to kubernetes deploy.sh

9/28/2021

I am trying to adapt the quickstart guide for Mongo Atlas Operator here Atlas Operator Quickstart to use secure env variables set in TravisCI.

I want to put the quickstart scripts into my deploy.sh, which is triggered from my travis.yaml file.

My travis.yaml already sets one global variable like this:

env:
 global:
    - SHA=$(git rev-parse HEAD)

Which is consumed by the deploy.sh file like this:

docker build -t mydocker/k8s-client:latest -t mydocker/k8s-client:$SHA -f ./client/Dockerfile ./client

but I'm not sure how to pass vars set in the Environment variables bit in the travis Settings to deploy.sh

env vars

This is the section of script I want to pass variables to:

    kubectl create secret generic mongodb-atlas-operator-api-key \
  --from-literal="orgId=$MY_ORG_ID" \
  --from-literal="publicApiKey=$MY_PUBLIC_API_KEY" \
  --from-literal="privateApiKey=$MY_PRIVATE_API_KEY" \
  -n mongodb-atlas-system

I'm assuming the --from-literal syntax will just put in the literal string "orgId=$MY_ORG_ID" for example, and I need to use pipe syntax - but can I do something along the lines of this?:

echo "$MY_ORG_ID" | kubectl create secret generic mongodb-atlas-operator-api-key --orgId-stdin

Or do I need to put something in my travis.yaml before_install script?

-- Davtho1983
kubernetes
mongodb-atlas
travis-ci

1 Answer

9/30/2021

Looks like the echo approach is fine, I've found a similar use-case to yours, have a look here.

-- Jakub Siemaszko
Source: StackOverflow