Skip to content

Commit

Permalink
Update bot to use externally defined configs mounted from a ConfigMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonhasacat committed Feb 7, 2024
1 parent 41d5a18 commit ca681c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/bot/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bot
import (
"errors"
"fmt"
"github.com/VATUSA/discord-bot-v3/internal/config"
"github.com/VATUSA/discord-bot-v3/pkg/constants"
"gopkg.in/yaml.v3"
"io/ioutil"
Expand Down Expand Up @@ -66,17 +67,17 @@ func LoadServerConfig(configPath string) (*ServerConfig, error) {
if err != nil {
return nil, err
}
var config ServerConfig
err = yaml.Unmarshal(data, &config)
var cfg ServerConfig
err = yaml.Unmarshal(data, &cfg)
if err != nil {
return nil, err
}
// TODO: Validate that roles aren't duplicated
// TODO: Validate role criteria
return &config, nil
return &cfg, nil
}

var configs = LoadAllServerConfigOrPanic("./config/servers/")
var configs = LoadAllServerConfigOrPanic(config.CONFIG_PATH)

func GetServerConfig(id string) *ServerConfig {
cfg, ok := configs[id]
Expand Down
1 change: 1 addition & 0 deletions internal/config/vatusa.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ import "os"
import _ "github.com/joho/godotenv/autoload"

var VATUSA_API2_URL = os.Getenv("VATUSA_API2_URL")
var CONFIG_PATH = os.Getenv("CONFIG_PATH")
3 changes: 3 additions & 0 deletions manifest/bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ spec:
image: vatusa/discord-bot-v3
imagePullPolicy: IfNotPresent
command: ["/app/bot"]
env:
- name: CONFIG_PATH
value: "/mnt/config"
envFrom:
- secretRef:
name: discord-bot
Expand Down

0 comments on commit ca681c3

Please sign in to comment.