-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor target allocator config handling (#1957)
* Refactor target allocator config handling * Move TargetAllocator flags to a separate file * Fix yaml annotation on the TA config struct * Clearly separate loading config from CLI and file * Use an explicit flag set for target allocator flags * Add changelog entry * Pass config by value to PrometheusCRWatcher
- Loading branch information
Showing
12 changed files
with
284 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: enhancement | ||
|
||
# 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: Allow target allocator to be completely configured via the config file | ||
|
||
# One or more tracking issues related to the change | ||
issues: [2129] | ||
|
||
# (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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// 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 config | ||
|
||
import ( | ||
"flag" | ||
"path/filepath" | ||
|
||
"github.com/spf13/pflag" | ||
"k8s.io/client-go/util/homedir" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
) | ||
|
||
// Flag names. | ||
const ( | ||
targetAllocatorName = "target-allocator" | ||
configFilePathFlagName = "config-file" | ||
listenAddrFlagName = "listen-addr" | ||
prometheusCREnabledFlagName = "enable-prometheus-cr-watcher" | ||
kubeConfigPathFlagName = "kubeconfig-path" | ||
) | ||
|
||
// We can't bind this flag to our FlagSet, so we need to handle it separately. | ||
var zapCmdLineOpts zap.Options | ||
|
||
func getFlagSet(errorHandling pflag.ErrorHandling) *pflag.FlagSet { | ||
flagSet := pflag.NewFlagSet(targetAllocatorName, errorHandling) | ||
flagSet.String(configFilePathFlagName, DefaultConfigFilePath, "The path to the config file.") | ||
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") | ||
zapFlagSet := flag.NewFlagSet("", flag.ErrorHandling(errorHandling)) | ||
zapCmdLineOpts.BindFlags(zapFlagSet) | ||
flagSet.AddGoFlagSet(zapFlagSet) | ||
return flagSet | ||
} | ||
|
||
func getConfigFilePath(flagSet *pflag.FlagSet) (string, error) { | ||
return flagSet.GetString(configFilePathFlagName) | ||
} | ||
|
||
func getKubeConfigFilePath(flagSet *pflag.FlagSet) (string, error) { | ||
return flagSet.GetString(kubeConfigPathFlagName) | ||
} | ||
|
||
func getListenAddr(flagSet *pflag.FlagSet) (string, error) { | ||
return flagSet.GetString(listenAddrFlagName) | ||
} | ||
|
||
func getPrometheusCREnabled(flagSet *pflag.FlagSet) (bool, error) { | ||
return flagSet.GetBool(prometheusCREnabledFlagName) | ||
} |
Oops, something went wrong.