Skip to content

Conversation

@gacerioni
Copy link

Override configuration with environment variables if they exist.

Hey, team. This is your friend Gabs from Harness, and I have a quick suggestion to allow us to provide some important configuration that overrides the config file app.config when necessary.

For example, during my CD Pipeline, I will retrieve the Redis details from a Vault Server, using Harness expressions (<+secrets.getValue("redis_host")>) and use it in the K8s Deployment -> Pod -> Container environment variables.

For example, I create a Secret or a Configmap to hold these, but then I serve the variables for the python app at runtime, with K8s's envFrom.

Small test:

1-) using a bad redis endpoint, the test will fail:

(env) root@DESKTOP-S8EV48S:~/REDIS/REDIS_PYTHON/ru102py# export REDIS_HOST=cerioni.platformengineer.io
(env) root@DESKTOP-S8EV48S:~/REDIS/REDIS_PYTHON/ru102py# pytest ./tests/test_hello.py
FAIL!!!

2-) now the good old redis that I have in my godaddy domain:

(env) root@DESKTOP-S8EV48S:~/REDIS/REDIS_PYTHON/ru102py# export REDIS_HOST=redis.platformengineer.io
(env) root@DESKTOP-S8EV48S:~/REDIS/REDIS_PYTHON/ru102py# pytest ./tests/test_hello.py
SUCCESS!!!
<...> 1 passed in 2.08s

Cheers!

Override configuration with environment variables if they exist.

Hey, team. This is your friend Gabs from Harness, and I have a quick suggestion to allow us to provide some important configuration that overrides the config file app.config when necessary.

For example, during my CD Pipeline, I will retrieve the Redis details from a Vault Server, using Harness expressions (<+secrets.getValue("redis_host")>) and use it in the K8s Deployment -> Pod -> Container environment variables.

For example, I create a Secret or a Configmap to hold these, but then I serve the variables for the python app at runtime, with K8s's envFrom.

Cheers!
@gacerioni
Copy link
Author

Howdy! Can ping me on https://www.linkedin.com/in/gabrielcerioni

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant