Skip to content

Commit

Permalink
Merge pull request #20 from snapp-incubator/revised/custom-bundle
Browse files Browse the repository at this point in the history
revised how custom config is used
  • Loading branch information
sinamna authored Dec 25, 2023
2 parents 2a1bec6 + 8e7ef8c commit 055240a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
19 changes: 13 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func main() {
var customConfigPath string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&customConfigPath, "custom-config-path", "./custom/config.yaml", "the path to custom config.")
flag.StringVar(&customConfigPath, "custom-config-path", "", "the path to custom config.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
Expand All @@ -69,12 +69,19 @@ func main() {
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
customConfig, err := config.InitConfig(customConfigPath)
if err != nil {
setupLog.Info("custom config not loaded")
} else {
authenticatorv1alpha1.ValidationTimeout = time.Second * time.Duration(customConfig.WebhookConf.ValidationTimeoutSecond)

var customConfig *config.CustomConfig
if customConfigPath != "" {
setupLog.Info(customConfigPath)
tmpConf, err := config.InitConfig(customConfigPath)
if err != nil {
setupLog.Error(err, "failed to load custom config")
} else {
customConfig = tmpConf
authenticatorv1alpha1.ValidationTimeout = time.Second * time.Duration(customConfig.WebhookConf.ValidationTimeoutSecond)
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Expand Down
1 change: 1 addition & 0 deletions config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ spec:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
- $(ARGS)
6 changes: 4 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import "github.com/spf13/viper"
import (
"github.com/spf13/viper"
)

type CustomConfig struct {
WebserverConf WebserverConfig `mapstructure:"webserver"`
Expand All @@ -17,7 +19,7 @@ type WebhookConfig struct {
}

func InitConfig(configPath string) (*CustomConfig, error) {
viper.AddConfigPath(configPath)
viper.SetConfigFile(configPath)
viper.SetConfigType("yaml")
err := viper.ReadInConfig()
if err != nil {
Expand Down

0 comments on commit 055240a

Please sign in to comment.