Merge pull request #1906 from mattburgess/fix-logging-alpha-options

Fix LoggingAlphaOptions wiring
This commit is contained in:
kubernetes-prow[bot]
2026-08-25 11:23:36 +00:00
committed by GitHub
4 changed files with 81 additions and 5 deletions
+6 -4
View File
@@ -28,13 +28,13 @@ import (
"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
"sigs.k8s.io/descheduler/pkg/descheduler"
"sigs.k8s.io/descheduler/pkg/features"
"sigs.k8s.io/descheduler/pkg/tracing"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apiserver/pkg/server/healthz"
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/component-base/featuregate"
"k8s.io/component-base/logs"
logsapi "k8s.io/component-base/logs/api/v1"
_ "k8s.io/component-base/logs/json/register"
@@ -49,7 +49,6 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
klog.ErrorS(err, "unable to initialize server")
}
featureGate := featuregate.NewFeatureGate()
logConfig := logsapi.NewLoggingConfiguration()
cmd := &cobra.Command{
@@ -58,7 +57,10 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
Long: "The descheduler evicts pods which may be bound to less desired nodes",
PreRunE: func(cmd *cobra.Command, args []string) error {
logs.InitLogs()
if logsapi.ValidateAndApply(logConfig, featureGate); err != nil {
if err := features.DefaultMutableFeatureGate.SetFromMap(s.FeatureGates); err != nil {
return err
}
if err := logsapi.ValidateAndApply(logConfig, features.DefaultMutableFeatureGate); err != nil {
return err
}
descheduler.SetupPlugins()
@@ -80,9 +82,9 @@ func NewDeschedulerCommand(out io.Writer) *cobra.Command {
}
cmd.SetOut(out)
flags := cmd.Flags()
runtime.Must(logsapi.AddFeatureGates(features.DefaultMutableFeatureGate))
s.AddFlags(flags)
runtime.Must(logsapi.AddFeatureGates(featureGate))
logsapi.AddFlags(logConfig, flags)
return cmd
+71
View File
@@ -0,0 +1,71 @@
/*
Copyright 2026 The Kubernetes 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 app
import (
"io"
"strings"
"testing"
)
func TestNewDeschedulerCommand_LoggingAlphaOptions(t *testing.T) {
tests := []struct {
name string
args []string
wantErr string
}{
{
name: "LoggingAlphaOptions=false rejects --log-json-split-stream",
args: []string{
"--logging-format=json",
"--log-json-split-stream",
"--feature-gates=LoggingAlphaOptions=false",
},
wantErr: "LoggingAlphaOptions is disabled",
},
{
name: "LoggingAlphaOptions=true accepts --log-json-split-stream",
args: []string{
"--logging-format=json",
"--log-json-split-stream",
"--feature-gates=LoggingAlphaOptions=true",
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cmd := NewDeschedulerCommand(io.Discard)
if err := cmd.ParseFlags(tc.args); err != nil {
t.Fatalf("ParseFlags(%v): %v", tc.args, err)
}
err := cmd.PreRunE(cmd, cmd.Flags().Args())
if tc.wantErr == "" {
if err != nil {
t.Fatalf("expected PreRunE to succeed, got error: %v", err)
}
return
}
if err == nil {
t.Fatalf("expected PreRunE to fail with %q, got nil", tc.wantErr)
}
if !strings.Contains(err.Error(), tc.wantErr) {
t.Fatalf("expected PreRunE error to contain %q, got :%v", tc.wantErr, err)
}
})
}
}
+3
View File
@@ -26,7 +26,10 @@ descheduler [flags]
--feature-gates mapStringBool A set of key=value pairs that describe feature gates for alpha/experimental features. Options are:
AllAlpha=true|false (ALPHA - default=false)
AllBeta=true|false (BETA - default=false)
ContextualLogging=true|false (BETA - default=true)
EvictionsInBackground=true|false (ALPHA - default=false)
LoggingAlphaOptions=true|false (ALPHA - default=false)
LoggingBetaOptions=true|false (BETA - default=true)
-h, --help help for descheduler
--http2-max-streams-per-connection int The limit that the server gives to clients for the maximum number of streams in an HTTP/2 connection. Zero means to use golang's default.
--kubeconfig string File with kube configuration. Deprecated, use client-connection-kubeconfig instead.
+1 -1
View File
@@ -46,4 +46,4 @@ var defaultDeschedulerFeatureGates = map[featuregate.Feature]featuregate.Feature
// Tests that need to modify feature gates for the duration of their test should use:
//
// defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.<FeatureName>, <value>)()
var DefaultMutableFeatureGate featuregate.MutableFeatureGate = featuregate.NewFeatureGate()
var DefaultMutableFeatureGate featuregate.MutableVersionedFeatureGate = featuregate.NewFeatureGate()