Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code cleanup for kubectl #101004

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion staging/src/k8s.io/kubectl/pkg/cmd/autoscale/autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Max, "max", -1, "The upper limit for the number of pods that can be set by the autoscaler. Required.")
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."))
cmdutil.AddDryRunFlag(cmd)
cmdutil.AddFilenameOptionFlags(cmd, o.FilenameOptions, "identifying the resource to autoscale.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
certificatesv1 "k8s.io/api/certificates/v1"
certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -251,7 +250,7 @@ func (o *CertificateOptions) modifyCertificateCondition(builder *resource.Builde
default:
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 {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions staging/src/k8s.io/kubectl/pkg/cmd/create/create_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ func (o *CreateIngressOptions) buildIngressSpec() networkingv1.IngressSpec {
}

func (o *CreateIngressOptions) buildTLSRules() []networkingv1.IngressTLS {
var hostAlreadyPresent map[string]struct{}
hostAlreadyPresent = make(map[string]struct{})
hostAlreadyPresent := make(map[string]struct{})

ingressTLSs := []networkingv1.IngressTLS{}
var secret string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"

networkingv1 "k8s.io/api/networking/v1"
v1 "k8s.io/api/networking/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -192,7 +191,7 @@ func TestCreateIngress(t *testing.T) {
},
},
},
TLS: []v1.IngressTLS{},
TLS: []networkingv1.IngressTLS{},
Rules: []networkingv1.IngressRule{
{
Host: "",
Expand Down Expand Up @@ -245,7 +244,7 @@ func TestCreateIngress(t *testing.T) {
},
},
},
TLS: []v1.IngressTLS{
TLS: []networkingv1.IngressTLS{
{
SecretName: "secret1",
},
Expand Down Expand Up @@ -305,7 +304,7 @@ func TestCreateIngress(t *testing.T) {
},
},
},
TLS: []v1.IngressTLS{
TLS: []networkingv1.IngressTLS{
{
Hosts: []string{
"foo.com",
Expand Down Expand Up @@ -456,7 +455,7 @@ func TestCreateIngress(t *testing.T) {
},
},
Spec: networkingv1.IngressSpec{
TLS: []v1.IngressTLS{
TLS: []networkingv1.IngressTLS{
{
Hosts: []string{
"foo.com",
Expand Down
3 changes: 1 addition & 2 deletions staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
Expand Down Expand Up @@ -1272,7 +1271,7 @@ func TestCompleteAndValidate(t *testing.T) {
args: "--image=busybox --env=FOO=BAR mypod",
wantOpts: &DebugOptions{
Args: []string{},
Env: []v1.EnvVar{{Name: "FOO", Value: "BAR"}},
Env: []corev1.EnvVar{{Name: "FOO", Value: "BAR"}},
Image: "busybox",
Namespace: "test",
ShareProcesses: true,
Expand Down
7 changes: 3 additions & 4 deletions staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package get
import (
"bytes"
"encoding/json"
encjson "encoding/json"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -124,13 +123,13 @@ func TestGetUnknownSchemaObject(t *testing.T) {
for i, obj := range actual {
expectedJSON := runtime.EncodeOrDie(codec, expected[i])
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)
}

actualJSON := runtime.EncodeOrDie(codec, obj)
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)
}

Expand Down Expand Up @@ -879,7 +878,7 @@ func TestGetSortedObjectsUnstructuredTable(t *testing.T) {
if err != nil {
t.Fatal(err)
}
unstructuredBytes, err := encjson.MarshalIndent(unstructuredMap, "", " ")
unstructuredBytes, err := json.MarshalIndent(unstructuredMap, "", " ")
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 3 additions & 4 deletions staging/src/k8s.io/kubectl/pkg/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -413,7 +412,7 @@ func (d *NamespaceDescriber) Describe(namespace, name string, describerSettings
return newList, nil
})
if err != nil {
if errors.IsNotFound(err) {
if apierrors.IsNotFound(err) {
// Server does not support resource quotas.
// Not an error, will not show resource quotas information.
resourceQuotaList = nil
Expand All @@ -433,7 +432,7 @@ func (d *NamespaceDescriber) Describe(namespace, name string, describerSettings
return newList, nil
})
if err != nil {
if errors.IsNotFound(err) {
if apierrors.IsNotFound(err) {
// Server does not support limit ranges.
// Not an error, will not show limit ranges information.
limitRangeList = nil
Expand Down Expand Up @@ -3483,7 +3482,7 @@ func (d *NodeDescriber) Describe(namespace, name string, describerSettings Descr
}
nodeNonTerminatedPodsList, err := getPodsInChunks(d.CoreV1().Pods(namespace), initialOpts)
if err != nil {
if !errors.IsForbidden(err) {
if !apierrors.IsForbidden(err) {
return "", err
}
canViewPods = false
Expand Down