Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snap): use updated environment variable injection #3924

Closed
wants to merge 4 commits into from
Closed

feat(snap): use updated environment variable injection #3924

wants to merge 4 commits into from

Conversation

siggiskulason
Copy link

@siggiskulason siggiskulason commented Mar 24, 2022

Signed-off-by: Siggi Skulason [email protected]

This PR updates edgex-go to use the new environment variable injection.

apps.<app>.config.<my.env.var> -> setting env var MY_ENV_VAR for an app (e.g. apps.core-data.config.service.port=1000)
config.<my.env.var> -> setting env variable for all apps (e.g. config.service.host=localhost)

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?) N/A - they are in the imported module
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?) N/A

Testing Instructions

Do

sudo snap set edgexfoundry env.core-data.service.host=localhost
sudo snap set edgexfoundry apps.core-data.config.service.port=8080
sudo snap set edgexfoundry config.debug=true
  1. Confirm that all .env files have DEBUG=true
  2. Confirm that the core-data .env file also has both the SERVICE_HOST and SERVICE_PORT settings
$ more /var/snap/edgexfoundry/current/config/core-data/res/core-data.env 
export SERVICE_HOST=localhost
export DEBUG=true
export SERVICE_PORT=8080
$ more /var/snap/edgexfoundry/current/config/core-command/res/core-command.env 
export DEBUG=true


New Dependency Instructions (If applicable)

@siggiskulason siggiskulason changed the title feat(snap): use updated environment variable injection [WIP] feat(snap): use updated environment variable injection Mar 30, 2022
@siggiskulason siggiskulason marked this pull request as ready for review March 30, 2022 19:12
@siggiskulason siggiskulason requested a review from farshidtz March 30, 2022 19:12
siggi added 2 commits April 1, 2022 13:05
Use ProcessAppConfig instead of ProcessOptions

Signed-off-by: siggi <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 1, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@siggiskulason
Copy link
Author

@farshidtz - this is now ready for review- it uses version v2.2.0-beta.2 of the snap hooks.

Copy link
Member

@farshidtz farshidtz left a comment

Choose a reason for hiding this comment

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

It works according to the given instructions:

$ sudo snap set edgexfoundry env.core-data.service.host=localhost
$ sudo snap set edgexfoundry apps.core-data.config.service.port=8080
$ sudo snap set edgexfoundry config.debug=true

$ cat /var/snap/edgexfoundry/current/config/core-data/res/core-data.env 
export SERVICE_HOST=localhost
export DEBUG=true
export SERVICE_PORT=8080

$ cat /var/snap/edgexfoundry/current/config/core-command/res/core-command.env
export DEBUG=true

But there is a bug for services that don't have env.* legacy options and only the new ones:

  1. env vars keep getting appended to the env files:
$ sudo snap set edgexfoundry apps.core-command.config.x=true
$ sudo snap set edgexfoundry apps.core-command.config.x=true
$ sudo snap set edgexfoundry apps.core-command.config.x=true
$ cat /var/snap/edgexfoundry/current/config/core-command/res/core-command.env
export DEBUG=true
export X=true
export X=true
export X=true
  1. unset does not remove the env var:
$ sudo snap unset edgexfoundry apps.core-command.config.x
$ cat /var/snap/edgexfoundry/current/config/core-command/res/core-command.env
export DEBUG=true
export X=true
export X=true
export X=true

As discussed with @siggiskulason, this is because the new functions try to be backwards compatible by appending to env files, while the old functions always read all snap options and write the env file from scratch.

@farshidtz
Copy link
Member

Thanks @siggiskulason for this addition. I've added a new PR (#3986) with some fixes and additions.

I'm going to close this in favor of the other PR.

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.

2 participants