Skip to content

Commit

Permalink
add singletone
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <[email protected]>
  • Loading branch information
Pavel Okhlopkov committed Dec 6, 2024
1 parent 70b156d commit 12e6ec7
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions pkg/app/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ func (cfg *Config) SetupGlobalVars() {
setIfNotEmpty(&DebugKubernetesAPI, cfg.DebugConfig.KubernetesAPI)
setIfNotEmpty(&DebugUnixSocket, cfg.DebugConfig.UnixSocket)

fmt.Println("LOL UNIX SOCKET")
fmt.Println(DebugUnixSocket)
fmt.Println("LOL UNIX SOCKET FROM CFG")
fmt.Println(cfg.DebugConfig.UnixSocket)

setIfNotEmpty(&JqLibraryPath, cfg.JQConfig.LibraryPath)

setIfNotEmpty(&KubeContext, cfg.KubeConfig.ContextName)
Expand Down Expand Up @@ -209,6 +204,33 @@ func (cfg *Config) SetupGlobalVars() {
setIfNotEmpty(&ConversionWebhookSettings.ListenAddr, cfg.ValidatingWebhookConfig.ListenAddress)
}

var configInstance *Config

func MustGetConfig() *Config {
cfg, err := GetConfig()
if err != nil {
panic(err)
}

return cfg
}

func GetConfig() (*Config, error) {
if configInstance != nil {
return configInstance, nil
}

cfg := NewConfig()
err := cfg.Parse()
if err != nil {
return nil, err
}

configInstance = cfg

return configInstance, nil
}

func setIfNotEmpty[T comparable](v *T, env T) {
if !isZero(env) {
*v = env
Expand Down

0 comments on commit 12e6ec7

Please sign in to comment.