mirror of
https://github.com/coreos/prometheus-operator.git
synced 2026-02-05 06:45:27 +01:00
feat: add support for UTF8 labels and rules (#7637)
for admission webhook default is legacy validation Assissted-By: Cursor Signed-off-by: Jayapriya Pai <slashpai9@gmail.com> Co-authored-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/model"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/goruntime"
|
||||
@@ -35,13 +36,15 @@ import (
|
||||
)
|
||||
|
||||
const defaultGOMemlimitRatio = 0.0
|
||||
const defaultValidationScheme = "legacy"
|
||||
|
||||
func main() {
|
||||
var (
|
||||
serverConfig = server.DefaultConfig(":8443", true)
|
||||
flagset = flag.CommandLine
|
||||
logConfig logging.Config
|
||||
memlimitRatio float64
|
||||
serverConfig = server.DefaultConfig(":8443", true)
|
||||
flagset = flag.CommandLine
|
||||
logConfig logging.Config
|
||||
memlimitRatio float64
|
||||
nameValidationScheme string
|
||||
)
|
||||
|
||||
server.RegisterFlags(flagset, &serverConfig)
|
||||
@@ -49,6 +52,7 @@ func main() {
|
||||
logging.RegisterFlags(flagset, &logConfig)
|
||||
|
||||
flagset.Float64Var(&memlimitRatio, "auto-gomemlimit-ratio", defaultGOMemlimitRatio, "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value should be greater than 0.0 and less than 1.0. Default: 0.0 (disabled).")
|
||||
flagset.StringVar(&nameValidationScheme, "name-validation-scheme", defaultValidationScheme, "The name validation scheme to use ('legacy' or 'utf8').")
|
||||
|
||||
_ = flagset.Parse(os.Args[1:])
|
||||
|
||||
@@ -65,12 +69,24 @@ func main() {
|
||||
goruntime.SetMaxProcs(logger)
|
||||
goruntime.SetMemLimit(logger, memlimitRatio)
|
||||
|
||||
// Parse and validate the name validation scheme
|
||||
var validationScheme model.ValidationScheme
|
||||
switch nameValidationScheme {
|
||||
case "utf8":
|
||||
validationScheme = model.UTF8Validation
|
||||
case "legacy":
|
||||
validationScheme = model.LegacyValidation
|
||||
default:
|
||||
logger.Error("invalid name validation scheme", "scheme", nameValidationScheme, "supported", []string{"utf8", "legacy"})
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
wg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
admit := admission.New(logger.With("component", "admissionwebhook"))
|
||||
admit := admission.New(logger.With("component", "admissionwebhook"), validationScheme)
|
||||
admit.Register(mux)
|
||||
|
||||
r := metrics.NewRegistry("prometheus_operator_admission_webhook")
|
||||
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/version"
|
||||
"golang.org/x/sync/errgroup"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
@@ -601,7 +602,7 @@ func run(fs *flag.FlagSet) int {
|
||||
|
||||
// Setup the web server.
|
||||
mux := http.NewServeMux()
|
||||
admit := admission.New(logger.With("component", "admissionwebhook"))
|
||||
admit := admission.New(logger.With("component", "admissionwebhook"), model.LegacyValidation)
|
||||
admit.Register(mux)
|
||||
|
||||
r.MustRegister(cfg.Gates)
|
||||
|
||||
Reference in New Issue
Block a user