Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

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

Merged
merged 3 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 5 additions & 5 deletions snap/local/bin/source-env-file.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 4 additions & 4 deletions snap/local/helper-go/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ import (
"github.com/canonical/edgex-snap-hooks/v3/options"
)

func configure() {
const app = "kuiperd"
const daemonApp = "kuiperd"

func configure() {
log.SetComponentName("configure")

options.EnableConfigHierarchy()
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)
}
}
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/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
2 changes: 2 additions & 0 deletions snap/local/helper-go/go.sum
Original file line number Diff line number Diff line change
@@ -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=
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"
)

// installConfig copies all config files from $SNAP to $SNAP_DATA.
Expand All @@ -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("ekuiper-data").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)
}
}
}