Merge pull request #101004 from lojies/cleanupforkubectl

code cleanup for kubectl
This commit is contained in:
Kubernetes Prow Robot 2021-11-02 17:58:58 -07:00 committed by GitHub
commit c2c0f91385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 20 deletions

View File

@ -121,7 +121,7 @@ func NewCmdAutoscale(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *
cmd.Flags().Int32Var(&o.Min, "min", -1, "The lower limit for the number of pods that can be set by the autoscaler. If it's not specified or negative, the server will apply a default value.") cmd.Flags().Int32Var(&o.Min, "min", -1, "The lower limit for the number of pods that can be set by the autoscaler. If it's not specified or negative, the server will apply a default value.")
cmd.Flags().Int32Var(&o.Max, "max", -1, "The upper limit for the number of pods that can be set by the autoscaler. Required.") cmd.Flags().Int32Var(&o.Max, "max", -1, "The upper limit for the number of pods that can be set by the autoscaler. Required.")
cmd.MarkFlagRequired("max") cmd.MarkFlagRequired("max")
cmd.Flags().Int32Var(&o.CPUPercent, "cpu-percent", -1, fmt.Sprintf("The target average CPU utilization (represented as a percent of requested CPU) over all the pods. If it's not specified or negative, a default autoscaling policy will be used.")) cmd.Flags().Int32Var(&o.CPUPercent, "cpu-percent", -1, "The target average CPU utilization (represented as a percent of requested CPU) over all the pods. If it's not specified or negative, a default autoscaling policy will be used.")
cmd.Flags().StringVar(&o.Name, "name", "", i18n.T("The name for the newly created object. If not specified, the name of the input resource will be used.")) cmd.Flags().StringVar(&o.Name, "name", "", i18n.T("The name for the newly created object. If not specified, the name of the input resource will be used."))
cmdutil.AddDryRunFlag(cmd) cmdutil.AddDryRunFlag(cmd)
cmdutil.AddFilenameOptionFlags(cmd, o.FilenameOptions, "identifying the resource to autoscale.") cmdutil.AddFilenameOptionFlags(cmd, o.FilenameOptions, "identifying the resource to autoscale.")

View File

@ -26,7 +26,6 @@ import (
certificatesv1 "k8s.io/api/certificates/v1" certificatesv1 "k8s.io/api/certificates/v1"
certificatesv1beta1 "k8s.io/api/certificates/v1beta1" certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@ -259,7 +258,7 @@ func (o *CertificateOptions) modifyCertificateCondition(builder *resource.Builde
default: default:
return fmt.Errorf("can only handle certificates.k8s.io CertificateSigningRequest objects, got %T", modifiedCSR) return fmt.Errorf("can only handle certificates.k8s.io CertificateSigningRequest objects, got %T", modifiedCSR)
} }
if errors.IsConflict(err) && i < 10 { if apierrors.IsConflict(err) && i < 10 {
if err := info.Get(); err != nil { if err := info.Get(); err != nil {
return err return err
} }

View File

@ -320,8 +320,7 @@ func (o *CreateIngressOptions) buildIngressSpec() networkingv1.IngressSpec {
} }
func (o *CreateIngressOptions) buildTLSRules() []networkingv1.IngressTLS { func (o *CreateIngressOptions) buildTLSRules() []networkingv1.IngressTLS {
var hostAlreadyPresent map[string]struct{} hostAlreadyPresent := make(map[string]struct{})
hostAlreadyPresent = make(map[string]struct{})
ingressTLSs := []networkingv1.IngressTLS{} ingressTLSs := []networkingv1.IngressTLS{}
var secret string var secret string

View File

@ -20,7 +20,6 @@ import (
"testing" "testing"
networkingv1 "k8s.io/api/networking/v1" networkingv1 "k8s.io/api/networking/v1"
v1 "k8s.io/api/networking/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality" apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@ -192,7 +191,7 @@ func TestCreateIngress(t *testing.T) {
}, },
}, },
}, },
TLS: []v1.IngressTLS{}, TLS: []networkingv1.IngressTLS{},
Rules: []networkingv1.IngressRule{ Rules: []networkingv1.IngressRule{
{ {
Host: "", Host: "",
@ -245,7 +244,7 @@ func TestCreateIngress(t *testing.T) {
}, },
}, },
}, },
TLS: []v1.IngressTLS{ TLS: []networkingv1.IngressTLS{
{ {
SecretName: "secret1", SecretName: "secret1",
}, },
@ -305,7 +304,7 @@ func TestCreateIngress(t *testing.T) {
}, },
}, },
}, },
TLS: []v1.IngressTLS{ TLS: []networkingv1.IngressTLS{
{ {
Hosts: []string{ Hosts: []string{
"foo.com", "foo.com",
@ -456,7 +455,7 @@ func TestCreateIngress(t *testing.T) {
}, },
}, },
Spec: networkingv1.IngressSpec{ Spec: networkingv1.IngressSpec{
TLS: []v1.IngressTLS{ TLS: []networkingv1.IngressTLS{
{ {
Hosts: []string{ Hosts: []string{
"foo.com", "foo.com",

View File

@ -26,7 +26,6 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts" "github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing" cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
@ -1300,7 +1299,7 @@ func TestCompleteAndValidate(t *testing.T) {
args: "--image=busybox --env=FOO=BAR mypod", args: "--image=busybox --env=FOO=BAR mypod",
wantOpts: &DebugOptions{ wantOpts: &DebugOptions{
Args: []string{}, Args: []string{},
Env: []v1.EnvVar{{Name: "FOO", Value: "BAR"}}, Env: []corev1.EnvVar{{Name: "FOO", Value: "BAR"}},
Image: "busybox", Image: "busybox",
Namespace: "test", Namespace: "test",
ShareProcesses: true, ShareProcesses: true,

View File

@ -19,7 +19,6 @@ package get
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
encjson "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -124,13 +123,13 @@ func TestGetUnknownSchemaObject(t *testing.T) {
for i, obj := range actual { for i, obj := range actual {
expectedJSON := runtime.EncodeOrDie(codec, expected[i]) expectedJSON := runtime.EncodeOrDie(codec, expected[i])
expectedMap := map[string]interface{}{} expectedMap := map[string]interface{}{}
if err := encjson.Unmarshal([]byte(expectedJSON), &expectedMap); err != nil { if err := json.Unmarshal([]byte(expectedJSON), &expectedMap); err != nil {
t.Fatal(err) t.Fatal(err)
} }
actualJSON := runtime.EncodeOrDie(codec, obj) actualJSON := runtime.EncodeOrDie(codec, obj)
actualMap := map[string]interface{}{} actualMap := map[string]interface{}{}
if err := encjson.Unmarshal([]byte(actualJSON), &actualMap); err != nil { if err := json.Unmarshal([]byte(actualJSON), &actualMap); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -879,7 +878,7 @@ func TestGetSortedObjectsUnstructuredTable(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
unstructuredBytes, err := encjson.MarshalIndent(unstructuredMap, "", " ") unstructuredBytes, err := json.MarshalIndent(unstructuredMap, "", " ")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -52,7 +52,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
schedulingv1 "k8s.io/api/scheduling/v1" schedulingv1 "k8s.io/api/scheduling/v1"
storagev1 "k8s.io/api/storage/v1" storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
@ -414,7 +413,7 @@ func (d *NamespaceDescriber) Describe(namespace, name string, describerSettings
return newList, nil return newList, nil
}) })
if err != nil { if err != nil {
if errors.IsNotFound(err) { if apierrors.IsNotFound(err) {
// Server does not support resource quotas. // Server does not support resource quotas.
// Not an error, will not show resource quotas information. // Not an error, will not show resource quotas information.
resourceQuotaList = nil resourceQuotaList = nil
@ -434,7 +433,7 @@ func (d *NamespaceDescriber) Describe(namespace, name string, describerSettings
return newList, nil return newList, nil
}) })
if err != nil { if err != nil {
if errors.IsNotFound(err) { if apierrors.IsNotFound(err) {
// Server does not support limit ranges. // Server does not support limit ranges.
// Not an error, will not show limit ranges information. // Not an error, will not show limit ranges information.
limitRangeList = nil limitRangeList = nil
@ -3493,7 +3492,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
} }
nodeNonTerminatedPodsList, err := getPodsInChunks(d.CoreV1().Pods(namespace), initialOpts) nodeNonTerminatedPodsList, err := getPodsInChunks(d.CoreV1().Pods(namespace), initialOpts)
if err != nil { if err != nil {
if !errors.IsForbidden(err) { if !apierrors.IsForbidden(err) {
return "", err return "", err
} }
canViewPods = false canViewPods = false