Skip to content

Commit 055240a

Browse files
authored
Merge pull request #20 from snapp-incubator/revised/custom-bundle
revised how custom config is used
2 parents 2a1bec6 + 8e7ef8c commit 055240a

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

cmd/main.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
var customConfigPath string
5959
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6060
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
61-
flag.StringVar(&customConfigPath, "custom-config-path", "./custom/config.yaml", "the path to custom config.")
61+
flag.StringVar(&customConfigPath, "custom-config-path", "", "the path to custom config.")
6262
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6363
"Enable leader election for controller manager. "+
6464
"Enabling this will ensure there is only one active controller manager.")
@@ -69,12 +69,19 @@ func main() {
6969
flag.Parse()
7070

7171
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
72-
customConfig, err := config.InitConfig(customConfigPath)
73-
if err != nil {
74-
setupLog.Info("custom config not loaded")
75-
} else {
76-
authenticatorv1alpha1.ValidationTimeout = time.Second * time.Duration(customConfig.WebhookConf.ValidationTimeoutSecond)
72+
73+
var customConfig *config.CustomConfig
74+
if customConfigPath != "" {
75+
setupLog.Info(customConfigPath)
76+
tmpConf, err := config.InitConfig(customConfigPath)
77+
if err != nil {
78+
setupLog.Error(err, "failed to load custom config")
79+
} else {
80+
customConfig = tmpConf
81+
authenticatorv1alpha1.ValidationTimeout = time.Second * time.Duration(customConfig.WebhookConf.ValidationTimeoutSecond)
82+
}
7783
}
84+
7885
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
7986
Scheme: scheme,
8087
MetricsBindAddress: metricsAddr,

config/default/manager_auth_proxy_patch.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ spec:
5353
- "--health-probe-bind-address=:8081"
5454
- "--metrics-bind-address=127.0.0.1:8080"
5555
- "--leader-elect"
56+
- $(ARGS)

internal/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package config
22

3-
import "github.com/spf13/viper"
3+
import (
4+
"github.com/spf13/viper"
5+
)
46

57
type CustomConfig struct {
68
WebserverConf WebserverConfig `mapstructure:"webserver"`
@@ -17,7 +19,7 @@ type WebhookConfig struct {
1719
}
1820

1921
func InitConfig(configPath string) (*CustomConfig, error) {
20-
viper.AddConfigPath(configPath)
22+
viper.SetConfigFile(configPath)
2123
viper.SetConfigType("yaml")
2224
err := viper.ReadInConfig()
2325
if err != nil {

0 commit comments

Comments
 (0)