Skip to content

Conversation

@chetanmeh
Copy link
Member

@chetanmeh chetanmeh commented May 23, 2018

Provides a way to extend the environment variable set for Controller and Invoker

Description

As mentioned in #3477 for some set of deployments like those using CosmosDB we need to add some extra environment variables like CONFIG_whisk_spi_ArtifactStoreProvider. To support that ansible playbook now supports add a set of environment variables conditionally.

Usage

To add extra environment variables user need to define them under group_vars/all for specific environment

cosmos:
    CONFIG_whisk_spi_ArtifactStoreProvider: whisk.core.database.cosmosdb.CosmosDBArtifactStoreProvider
    CONFIG_whisk_cosmosdb_endpoint : "https://<account name>.documents.azure.com:443/"
    CONFIG_whisk_cosmosdb_key : "some secret"
    CONFIG_whisk_cosmosdb_db : openwhisk

Here cosmos is the name of the environment variable set related to CosmosDB. To enable this set user needs to set an environment vairable

OPENWHISK_EXTRA_ENV=cosmos

Here OPENWHISK_EXTRA_ENV refers to a comma separated list of environment variable set which need to be added. If configured then all variables defined under cosmos key would be added to env of controller and invoker

Related issue and scope

My changes affect the following components

  • API
  • Controller
  • Message Bus (e.g., Kafka)
  • Loadbalancer
  • Invoker
  • Intrinsic actions (e.g., sequences, conductors)
  • Data stores (e.g., CouchDB)
  • Tests
  • Deployment
  • CLI
  • General tooling
  • Documentation

Types of changes

  • Bug fix (generally a non-breaking change which closes an issue).
  • Enhancement or new feature (adds new functionality).
  • Breaking change (a bug fix or enhancement which changes existing behavior).

Checklist:

  • I signed an Apache CLA.
  • I reviewed the style guides and followed the recommendations (Travis CI will check :).
  • I added tests to cover my changes.
  • My changes require further changes to the documentation.
  • I updated the documentation where necessary.

@chetanmeh chetanmeh changed the title Extend env 3477 Enable extending environment variables of Controller and Invoker May 23, 2018
controller_env: "{{ controller_env | default({}) | combine(item) }}"
with_items: "{{ extraEnvSets.split(',') | map('trim') | map('extract', vars)| list }}"
loop_control:
label: redacted
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ansible would by default emit the item value to stdout. As the values may contain secrets set the label to a constant

@codecov-io
Copy link

codecov-io commented May 23, 2018

Codecov Report

Merging #3689 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3689      +/-   ##
==========================================
+ Coverage      75%   75.02%   +0.01%     
==========================================
  Files         127      127              
  Lines        6030     6030              
  Branches      388      388              
==========================================
+ Hits         4523     4524       +1     
+ Misses       1507     1506       -1
Impacted Files Coverage Δ
...rc/main/scala/whisk/common/ForcableSemaphore.scala 88.46% <0%> (+3.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0134f78...8fec3f5. Read the comment docs.

# license agreements; and to You under the Apache License, Version 2.0.

whisk_version_name: local
extraEnvSets: "{{ lookup('env', 'OPENWHISK_EXTRA_ENV_SETS')|default(false, true) }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not assume that is one top level set and force on both controller and invoker
Maybe user wants to set certain config or secret that is intended for controller but not invoker.
Or you want to set the same variable ie apikey to the db and is different for both controller and invoker.

What about having namespace with option to override

invoker:
   extraEnv: "{{ invoker_extra_env | lookup('env', 'OPENWHISK_EXTRA_ENV') | default(false, true) }}"

controller:
   extraEnv: "{{ controller_extra_env | lookup('env', 'OPENWHISK_EXTRA_ENV') | default(false, true) }}"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Update PR to support specific env for controller and invoker. By default they both rely on OPENWHISK_EXTRA_ENV. However one can change the setting in environment specific file.

Not sure on best practices for placing the vars in ansible ... for now I have added them to local/group_vars/all such that one can use a different setting in specific env

ansible/environments/custom/group_vars
controller:
   extraEnv: "cosmos,splunk"

@csantanapr
Copy link
Member

Hey @chetanmeh please review the commit I just pushed fd35871
It's was what I was proposing we do is much simpler, it allows override from an environment.
Also it does proper combine using dict in ansible

Now you are able to edit your own environment like environment/local and add something like

controller_extraEnv:
  CONFIG_whisk_cosmosdb_endpoint : "https://<account name>.documents.azure.com:443/"
  CONFIG_whisk_cosmosdb_key : "some secret"
  CONFIG_whisk_cosmosdb_db : openwhisk
invoker_extraEnv:
  CONFIG_whisk_cosmosdb_endpoint : "https://<account name>.documents.azure.com:443/"
  CONFIG_whisk_cosmosdb_key : "some secret"
  CONFIG_whisk_cosmosdb_db : openwhisk

You can do it like this ^^ or in your environment load an environment variable into the environment file, or override using ansible-playbook -e

@chetanmeh
Copy link
Member Author

@csantanapr I needed this support for travis specially. There I want to have a way where just with a env variable switch I can make test run against Cosmos. So earlier plan was to define pre configured env set in local

cosmos:
    CONFIG_whisk_spi_ArtifactStoreProvider: whisk.core.database.cosmosdb.CosmosDBArtifactStoreProvider
    CONFIG_whisk_cosmosdb_endpoint : {{ lookup('env','COSMOSDB_ENDPOINT') }}
    CONFIG_whisk_cosmosdb_key : "{{ lookup('env','COSMOSDB_KEY') }}"
    CONFIG_whisk_cosmosdb_db : "{{ lookup('env','COSMOSDB_KEY') }}"

These env variables would then be configured via travis ui. And then in cosmos db stage of travis set

export OPENWHISK_EXTRA_ENV=cosmos

This way with minimal changes specific to Cosmos I can run test against it. Any pointers on how to achieve that with approach you proposed?

@csantanapr
Copy link
Member

to bring back the discussion offline with @chetanmeh
This PR adds the ability to add extra env variables to controller and invoker

He has a seperate PR for the Cosmos DB that will leverage this but adding a way to overload the spi for db in ansible in global group vars:

controller:
  db:
    spi: "{{ controller_db_spi | default('') }}"
invoker:
  db:
    spi: "{{ invoker_db_spi | default('') }}"

Then in travis the openwhisk.yml playbook can be run with -e invoker_db_spi=whisk.core.database.cosmosdb.CosmosDBArtifactStoreProvider for the cosmos db stage.

@csantanapr
Copy link
Member

PG 3 2312 🏃

- name: merge extra env variables
set_fact:
controller_env: "{{ controller_env | default({}) | combine(controller.extraEnv) }}"
when: controller.extraEnv | default(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the when needed in the first place? Shouldn't we be able to specify: extraEnv: "{{ controller_extraEnv | default({}) }}" and run the combine step no matter what?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed we need it the extra safety, your proposing just dropping the when line?
since in group_vars we already default to default({}) and extra check is not need it.

Copy link
Member

@csantanapr csantanapr May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see define the default {} and then drop the when I will give this a test and update

@csantanapr
Copy link
Member

PG1 2974 ⌛️

@csantanapr
Copy link
Member

PG 1 2976 🔵

@csantanapr csantanapr merged commit 8b6681a into apache:master Jun 1, 2018
BillZong pushed a commit to BillZong/openwhisk that referenced this pull request Nov 18, 2019
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.

5 participants