1
0
mirror of https://github.com/coreos/prometheus-operator.git synced 2026-02-05 15:46:31 +01:00

Add structure for feature flags

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
This commit is contained in:
Arthur Silva Sens
2024-05-02 20:41:30 -03:00
committed by Arthur Silva Sens
parent f4b82d7235
commit 6b1caac3f1
3 changed files with 83 additions and 0 deletions

View File

@@ -49,6 +49,8 @@ Usage of ./operator:
Namespaces not to scope the interaction of the Prometheus Operator (deny list). This is mutually exclusive with --namespaces.
-enable-config-reloader-probes
Enable liveness and readiness for the config-reloader container. Default: false
-feature-gates value
Feature gates are a set of key=value pairs that describe Prometheus-Operator features. At the moment there are no feature gates available.
-key-file string
- NOT RECOMMENDED FOR PRODUCTION - Path to private TLS certificate file.
-kubelet-node-address-priority value

View File

@@ -41,6 +41,8 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
k8sflag "k8s.io/component-base/cli/flag"
"k8s.io/utils/ptr"
logging "github.com/prometheus-operator/prometheus-operator/internal/log"
"github.com/prometheus-operator/prometheus-operator/pkg/admission"
@@ -114,6 +116,8 @@ var (
kubeletObject string
kubeletSelector operator.LabelSelector
nodeAddressPriority operator.NodeAddressPriority
featureGates *k8sflag.MapStringBool
)
func parseFlags(fs *flag.FlagSet) {
@@ -166,6 +170,11 @@ func parseFlags(fs *flag.FlagSet) {
fs.Var(&cfg.ThanosRulerSelector, "thanos-ruler-instance-selector", "Label selector to filter ThanosRuler Custom Resources to watch.")
fs.Var(&cfg.SecretListWatchSelector, "secret-field-selector", "Field selector to filter Secrets to watch")
featureGates = k8sflag.NewMapStringBool(ptr.To(make(map[string]bool)))
fs.Var(featureGates, "feature-gates", "Feature gates are a set of key=value pairs that describe Prometheus-Operator features. At the moment there are no feature gates available.")
// Once the first feature gate is added, the line below should be uncommented and the line above deleted.
//fs.Var(featureGates, "feature-gates", fmt.Sprintf("Feature gates are a set of key=value pairs that describe Prometheus-Operator features. Available features: %q.", operator.AvailableFeatureGates()))
logging.RegisterFlags(fs, &logConfig)
versionutil.RegisterFlags(fs)
@@ -193,8 +202,17 @@ func run(fs *flag.FlagSet) int {
level.Warn(logger).Log("msg", "Failed to set GOMAXPROCS automatically", "err", err)
}
gates, err := operator.ValidateFeatureGates(featureGates)
if err != nil {
level.Error(logger).Log(
"msg", "error validating feature gates",
"error", err)
return 1
}
level.Info(logger).Log("msg", "Starting Prometheus Operator", "version", version.Info())
level.Info(logger).Log("build_context", version.BuildContext())
level.Info(logger).Log("feature_gates", gates)
if len(cfg.Namespaces.AllowList) > 0 && len(cfg.Namespaces.DenyList) > 0 {
level.Error(logger).Log(

View File

@@ -0,0 +1,63 @@
// Copyright 2024 The prometheus-operator 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 operator
import (
"fmt"
"slices"
"strings"
k8sflag "k8s.io/component-base/cli/flag"
)
// At the moment, the are no feature gates available.
var defaultFeatureGates = map[string]bool{}
// ValidateFeatureGates merges the feature gate default values with
// the values provided by the user.
func ValidateFeatureGates(flags *k8sflag.MapStringBool) (string, error) {
gates := defaultFeatureGates
if flags.Empty() {
return mapToString(gates), nil
}
imgs := *flags.Map
for k, v := range imgs {
if _, ok := gates[k]; !ok {
return "", fmt.Errorf("feature gate %v is unknown", k)
}
gates[k] = v
}
return mapToString(gates), nil
}
func AvailableFeatureGates() []string {
i := 0
gates := make([]string, len(defaultFeatureGates))
for k := range defaultFeatureGates {
gates[i] = k
i++
}
slices.Sort(gates)
return gates
}
func mapToString(m map[string]bool) string {
var s []string
for k, v := range m {
s = append(s, fmt.Sprintf("%s=%t", k, v))
}
return strings.Join(s, ",")
}