From abde226c32ba95bf37cdce0bb69e9d345f610afb Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Fri, 17 Mar 2023 17:01:20 +0100 Subject: [PATCH 1/3] fix(snap): Refactor to avoid conflicts with readonly config provider directory Signed-off-by: Mengyi Wang --- snap/local/bin/source-env-file.sh | 10 +++++----- snap/local/helper-go/configure.go | 2 -- snap/local/helper-go/go.mod | 2 +- snap/local/helper-go/go.sum | 2 ++ snap/local/helper-go/install.go | 12 ++++++++++-- snap/local/helper-go/main.go | 2 ++ 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/snap/local/bin/source-env-file.sh b/snap/local/bin/source-env-file.sh index 5deb2c2..461c41a 100755 --- a/snap/local/bin/source-env-file.sh +++ b/snap/local/bin/source-env-file.sh @@ -1,13 +1,13 @@ -#!/bin/bash -e +#!/bin/bash -ex SERVICE="kuiperd" -SERVICE_ENV="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env" +ENV_FILE="$SNAP_DATA/config/$SERVICE/res/overrides.env" TAG="$SNAP_INSTANCE_NAME."$(basename "$0") -if [ -f "$SERVICE_ENV" ]; then - logger --tag=$TAG "Sourcing $SERVICE_ENV" +if [ -f "$ENV_FILE" ]; then + logger --tag=$TAG "Sourcing $ENV_FILE" set -o allexport - source "$SERVICE_ENV" set + source "$ENV_FILE" set set +o allexport fi diff --git a/snap/local/helper-go/configure.go b/snap/local/helper-go/configure.go index 7f6ca11..5a82282 100644 --- a/snap/local/helper-go/configure.go +++ b/snap/local/helper-go/configure.go @@ -22,8 +22,6 @@ import ( ) func configure() { - const app = "kuiperd" - log.SetComponentName("configure") options.EnableConfigHierarchy() diff --git a/snap/local/helper-go/go.mod b/snap/local/helper-go/go.mod index 4d4ef6f..bddbed2 100644 --- a/snap/local/helper-go/go.mod +++ b/snap/local/helper-go/go.mod @@ -2,4 +2,4 @@ module github.com/canonical/edgex-ekuiper-snap/snap/local/helper-go go 1.18 -require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab +require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230315153603-544c6823a1b0 diff --git a/snap/local/helper-go/go.sum b/snap/local/helper-go/go.sum index 8119883..7b59d34 100644 --- a/snap/local/helper-go/go.sum +++ b/snap/local/helper-go/go.sum @@ -1,5 +1,7 @@ github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab h1:wpiKN0hX8tqeZNa4jPvgyrqP8ixm1Xu7lcQA3bypR7w= github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY= +github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230315153603-544c6823a1b0 h1:h2C5W3mEC5g/s9W/mwh7X/3uSqKjNln/xHP41i8Mw/M= +github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230315153603-544c6823a1b0/go.mod h1:qGZwprCZGZk2pA9BrleUtSrGrfHIaIz1356p8aqzuN4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= diff --git a/snap/local/helper-go/install.go b/snap/local/helper-go/install.go index d951fb0..c8460f0 100644 --- a/snap/local/helper-go/install.go +++ b/snap/local/helper-go/install.go @@ -20,6 +20,7 @@ import ( hooks "github.com/canonical/edgex-snap-hooks/v3" "github.com/canonical/edgex-snap-hooks/v3/env" "github.com/canonical/edgex-snap-hooks/v3/log" + "github.com/canonical/edgex-snap-hooks/v3/snapctl" ) // installConfig copies all config files from $SNAP to $SNAP_DATA. @@ -39,7 +40,14 @@ func installConfig() error { func install() { log.SetComponentName("install") - if err := installConfig(); err != nil { - log.Fatalf("Error installing config files: %s", err) + // Install default config files only if no config provider is connected + isConnected, err := snapctl.IsConnected(app + "-config").Run() + if err != nil { + log.Fatalf("Error checking interface connection: %s", err) + } + if !isConnected { + if err := installConfig(); err != nil { + log.Fatalf("Error installing config files: %s", err) + } } } diff --git a/snap/local/helper-go/main.go b/snap/local/helper-go/main.go index 86c4308..11c53fe 100644 --- a/snap/local/helper-go/main.go +++ b/snap/local/helper-go/main.go @@ -19,6 +19,8 @@ import ( "os" ) +const app = "kuiperd" + func main() { subCommand := os.Args[1] switch subCommand { From b1d763cb10edeaf655fa459b10f40a66c85f01c1 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Mon, 20 Mar 2023 10:35:47 +0100 Subject: [PATCH 2/3] Update config interface slot name, and app name --- snap/local/helper-go/configure.go | 6 ++++-- snap/local/helper-go/install.go | 2 +- snap/local/helper-go/main.go | 2 -- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/snap/local/helper-go/configure.go b/snap/local/helper-go/configure.go index 5a82282..fa70b4b 100644 --- a/snap/local/helper-go/configure.go +++ b/snap/local/helper-go/configure.go @@ -21,6 +21,8 @@ import ( "github.com/canonical/edgex-snap-hooks/v3/options" ) +const daemonApp = "kuiperd" + func configure() { log.SetComponentName("configure") @@ -28,11 +30,11 @@ func configure() { options.SetHierarchySeparator("__") options.SetSegmentSeparator("_") - if err := options.ProcessConfig(app); err != nil { + if err := options.ProcessConfig(daemonApp); err != nil { log.Fatalf("Error processing config options: %v", err) } - if err := options.ProcessAutostart(app); err != nil { + if err := options.ProcessAutostart(daemonApp); err != nil { log.Fatalf("Error processing autostart options: %v", err) } } diff --git a/snap/local/helper-go/install.go b/snap/local/helper-go/install.go index c8460f0..5a3b0b5 100644 --- a/snap/local/helper-go/install.go +++ b/snap/local/helper-go/install.go @@ -41,7 +41,7 @@ func install() { log.SetComponentName("install") // Install default config files only if no config provider is connected - isConnected, err := snapctl.IsConnected(app + "-config").Run() + isConnected, err := snapctl.IsConnected("ekuiper-data").Run() if err != nil { log.Fatalf("Error checking interface connection: %s", err) } diff --git a/snap/local/helper-go/main.go b/snap/local/helper-go/main.go index 11c53fe..86c4308 100644 --- a/snap/local/helper-go/main.go +++ b/snap/local/helper-go/main.go @@ -19,8 +19,6 @@ import ( "os" ) -const app = "kuiperd" - func main() { subCommand := os.Args[1] switch subCommand { From 2f8a2c454ae6310532a008195312a61260482545 Mon Sep 17 00:00:00 2001 From: Mengyi Wang Date: Mon, 20 Mar 2023 12:53:19 +0100 Subject: [PATCH 3/3] Enable xtrace, update env file path Co-authored-by: Farshid Tavakolizadeh --- snap/local/bin/source-env-file.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snap/local/bin/source-env-file.sh b/snap/local/bin/source-env-file.sh index 461c41a..8556a14 100755 --- a/snap/local/bin/source-env-file.sh +++ b/snap/local/bin/source-env-file.sh @@ -1,7 +1,7 @@ -#!/bin/bash -ex +#!/bin/bash -e SERVICE="kuiperd" -ENV_FILE="$SNAP_DATA/config/$SERVICE/res/overrides.env" +ENV_FILE="$SNAP_DATA/config/$SERVICE/overrides.env" TAG="$SNAP_INSTANCE_NAME."$(basename "$0") if [ -f "$ENV_FILE" ]; then