Skip to content

Commit

Permalink
chore: delete watch config code
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Oct 23, 2023
1 parent f9447df commit 1bfc975
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
35 changes: 17 additions & 18 deletions cmd/oteld/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package main

import (
"flag"
"fmt"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -54,12 +53,12 @@ func init() {
utilruntime.Must(monitorv1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme

viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.SetDefault(constant.MonitorNamespaceEnvName, "default")
viper.AddConfigPath(fmt.Sprintf("/etc/%s/", constant.OTeldAppName))
viper.AddConfigPath(fmt.Sprintf("$HOME/.%s", constant.OTeldAppName))
viper.AddConfigPath(".")
// viper.SetConfigName("config")
// viper.SetConfigType("yaml")
// viper.SetDefault(constant.MonitorNamespaceEnvName, "default")
// viper.AddConfigPath(fmt.Sprintf("/etc/%s/", constant.OTeldAppName))
// viper.AddConfigPath(fmt.Sprintf("$HOME/.%s", constant.OTeldAppName))
// viper.AddConfigPath(".")

// set env default value
viper.SetDefault(constant.CfgKeyCtrlrMgrNS, "default")
Expand All @@ -83,16 +82,16 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

if err := viper.ReadInConfig(); err != nil {
setupLog.Error(err, "error reading config")
os.Exit(1)
}
setupLog.Info(fmt.Sprintf("oteld config file: %s", viper.ConfigFileUsed()))
config, err := types.LoadConfig(viper.ConfigFileUsed())
if err != nil {
setupLog.Error(err, "unable to load config")
os.Exit(1)
}
// if err := viper.ReadInConfig(); err != nil {
// setupLog.Error(err, "error reading config")
// os.Exit(1)
// }
// setupLog.Info(fmt.Sprintf("oteld config file: %s", viper.ConfigFileUsed()))
// config, err := types.LoadConfig(viper.ConfigFileUsed())
// if err != nil {
// setupLog.Error(err, "unable to load config")
// os.Exit(1)
// }

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Expand Down Expand Up @@ -122,7 +121,7 @@ func main() {
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("oteld-controller"),
}, config).SetupWithManager(mgr); err != nil {
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OTeld")
os.Exit(1)
}
Expand Down
17 changes: 2 additions & 15 deletions controllers/monitor/oteld_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ package monitor

import (
"context"
"fmt"

"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -114,12 +111,12 @@ func (o *OTeldReconciler) runTasks(reqCtx intctrlutil.RequestCtx, oteld *monitor
return nil
}

func New(params monitortypes.OTeldParams, config *monitortypes.Config) *OTeldReconciler {
func New(params monitortypes.OTeldParams) *OTeldReconciler {
reconcile := OTeldReconciler{
Client: params.Client,
Scheme: params.Scheme,
Recorder: params.Recorder,
Config: config,
// Config: config,

// sub-controllers
tasks: []monitortypes.ReconcileTask{
Expand All @@ -136,16 +133,6 @@ func New(params monitortypes.OTeldParams, config *monitortypes.Config) *OTeldRec
},
}

viper.OnConfigChange(func(e fsnotify.Event) {
log.Log.Info(fmt.Sprintf("config file changed: %s", e.Name))
newConfig, err := monitortypes.LoadConfig(viper.ConfigFileUsed())
if err != nil {
log.Log.Error(err, fmt.Sprintf("failed to reload config: %s", e.Name))
return
}
// TODO how to trigger the operator to reconcile
reconcile.Config = newConfig
})
return &reconcile
}

Expand Down

0 comments on commit 1bfc975

Please sign in to comment.