diff --git a/common/leaderelection/leaderelection.go b/common/leaderelection/leaderelection.go index deac594c3c..3027c02887 100644 --- a/common/leaderelection/leaderelection.go +++ b/common/leaderelection/leaderelection.go @@ -11,7 +11,6 @@ import ( "github.com/fsnotify/fsnotify" "github.com/nats-io/graft" nats "github.com/nats-io/nats.go" - "github.com/spf13/viper" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -79,7 +78,7 @@ func getEventBusAuth(ctx context.Context, authStrategy *eventbusv1alpha1.AuthStr Strategy: eventbusv1alpha1.AuthStrategyNone, } } else { - v := viper.New() + v := common.ViperWithLogging() v.SetConfigName("auth") v.SetConfigType("yaml") v.AddConfigPath(eventBusAuthFileMountPath) diff --git a/common/viper.go b/common/viper.go new file mode 100644 index 0000000000..b53b3a72a2 --- /dev/null +++ b/common/viper.go @@ -0,0 +1,28 @@ +/* +Copyright 2024 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "github.com/spf13/viper" + "log/slog" + "os" +) + +func ViperWithLogging() *viper.Viper { + v := viper.NewWithOptions(viper.WithLogger(slog.New(slog.NewJSONHandler(os.Stdout, nil)))) + return v +} diff --git a/controllers/config.go b/controllers/config.go index c64365ea1b..f335468a1a 100644 --- a/controllers/config.go +++ b/controllers/config.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" + "github.com/argoproj/argo-events/common" "github.com/fsnotify/fsnotify" - "github.com/spf13/viper" ) type GlobalConfig struct { @@ -94,7 +94,7 @@ func (g *GlobalConfig) GetJetStreamVersion(version string) (*JetStreamVersion, e } func LoadConfig(onErrorReloading func(error)) (*GlobalConfig, error) { - v := viper.New() + v := common.ViperWithLogging() v.SetConfigName("controller-config") v.SetConfigType("yaml") v.AddConfigPath("/etc/argo-events") diff --git a/eventbus/driver.go b/eventbus/driver.go index 585aa67db7..06fc095788 100644 --- a/eventbus/driver.go +++ b/eventbus/driver.go @@ -19,7 +19,6 @@ import ( stansensor "github.com/argoproj/argo-events/eventbus/stan/sensor" eventbusv1alpha1 "github.com/argoproj/argo-events/pkg/apis/eventbus/v1alpha1" "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" - "github.com/spf13/viper" ) func GetEventSourceDriver(ctx context.Context, eventBusConfig eventbusv1alpha1.BusConfig, eventSourceName string, defaultSubject string) (eventbuscommon.EventSourceDriver, error) { @@ -134,7 +133,7 @@ func GetAuth(ctx context.Context, eventBusConfig eventbusv1alpha1.BusConfig) (*e Strategy: eventbusv1alpha1.AuthStrategyNone, } } else { - v := viper.New() + v := common.ViperWithLogging() v.SetConfigName("auth") v.SetConfigType("yaml") v.AddConfigPath(common.EventBusAuthFileMountPath)