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

fix(snap): Refactor to avoid conflicts with readonly config provider directory #354

Merged
merged 5 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions snap/local/bin/source-env-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ BINPATH="${ARGV[0]}"

# binary name == service name/key
SERVICE=$(basename "$BINPATH")
SERVICE_ENV="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env"
ENV_FILE="$SNAP_DATA/config/$SERVICE/overrides.env"
TAG="edgex-$SERVICE."$(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
set +o allexport
source "$ENV_FILE" set
set +o allexport
fi

exec "$@"

2 changes: 1 addition & 1 deletion snap/local/helper-go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/edgexfoundry/device-virtual-go/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-20230315092647-3e5be341fbd0
4 changes: 2 additions & 2 deletions snap/local/helper-go/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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-20230315092647-3e5be341fbd0 h1:JfHMf7jDblOMgFBbJpLI4srXjQolVDNJmsT8M6oumKY=
github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230315092647-3e5be341fbd0/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY=
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=
Expand Down
12 changes: 10 additions & 2 deletions snap/local/helper-go/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

func installConfig() error {
Expand All @@ -38,7 +39,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)
}
}
}