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): add support for env var injection #160

Merged
merged 1 commit into from
Apr 26, 2022

Conversation

farshidtz
Copy link
Member

@farshidtz farshidtz commented Apr 25, 2022

For details on the new scheme for setting environment variables, please refer to edgexfoundry/edgex-go#3986.

Signed-off-by: Farshid Tavakolizadeh [email protected]

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/app-rfid-llrp-inventory/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?): Add tests for snap config options canonical/edgex-snap-testing#53
  • 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?)

Testing Instructions

  1. Set up:
snap install edgexfoundry --edge
snap install edgex-device-snmp --channel=edge/pr-160
  1. Enable config and set a global config value:
$ snap set edgex-device-snmp config-enabled=true
$ snap set edgex-device-snmp config.service-startupmsg="testing injection"

$ snap start edgex-device-snmp
Started.

$ snap logs -n=all edgex-device-snmp | grep "testing"
2022-04-26T10:33:16+02:00 edgex-device-snmp.device-snmp[41697]: ++ export 'SERVICE_STARTUPMSG=testing injection'
2022-04-26T10:33:16+02:00 edgex-device-snmp.device-snmp[41697]: ++ SERVICE_STARTUPMSG='testing injection'
2022-04-26T10:33:16+02:00 edgex-device-snmp.device-snmp[41697]: level=INFO ts=2022-04-26T08:33:16.892242677Z app=device-snmp source=variables.go:352 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=testing injection"
2022-04-26T10:33:16+02:00 edgex-device-snmp.device-snmp[41697]: level=INFO ts=2022-04-26T08:33:16.942854875Z app=device-snmp source=message.go:55 msg="testing injection"
  1. Set a app-specific value:
$ snap set edgex-device-snmp apps.device-snmp.config.service-port=11111

$ snap restart edgex-device-snmp
Restarted.

$ snap logs -n=all edgex-device-snmp | grep "11111"
2022-04-26T10:14:12+02:00 edgex-device-snmp.device-snmp[33387]: ++ export SERVICE_PORT=11111
2022-04-26T10:14:12+02:00 edgex-device-snmp.device-snmp[33387]: ++ SERVICE_PORT=11111
2022-04-26T10:14:12+02:00 edgex-device-snmp.device-snmp[33387]: level=INFO ts=2022-04-26T08:14:12.464790178Z app=device-snmp source=variables.go:352 msg="Variables override of 'Service.Port' by environment variable: SERVICE_PORT=11111"
2022-04-26T10:14:12+02:00 edgex-device-snmp.device-snmp[33387]: level=INFO ts=2022-04-26T08:14:12.515347747Z app=device-snmp source=httpserver.go:123 msg="Web server starting (localhost:11111)"

New Dependency Instructions (If applicable)

@codecov-commenter
Copy link

Codecov Report

Merging #160 (982e461) into main (6b046bf) will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff          @@
##            main    #160   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files          2       2           
  Lines        200     200           
=====================================
  Misses       200     200           

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 6b046bf...982e461. Read the comment docs.

@farshidtz farshidtz marked this pull request as ready for review April 26, 2022 08:37
@farshidtz
Copy link
Member Author

@MonicaisHer please review.

Copy link
Contributor

@MonicaisHer MonicaisHer left a comment

Choose a reason for hiding this comment

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

@farshidtz Thank you. It works as expected.

Validate error handling:

$ snap set edgex-device-snmp config.service-startupmsg="testing injection"
error: cannot perform the following tasks:
- Run configure hook of "edgex-device-snmp" snap (run hook "configure": 
-----
edgex-device-snmp.configure: could not process options: 'config.' and 'apps.' options are allowed only when config-enabled is true.

WARNING: Setting config-enabled=true will unset existing 'env.' options and ignore future sets!!
-----)

$ snap set edgex-device-snmp config-enabled=true
$ snap set edgex-device-snmp config.service.startupmsg="testing injection"
error: cannot perform the following tasks:
- Run configure hook of "edgex-device-snmp" snap (run hook "configure": edgex-device-snmp.configure: could not process options: error converting config key to environment variable key: config key must not contain dots: service.startupmsg)

Test:

$ snap set edgex-device-snmp config.service-startupmsg="testing injection"
$ snap start edgex-device-snmp
Started.

$ snap logs -n=all edgex-device-snmp | grep "testing"
2022-04-26T11:47:03+02:00 edgex-device-snmp.device-snmp[1762787]: ++ export 'SERVICE_STARTUPMSG=testing injection'
2022-04-26T11:47:03+02:00 edgex-device-snmp.device-snmp[1762787]: ++ SERVICE_STARTUPMSG='testing injection'
2022-04-26T11:47:04+02:00 edgex-device-snmp.device-snmp[1762787]: level=INFO ts=2022-04-26T09:47:04.323706439Z app=device-snmp source=variables.go:352 msg="Variables override of 'Service.StartupMsg' by environment variable: SERVICE_STARTUPMSG=testing injection"
2022-04-26T11:47:04+02:00 edgex-device-snmp.device-snmp[1762787]: level=INFO ts=2022-04-26T09:47:04.36831019Z app=device-snmp source=message.go:55 msg="testing injection"

$ snap set edgex-device-snmp apps.device-snmp.config.service-port=11111
$ snap restart edgex-device-snmp
Restarted.

$ snap logs -n=all edgex-device-snmp | grep "11111"
2022-04-26T11:47:39+02:00 edgex-device-snmp.device-snmp[1763017]: ++ export SERVICE_PORT=11111
2022-04-26T11:47:39+02:00 edgex-device-snmp.device-snmp[1763017]: ++ SERVICE_PORT=11111
2022-04-26T11:47:39+02:00 edgex-device-snmp.device-snmp[1763017]: level=INFO ts=2022-04-26T09:47:39.10975401Z app=device-snmp source=variables.go:352 msg="Variables override of 'Service.Port' by environment variable: SERVICE_PORT=11111"
2022-04-26T11:47:39+02:00 edgex-device-snmp.device-snmp[1763017]: level=INFO ts=2022-04-26T09:47:39.135056084Z app=device-snmp source=httpserver.go:123 msg="Web server starting (localhost:11111)"

@lenny-goodell lenny-goodell merged commit 9a3dba1 into edgexfoundry:main Apr 26, 2022
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.

4 participants