From c2f6aef41b644714e1771e97868877555508b748 Mon Sep 17 00:00:00 2001 From: Siggi Skulason Date: Thu, 24 Mar 2022 00:05:04 +0000 Subject: [PATCH 1/7] feat(snap): use updated environment variable injection Signed-off-by: Siggi Skulason --- snap/local/hooks/cmd/configure/configure.go | 24 +++++++++++++++++++++ snap/local/hooks/cmd/configure/main.go | 1 + snap/local/hooks/go.mod | 2 +- snap/local/hooks/go.sum | 4 ++-- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/snap/local/hooks/cmd/configure/configure.go b/snap/local/hooks/cmd/configure/configure.go index 35bdc67f98..3787ed76d8 100644 --- a/snap/local/hooks/cmd/configure/configure.go +++ b/snap/local/hooks/cmd/configure/configure.go @@ -26,6 +26,7 @@ import ( "strings" hooks "github.com/canonical/edgex-snap-hooks/v2" + snaphookoptions "github.com/canonical/edgex-snap-hooks/v2/options" ) const ( // iota is reset to 0 @@ -601,3 +602,26 @@ func configure() { } } } + +func configureApps() { + hooks.Info("edgexfoundry:configure Processing apps.* and config.* configuration") + err := snaphookoptions.ProcessOptions( + "core-data", + "core-metadata", + "core-command", + "support-notifications", + "support-scheduler", + "app-service-configurable", + "device-virtual", + "security-secret-store", + "security-secretstore-setup", + "security-proxy-setup", + "security-bootstrapper", + "sys-mgmgt-agent") + + if err != nil { + hooks.Error(fmt.Sprintf("edgexfoundry:configure could not process options: %v", err)) + os.Exit(1) + } + +} diff --git a/snap/local/hooks/cmd/configure/main.go b/snap/local/hooks/cmd/configure/main.go index d1b269d771..e5d8401206 100644 --- a/snap/local/hooks/cmd/configure/main.go +++ b/snap/local/hooks/cmd/configure/main.go @@ -29,6 +29,7 @@ func main() { if len(os.Args) == 1 { // configure everything configure() + configureApps() return } diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index 53536ccc94..0d6427d02a 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,5 +1,5 @@ module github.com/canonical/edgex-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.1.3 +require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta go 1.17 diff --git a/snap/local/hooks/go.sum b/snap/local/hooks/go.sum index 039e14dc08..8099aab659 100644 --- a/snap/local/hooks/go.sum +++ b/snap/local/hooks/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v2 v2.1.3 h1:mcV/atn6k6sN6Uik+lSQGEZi4Q6r96epgBW+u6AGZ3Y= -github.com/canonical/edgex-snap-hooks/v2 v2.1.3/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta h1:FblUp4/cn7Qk1PJzXR6NfN8eFAHLilVHv7eFCp6Jvv0= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From 9d02839a2fca642b336364ec709521940e0b257d Mon Sep 17 00:00:00 2001 From: Siggi Skulason Date: Wed, 30 Mar 2022 20:05:57 +0100 Subject: [PATCH 2/7] feat(snap): use updated environment variable injection Signed-off-by: Siggi Skulason --- snap/local/hooks/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index 0d6427d02a..dae41097fb 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,5 +1,5 @@ module github.com/canonical/edgex-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta +require github.com/canonical/edgex-snap-hooks/v2 v2.2.0 go 1.17 From 3744ca2e470ec7bd45e69fab73b26887afd5eece Mon Sep 17 00:00:00 2001 From: siggi Date: Fri, 1 Apr 2022 13:05:42 +0100 Subject: [PATCH 3/7] feat(snap): use updated environment variable injection Use ProcessAppConfig instead of ProcessOptions Signed-off-by: siggi --- snap/local/hooks/cmd/configure/configure.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/local/hooks/cmd/configure/configure.go b/snap/local/hooks/cmd/configure/configure.go index 3787ed76d8..c3e668cd50 100644 --- a/snap/local/hooks/cmd/configure/configure.go +++ b/snap/local/hooks/cmd/configure/configure.go @@ -605,7 +605,7 @@ func configure() { func configureApps() { hooks.Info("edgexfoundry:configure Processing apps.* and config.* configuration") - err := snaphookoptions.ProcessOptions( + err := snaphookoptions.ProcessAppConfig( "core-data", "core-metadata", "core-command", From 4a7468f1b4c3eb1dc700504b11e06a6d3f50f24d Mon Sep 17 00:00:00 2001 From: siggi Date: Fri, 1 Apr 2022 13:40:36 +0100 Subject: [PATCH 4/7] feat(snap): use updated environment variable injection Signed-off-by: siggi --- snap/local/hooks/go.mod | 2 +- snap/local/hooks/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index dae41097fb..1a9e550938 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,5 +1,5 @@ module github.com/canonical/edgex-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.2.0 +require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2 go 1.17 diff --git a/snap/local/hooks/go.sum b/snap/local/hooks/go.sum index 8099aab659..9b0212d22f 100644 --- a/snap/local/hooks/go.sum +++ b/snap/local/hooks/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta h1:FblUp4/cn7Qk1PJzXR6NfN8eFAHLilVHv7eFCp6Jvv0= -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2 h1:HMh7QgZaJmlu3kAEGEgr1PJTr8nbfsQSWLmYuWeuPhI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From 327cf1d3476a2d15cdfd2433c47356c9560b3006 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Fri, 22 Apr 2022 15:22:56 +0200 Subject: [PATCH 5/7] feat(snap): add proxy option handling, bump mod Signed-off-by: Farshid Tavakolizadeh --- snap/local/hooks/cmd/configure/configure.go | 24 --------- snap/local/hooks/cmd/configure/main.go | 5 +- snap/local/hooks/cmd/configure/options.go | 52 +++++++++++++++++++ snap/local/hooks/go.mod | 3 +- snap/local/hooks/go.sum | 4 +- .../bin/security-proxy-post-setup.sh | 3 ++ 6 files changed, 62 insertions(+), 29 deletions(-) diff --git a/snap/local/hooks/cmd/configure/configure.go b/snap/local/hooks/cmd/configure/configure.go index c3e668cd50..35bdc67f98 100644 --- a/snap/local/hooks/cmd/configure/configure.go +++ b/snap/local/hooks/cmd/configure/configure.go @@ -26,7 +26,6 @@ import ( "strings" hooks "github.com/canonical/edgex-snap-hooks/v2" - snaphookoptions "github.com/canonical/edgex-snap-hooks/v2/options" ) const ( // iota is reset to 0 @@ -602,26 +601,3 @@ func configure() { } } } - -func configureApps() { - hooks.Info("edgexfoundry:configure Processing apps.* and config.* configuration") - err := snaphookoptions.ProcessAppConfig( - "core-data", - "core-metadata", - "core-command", - "support-notifications", - "support-scheduler", - "app-service-configurable", - "device-virtual", - "security-secret-store", - "security-secretstore-setup", - "security-proxy-setup", - "security-bootstrapper", - "sys-mgmgt-agent") - - if err != nil { - hooks.Error(fmt.Sprintf("edgexfoundry:configure could not process options: %v", err)) - os.Exit(1) - } - -} diff --git a/snap/local/hooks/cmd/configure/main.go b/snap/local/hooks/cmd/configure/main.go index e5d8401206..5be00c478e 100644 --- a/snap/local/hooks/cmd/configure/main.go +++ b/snap/local/hooks/cmd/configure/main.go @@ -27,9 +27,10 @@ var cli *hooks.CtlCli = hooks.NewSnapCtl() func main() { // no subcommand, as called by snapd if len(os.Args) == 1 { - // configure everything + // process the EdgeX >=2.2 snap options + processAppOptions() + // configure everything else, incl. the legacy snap options configure() - configureApps() return } diff --git a/snap/local/hooks/cmd/configure/options.go b/snap/local/hooks/cmd/configure/options.go index 2876ec7208..d38567740c 100644 --- a/snap/local/hooks/cmd/configure/options.go +++ b/snap/local/hooks/cmd/configure/options.go @@ -22,6 +22,7 @@ import ( "os" hooks "github.com/canonical/edgex-snap-hooks/v2" + app_options "github.com/canonical/edgex-snap-hooks/v2/options" ) func applyConfigOptions(service string) error { @@ -60,8 +61,59 @@ func options() { hooks.Info("edgexfoundry:configure-options: handling config options for a single service: " + *service) + // process the EdgeX >=2.2 snap options + err = app_options.ProcessAppCustomOptions(*service) + if err != nil { + hooks.Error(fmt.Sprintf("edgexfoundry:configure-options: could not process custom options: %v", err)) + os.Exit(1) + } + + // process the legacy snap options if err := applyConfigOptions(*service); err != nil { hooks.Error(fmt.Sprintf("edgexfoundry:configure-options: error handling config options for %s: %v", *service, err)) os.Exit(1) } } + +func processAppOptions() { + err := app_options.ProcessAppConfig( + "core-data", + "core-metadata", + "core-command", + "support-notifications", + "support-scheduler", + "app-service-configurable", + "device-virtual", + "security-secret-store", + "security-secretstore-setup", + "security-proxy-setup", + "security-bootstrapper", + "sys-mgmgt-agent", + ) + if err != nil { + hooks.Error(fmt.Sprintf("edgexfoundry:configure could not process config options: %v", err)) + os.Exit(1) + } + + // After installation, the configure hook initiates the deferred startup of services, + // processes snap options and exits. The actual services startup happens only + // after the configure hook exits. + // + // The following options should not be processed within the configure hook during + // the initial installation (install-mode=defer-startup). They should be processed + // only on follow-up calls to the configure hook (i.e. when snap set/unset is called) + installMode, err := hooks.NewSnapCtl().Config("install-mode") // this set in the install hook + if err != nil { + hooks.Error(fmt.Sprintf("edgexfoundry:configure failed to read 'install-mode': %s", err)) + os.Exit(1) + } + if installMode != "defer-startup" { + err = app_options.ProcessAppCustomOptions( + "secrets-config", // also processed in security-proxy-post-setup.sh + ) + if err != nil { + hooks.Error(fmt.Sprintf("edgexfoundry:configure: could not process custom options: %v", err)) + os.Exit(1) + } + } +} diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index 1a9e550938..4822aa77ce 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,5 +1,6 @@ module github.com/canonical/edgex-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2 +require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3 + go 1.17 diff --git a/snap/local/hooks/go.sum b/snap/local/hooks/go.sum index 9b0212d22f..0a09dcd06a 100644 --- a/snap/local/hooks/go.sum +++ b/snap/local/hooks/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2 h1:HMh7QgZaJmlu3kAEGEgr1PJTr8nbfsQSWLmYuWeuPhI= -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3 h1:kQ7tGjA7k6iAfsvLRKpdoLy0zwsG+4Wqn3DNkbJrhZ8= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh b/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh index 066decdb49..90751a196b 100755 --- a/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh +++ b/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh @@ -11,3 +11,6 @@ export PATH="$SNAP/bin:$PATH" # Several config options depend on resources that only exist after proxy # setup. This re-applies the config options logic after deferred startup: $SNAP/snap/hooks/configure options --service=security-proxy + +# Process the EdgeX >=2.2 snap options +$SNAP/snap/hooks/configure options --service=secrets-config From 164276654257e42004c472ad1fba05155714cab8 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 15:34:32 +0200 Subject: [PATCH 6/7] feat: upgrade edgex-snap-hooks to remove support for complex config keys https://github.com/canonical/edgex-snap-hooks/pull/45 Signed-off-by: Farshid Tavakolizadeh --- snap/local/hooks/go.mod | 2 +- snap/local/hooks/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index 4822aa77ce..e2855a75be 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,6 +1,6 @@ module github.com/canonical/edgex-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3 +require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.4 go 1.17 diff --git a/snap/local/hooks/go.sum b/snap/local/hooks/go.sum index 0a09dcd06a..5ad5144be4 100644 --- a/snap/local/hooks/go.sum +++ b/snap/local/hooks/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3 h1:kQ7tGjA7k6iAfsvLRKpdoLy0zwsG+4Wqn3DNkbJrhZ8= -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.4 h1:mbHxD8lIv3ewSUSkwqXj4SEVek2bvw5Nh/+gngInscI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.4/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From 1d3cb66f23cd7c6c81c28b68602ea332c4e91132 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 25 Apr 2022 16:45:48 +0200 Subject: [PATCH 7/7] build: bump edgex-snap-hooks for env value bugfix https://github.com/canonical/edgex-snap-hooks/pull/46 Signed-off-by: Farshid Tavakolizadeh --- snap/local/hooks/go.mod | 4 +++- snap/local/hooks/go.sum | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index e2855a75be..592ec830e0 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,6 +1,8 @@ module github.com/canonical/edgex-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.4 +require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.5 +// replace github.com/canonical/edgex-snap-hooks/v2 => ./edgex-snap-hooks +// replace github.com/canonical/edgex-snap-hooks/v2 => github.com/farshidtz/edgex-snap-hooks/v2 d43ccc771100d663099c8ca8e3974d78076b2058 go 1.17 diff --git a/snap/local/hooks/go.sum b/snap/local/hooks/go.sum index 5ad5144be4..207bcb21d9 100644 --- a/snap/local/hooks/go.sum +++ b/snap/local/hooks/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.4 h1:mbHxD8lIv3ewSUSkwqXj4SEVek2bvw5Nh/+gngInscI= -github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.4/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.5 h1:EDFjmHy8CG4T8uFPqD+Per8Hgk250PvRsMgEDCXjYtE= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.5/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=