Skip to content

Commit

Permalink
Remove configuration hot reloading from target allocator (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm authored Dec 7, 2023
1 parent 5566a01 commit d595f40
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 138 deletions.
16 changes: 16 additions & 0 deletions .chloggen/ta_removehotreload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: target allocator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove configuration hot reloading from target allocator

# One or more tracking issues related to the change
issues: [2032]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: This only affects use of target allocator without the operator.
18 changes: 6 additions & 12 deletions cmd/otel-allocator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type Config struct {
KubeConfigFilePath string `yaml:"kube_config_file_path,omitempty"`
ClusterConfig *rest.Config `yaml:"-"`
RootLogger logr.Logger `yaml:"-"`
ReloadConfig bool `yaml:"-"`
LabelSelector map[string]string `yaml:"label_selector,omitempty"`
PromConfig *promconfig.Config `yaml:"config"`
AllocationStrategy *string `yaml:"allocation_strategy,omitempty"`
Expand Down Expand Up @@ -111,11 +110,6 @@ func LoadFromCLI(target *Config, flagSet *pflag.FlagSet) error {
return err
}

target.ReloadConfig, err = getConfigReloadEnabled(flagSet)
if err != nil {
return err
}

return nil
}

Expand All @@ -139,33 +133,33 @@ func CreateDefaultConfig() Config {
}
}

func Load() (*Config, string, error) {
func Load() (*Config, error) {
var err error

flagSet := getFlagSet(pflag.ExitOnError)
err = flagSet.Parse(os.Args)
if err != nil {
return nil, "", err
return nil, err
}

config := CreateDefaultConfig()

// load the config from the config file
configFilePath, err := getConfigFilePath(flagSet)
if err != nil {
return nil, "", err
return nil, err
}
err = LoadFromFile(configFilePath, &config)
if err != nil {
return nil, "", err
return nil, err
}

err = LoadFromCLI(&config, flagSet)
if err != nil {
return nil, "", err
return nil, err
}

return &config, configFilePath, nil
return &config, nil
}

// ValidateConfig validates the cli and file configs together.
Expand Down
6 changes: 0 additions & 6 deletions cmd/otel-allocator/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const (
listenAddrFlagName = "listen-addr"
prometheusCREnabledFlagName = "enable-prometheus-cr-watcher"
kubeConfigPathFlagName = "kubeconfig-path"
reloadConfigFlagName = "reload-config"
)

// We can't bind this flag to our FlagSet, so we need to handle it separately.
Expand All @@ -42,7 +41,6 @@ func getFlagSet(errorHandling pflag.ErrorHandling) *pflag.FlagSet {
flagSet.String(listenAddrFlagName, ":8080", "The address where this service serves.")
flagSet.Bool(prometheusCREnabledFlagName, false, "Enable Prometheus CRs as target sources")
flagSet.String(kubeConfigPathFlagName, filepath.Join(homedir.HomeDir(), ".kube", "config"), "absolute path to the KubeconfigPath file")
flagSet.Bool(reloadConfigFlagName, false, "Enable automatic configuration reloading. This functionality is deprecated and will be removed in a future release.")
zapFlagSet := flag.NewFlagSet("", flag.ErrorHandling(errorHandling))
zapCmdLineOpts.BindFlags(zapFlagSet)
flagSet.AddGoFlagSet(zapFlagSet)
Expand All @@ -64,7 +62,3 @@ func getListenAddr(flagSet *pflag.FlagSet) (string, error) {
func getPrometheusCREnabled(flagSet *pflag.FlagSet) (bool, error) {
return flagSet.GetBool(prometheusCREnabledFlagName)
}

func getConfigReloadEnabled(flagSet *pflag.FlagSet) (bool, error) {
return flagSet.GetBool(reloadConfigFlagName)
}
6 changes: 0 additions & 6 deletions cmd/otel-allocator/config/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ func TestFlagGetters(t *testing.T) {
expectedValue: true,
getterFunc: func(fs *pflag.FlagSet) (interface{}, error) { return getPrometheusCREnabled(fs) },
},
{
name: "GetConfigReloadEnabled",
flagArgs: []string{"--" + reloadConfigFlagName, "true"},
expectedValue: true,
getterFunc: func(fs *pflag.FlagSet) (interface{}, error) { return getConfigReloadEnabled(fs) },
},
{
name: "InvalidFlag",
flagArgs: []string{"--invalid-flag", "value"},
Expand Down
25 changes: 1 addition & 24 deletions cmd/otel-allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func main() {
allocator allocation.Allocator
discoveryManager *discovery.Manager
collectorWatcher *collector.Client
fileWatcher allocatorWatcher.Watcher
promWatcher allocatorWatcher.Watcher
targetDiscoverer *target.Discoverer

Expand All @@ -65,7 +64,7 @@ func main() {
interrupts = make(chan os.Signal, 1)
errChan = make(chan error)
)
cfg, configFilePath, err := config.Load()
cfg, err := config.Load()
if err != nil {
fmt.Printf("Failed to load config: %v", err)
os.Exit(1)
Expand Down Expand Up @@ -99,13 +98,6 @@ func main() {
setupLog.Error(collectorWatcherErr, "Unable to initialize collector watcher")
os.Exit(1)
}
if cfg.ReloadConfig {
fileWatcher, err = allocatorWatcher.NewFileWatcher(setupLog.WithName("file-watcher"), configFilePath)
if err != nil {
setupLog.Error(err, "Can't start the file watcher")
os.Exit(1)
}
}
signal.Notify(interrupts, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
defer close(interrupts)

Expand All @@ -129,21 +121,6 @@ func main() {
}
})
}
if cfg.ReloadConfig {
runGroup.Add(
func() error {
fileWatcherErr := fileWatcher.Watch(eventChan, errChan)
setupLog.Info("File watcher exited")
return fileWatcherErr
},
func(_ error) {
setupLog.Info("Closing file watcher")
fileWatcherErr := fileWatcher.Close()
if fileWatcherErr != nil {
setupLog.Error(fileWatcherErr, "file watcher failed to close")
}
})
}
runGroup.Add(
func() error {
discoveryManagerErr := discoveryManager.Run()
Expand Down
90 changes: 0 additions & 90 deletions cmd/otel-allocator/watcher/file.go

This file was deleted.

0 comments on commit d595f40

Please sign in to comment.