Skip to content

Commit

Permalink
feat: Use env vars to set config file
Browse files Browse the repository at this point in the history
* Set DB pointer for CEEMS LB only when exists

Signed-off-by: Mahendra Paipuri <mahendra.paipuri@gmail.com>
  • Loading branch information
mahendrapaipuri committed Jun 18, 2024
1 parent 673c104 commit af7205d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/api/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ func (b *CEEMSServer) Main() error {
webConfigFile = b.App.Flag(
"web.config.file",
"Path to configuration file that can enable TLS or authentication. See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md",
).Default("").String()
).Envar("CEEMS_API_SERVER_WEB_CONFIG_FILE").Default("").String()
configFile = b.App.Flag(
"config.file",
"Path to CEEMS API server configuration file.",
).Default("").String()
).Envar("CEEMS_API_SERVER_CONFIG_FILE").Default("").String()

// Testing related hidden CLI args
skipDeleteOldUnits = b.App.Flag(
Expand Down
4 changes: 2 additions & 2 deletions pkg/lb/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ func (lb *CEEMSLoadBalancer) Main() error {
webConfigFile = lb.App.Flag(
"web.config.file",
"Path to configuration file that can enable TLS or authentication. See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md",
).Default("").String()
).Envar("CEEMS_LB_WEB_CONFIG_FILE").Default("").String()
configFile = lb.App.Flag(
"config.file",
"Configuration file path.",
).Default("").String()
).Envar("CEEMS_LB_CONFIG_FILE").Default("").String()
maxProcs = lb.App.Flag(
"runtime.gomaxprocs", "The target number of CPUs Go will run on (GOMAXPROCS)",
).Envar("GOMAXPROCS").Default("1").Int()
Expand Down
9 changes: 7 additions & 2 deletions pkg/lb/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"slices"
"strings"
Expand Down Expand Up @@ -84,8 +85,12 @@ func NewLoadBalancer(c *Config) (LoadBalancer, error) {
return nil, err
}

if db, err = sql.Open("sqlite3", dbAbsPath); err != nil {
return nil, err
// Set DB pointer only if file exists. Else sql.Open will create an empty
// file as if exists already
if _, err := os.Stat(dbAbsPath); err == nil {
if db, err = sql.Open("sqlite3", dbAbsPath); err != nil {
return nil, err
}
}
}

Expand Down

0 comments on commit af7205d

Please sign in to comment.