From 164e47abb80d30e64b8e0222053bd11dbaf0258f Mon Sep 17 00:00:00 2001 From: Maciej Szulik Date: Wed, 22 Oct 2025 13:56:32 +0200 Subject: [PATCH] Promote KUBECTL_COMMAND_HEADERS to stable Signed-off-by: Maciej Szulik Kubernetes-commit: f82a139dc0840b51aa41931535f5eef6fc3507b4 --- pkg/cmd/cmd.go | 7 ------- pkg/cmd/cmd_test.go | 45 ----------------------------------------- pkg/cmd/util/helpers.go | 6 ------ 3 files changed, 58 deletions(-) diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 58523a143..608e6a016 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -526,17 +526,10 @@ func NewKubectlCommand(o KubectlOptions) *cobra.Command { // RoundTripper. CommandHeaderRoundTripper adds X-Headers then delegates // to standard RoundTripper. // -// For beta, these hooks are updated unless the KUBECTL_COMMAND_HEADERS environment variable -// is set, and the value of the env var is false (or zero). // See SIG CLI KEP 859 for more information: // // https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/859-kubectl-headers func addCmdHeaderHooks(cmds *cobra.Command, kubeConfigFlags *genericclioptions.ConfigFlags) { - if cmdutil.CmdHeaders.IsDisabled() { - klog.V(5).Infoln("kubectl command headers turned off") - return - } - klog.V(5).Infoln("kubectl command headers turned on") crt := &genericclioptions.CommandHeaderRoundTripper{} existingPreRunE := cmds.PersistentPreRunE // Add command parsing to the existing persistent pre-run function. diff --git a/pkg/cmd/cmd_test.go b/pkg/cmd/cmd_test.go index f624d5f8f..787aac0ee 100644 --- a/pkg/cmd/cmd_test.go +++ b/pkg/cmd/cmd_test.go @@ -26,10 +26,8 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" "github.com/spf13/cobra" - "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericiooptions" "k8s.io/kubectl/pkg/cmd/plugin" - cmdutil "k8s.io/kubectl/pkg/cmd/util" ) func TestNormalizationFuncGlobalExistence(t *testing.T) { @@ -360,46 +358,3 @@ func (h *testPluginHandler) Execute(executablePath string, cmdArgs, env []string h.withEnv = env return nil } - -func TestKubectlCommandHeadersHooks(t *testing.T) { - tests := map[string]struct { - envVar string - addsHooks bool - }{ - "empty environment variable; hooks added": { - envVar: "", - addsHooks: true, - }, - "random env var value; hooks added": { - envVar: "foo", - addsHooks: true, - }, - "true env var value; hooks added": { - envVar: "true", - addsHooks: true, - }, - "false env var value; hooks NOT added": { - envVar: "false", - addsHooks: false, - }, - } - - for name, testCase := range tests { - t.Run(name, func(t *testing.T) { - cmds := &cobra.Command{} - kubeConfigFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag() - if kubeConfigFlags.WrapConfigFn != nil { - t.Fatal("expected initial nil WrapConfigFn") - } - t.Setenv(string(cmdutil.CmdHeaders), testCase.envVar) - addCmdHeaderHooks(cmds, kubeConfigFlags) - // Valdidate whether the hooks were added. - if testCase.addsHooks && kubeConfigFlags.WrapConfigFn == nil { - t.Error("after adding kubectl command header, expecting non-nil WrapConfigFn") - } - if !testCase.addsHooks && kubeConfigFlags.WrapConfigFn != nil { - t.Error("env var feature gate should have blocked setting WrapConfigFn") - } - }) - } -} diff --git a/pkg/cmd/util/helpers.go b/pkg/cmd/util/helpers.go index fc623dded..755533aeb 100644 --- a/pkg/cmd/util/helpers.go +++ b/pkg/cmd/util/helpers.go @@ -425,12 +425,6 @@ func GetPodRunningTimeoutFlag(cmd *cobra.Command) (time.Duration, error) { type FeatureGate string const ( - // owner: @soltysh - // kep: https://kep.k8s.io/859 - // - // HTTP headers with command name and flags used. - CmdHeaders FeatureGate = "KUBECTL_COMMAND_HEADERS" - // owner: @ardaguclu // kep: https://kep.k8s.io/3104 //