Move away from deprecated term.AllowsColorOutput (#135454)

* Move away from deprecated term.AllowsColorOutput

* Move away from term.IsTerminal

Kubernetes-commit: bb9bb4d4224923964f6e4ed4306450a79fee647d
This commit is contained in:
Arda Güçlü 2025-12-18 09:35:36 +03:00 committed by Kubernetes Publisher
parent c3ae2c23bf
commit 12c7166176
9 changed files with 20 additions and 26 deletions

6
go.mod
View file

@ -30,10 +30,10 @@ require (
golang.org/x/sys v0.38.0
golang.org/x/text v0.31.0
gopkg.in/evanphx/json-patch.v4 v4.13.0
k8s.io/api v0.0.0-20251218022515-cc3b8d55eb43
k8s.io/apimachinery v0.0.0-20251218062152-a9de6f8b12f4
k8s.io/api v0.0.0-20251218062648-50474f4a1619
k8s.io/apimachinery v0.0.0-20251218062153-94056eccfb12
k8s.io/cli-runtime v0.0.0-20251204234503-91a837f2a3b2
k8s.io/client-go v0.0.0-20251218063301-b960c92ed74f
k8s.io/client-go v0.0.0-20251218063306-1aef261f0ad5
k8s.io/component-base v0.0.0-20251204225730-8cb15f10375f
k8s.io/component-helpers v0.0.0-20251204230024-d853346140cf
k8s.io/klog/v2 v2.130.1

12
go.sum
View file

@ -192,14 +192,14 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.0.0-20251218022515-cc3b8d55eb43 h1:3O08UsEzuxZLokQ1JfOHBklda+NOUKTX+4mEYtaLIzA=
k8s.io/api v0.0.0-20251218022515-cc3b8d55eb43/go.mod h1:OjSG925L2Qod5yd066wDJ6HLaA8lNCJRx5eAtCw5rOM=
k8s.io/apimachinery v0.0.0-20251218062152-a9de6f8b12f4 h1:6qzElS1kwIIk7oKF6tlSLLh7bQLDZ60+J406vLzB2Wg=
k8s.io/apimachinery v0.0.0-20251218062152-a9de6f8b12f4/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns=
k8s.io/api v0.0.0-20251218062648-50474f4a1619 h1:uqLi4NaZ8GcjLm5jQaPyxzeVXqTGKyzUiUo8DXD/8eQ=
k8s.io/api v0.0.0-20251218062648-50474f4a1619/go.mod h1:BF6wJ9t7NKHa7KSQlnAZ2/iI3e9YLY3YRFaMfEzOeec=
k8s.io/apimachinery v0.0.0-20251218062153-94056eccfb12 h1:EcHv2BCdOt2p8EIoLqsEFb2lTgBE7gy07YerdzjNCGY=
k8s.io/apimachinery v0.0.0-20251218062153-94056eccfb12/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns=
k8s.io/cli-runtime v0.0.0-20251204234503-91a837f2a3b2 h1:Enp0pfwIo4VgibNk4glyBdvYxs4ICprkD7o4bb5tLTQ=
k8s.io/cli-runtime v0.0.0-20251204234503-91a837f2a3b2/go.mod h1:vBG0V5wDapyWnz/yNY16mPxOOSHpTIi+Bci+f1LzD58=
k8s.io/client-go v0.0.0-20251218063301-b960c92ed74f h1:xc1omZg/dV9SWtaic9jqGf9ue1WQLNy1EPsg4JWygfI=
k8s.io/client-go v0.0.0-20251218063301-b960c92ed74f/go.mod h1:sg849vnQr6NuMcTFSLXzQjWQSkex2fVQ1FUcD9i23yI=
k8s.io/client-go v0.0.0-20251218063306-1aef261f0ad5 h1:edGMs/zH+JmmId6j7QM6eWxHUGMwOHmSBbW+lFhmdE4=
k8s.io/client-go v0.0.0-20251218063306-1aef261f0ad5/go.mod h1:XW/tTjAxjkB5EpWTvlrxaiy1AdZiTO6waddhIvbEe4U=
k8s.io/component-base v0.0.0-20251204225730-8cb15f10375f h1:+E5vv24SeZdDzNIzmNpkWe85rE7nR3pVu+n5mrKSkW4=
k8s.io/component-base v0.0.0-20251204225730-8cb15f10375f/go.mod h1:8Ohmd7Q46U1rnT5I8SNvql3xi+S81vMldMPHMNV+e+I=
k8s.io/component-helpers v0.0.0-20251204230024-d853346140cf h1:DQSxuouPfXAH1++b/0yNyB0ifvQqhyLE6zsjgVgL0ew=

View file

@ -42,7 +42,6 @@ import (
"k8s.io/kubectl/pkg/describe"
rbacutil "k8s.io/kubectl/pkg/util/rbac"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/util/term"
)
// CanIOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
@ -154,7 +153,7 @@ func NewCmdCanI(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra.Co
func (o *CanIOptions) Complete(f cmdutil.Factory, args []string) error {
// Set default WarningPrinter if not already set.
if o.WarningPrinter == nil {
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: term.AllowsColorOutput(o.ErrOut)})
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: printers.AllowsColorOutput(o.ErrOut)})
}
if o.List {

View file

@ -25,7 +25,9 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
cliflag "k8s.io/component-base/cli/flag"
@ -53,6 +55,7 @@ import (
"k8s.io/kubectl/pkg/cmd/explain"
"k8s.io/kubectl/pkg/cmd/expose"
"k8s.io/kubectl/pkg/cmd/get"
"k8s.io/kubectl/pkg/cmd/kustomize"
"k8s.io/kubectl/pkg/cmd/label"
"k8s.io/kubectl/pkg/cmd/logs"
"k8s.io/kubectl/pkg/cmd/options"
@ -74,10 +77,6 @@ import (
utilcomp "k8s.io/kubectl/pkg/util/completion"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/util/term"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/kustomize"
)
type KubectlOptions struct {
@ -163,7 +162,7 @@ func NewDefaultKubectlCommandWithArgs(o KubectlOptions) *cobra.Command {
// NewKubectlCommand creates the `kubectl` command and its nested children.
func NewKubectlCommand(o KubectlOptions) *cobra.Command {
warningHandler := rest.NewWarningWriter(o.IOStreams.ErrOut, rest.WarningWriterOptions{Deduplicate: true, Color: term.AllowsColorOutput(o.IOStreams.ErrOut)})
warningHandler := rest.NewWarningWriter(o.IOStreams.ErrOut, rest.WarningWriterOptions{Deduplicate: true, Color: printers.AllowsColorOutput(o.IOStreams.ErrOut)})
warningsAsErrors := false
var finishProfiling func() error
// Parent command to which all subcommands are added.

View file

@ -32,12 +32,12 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/cli-runtime/pkg/printers"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/scheme"
"k8s.io/kubectl/pkg/util/completion"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/util/term"
"k8s.io/utils/ptr"
)
@ -264,7 +264,7 @@ func (o *TokenOptions) Run() error {
return o.PrintObj(response)
}
if term.IsTerminal(o.Out) {
if printers.IsTerminal(o.Out) {
// include a newline when printing interactively
fmt.Fprintf(o.Out, "%s\n", response.Status.Token)
} else {

View file

@ -54,7 +54,6 @@ import (
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/interrupt"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/util/term"
"k8s.io/utils/ptr"
"sigs.k8s.io/yaml"
)
@ -268,7 +267,7 @@ func (o *DebugOptions) Complete(restClientGetter genericclioptions.RESTClientGet
// Set default WarningPrinter
if o.WarningPrinter == nil {
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: term.AllowsColorOutput(o.ErrOut)})
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: printers.AllowsColorOutput(o.ErrOut)})
}
if o.Applier == nil {

View file

@ -40,7 +40,6 @@ import (
"k8s.io/kubectl/pkg/util/completion"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/util/term"
)
var (
@ -205,7 +204,7 @@ func (o *DeleteOptions) Complete(f cmdutil.Factory, args []string, cmd *cobra.Co
// Set default WarningPrinter if not already set.
if o.WarningPrinter == nil {
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: term.AllowsColorOutput(o.ErrOut)})
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: printers.AllowsColorOutput(o.ErrOut)})
}
if len(o.Raw) != 0 {

View file

@ -39,7 +39,6 @@ import (
"k8s.io/kubectl/pkg/util/completion"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/util/term"
)
type DrainCmdOptions struct {
@ -287,7 +286,7 @@ func (o *DrainCmdOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
// Set default WarningPrinter if not already set.
if o.WarningPrinter == nil {
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: term.AllowsColorOutput(o.ErrOut)})
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: printers.AllowsColorOutput(o.ErrOut)})
}
builder := f.NewBuilder().

View file

@ -41,7 +41,6 @@ import (
"k8s.io/kubectl/pkg/scheme"
"k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubectl/pkg/util/term"
)
var (
@ -250,7 +249,7 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
o.builder = f.NewBuilder
// Set default WarningPrinter if not already set.
if o.WarningPrinter == nil {
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: term.AllowsColorOutput(o.ErrOut)})
o.WarningPrinter = printers.NewWarningPrinter(o.ErrOut, printers.WarningPrinterOptions{Color: printers.AllowsColorOutput(o.ErrOut)})
}
return nil