mirror of https://github.com/k3s-io/k3s
Merge pull request #66967 from deads2k/kubectl-09-naughty
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. stop adding internal types to external schemes at some point someone starting internal types to external schemes in kubectl tests. This fixes that mistake. @kubernetes/sig-cli-maintainers /assign @soltysh ```release-note NONE ```pull/8/head
commit
dab04dc6e0
|
@ -220,7 +220,6 @@ go_test(
|
|||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/strategicpatch:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/testing:go_default_library",
|
||||
|
|
|
@ -43,7 +43,6 @@ import (
|
|||
"k8s.io/client-go/rest/fake"
|
||||
clienttesting "k8s.io/client-go/testing"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
|
@ -146,9 +145,9 @@ func readReplicationController(t *testing.T, filenameRC string) (string, []byte)
|
|||
return metaAccessor.GetName(), rcBytes
|
||||
}
|
||||
|
||||
func readReplicationControllerFromFile(t *testing.T, filename string) *api.ReplicationController {
|
||||
func readReplicationControllerFromFile(t *testing.T, filename string) *corev1.ReplicationController {
|
||||
data := readBytesFromFile(t, filename)
|
||||
rc := api.ReplicationController{}
|
||||
rc := corev1.ReplicationController{}
|
||||
if err := runtime.DecodeInto(testapi.Default.Codec(), data, &rc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -165,9 +164,9 @@ func readUnstructuredFromFile(t *testing.T, filename string) *unstructured.Unstr
|
|||
return &unst
|
||||
}
|
||||
|
||||
func readServiceFromFile(t *testing.T, filename string) *api.Service {
|
||||
func readServiceFromFile(t *testing.T, filename string) *corev1.Service {
|
||||
data := readBytesFromFile(t, filename)
|
||||
svc := api.Service{}
|
||||
svc := corev1.Service{}
|
||||
if err := runtime.DecodeInto(testapi.Default.Codec(), data, &svc); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -204,7 +203,7 @@ func annotateRuntimeObject(t *testing.T, originalObj, currentObj runtime.Object,
|
|||
if currentAnnotations == nil {
|
||||
currentAnnotations = make(map[string]string)
|
||||
}
|
||||
currentAnnotations[api.LastAppliedConfigAnnotation] = string(original)
|
||||
currentAnnotations[corev1.LastAppliedConfigAnnotation] = string(original)
|
||||
currentAccessor.SetAnnotations(currentAnnotations)
|
||||
current, err := runtime.Encode(unstructured.JSONFallbackEncoder{Encoder: testapi.Default.Codec()}, currentObj)
|
||||
if err != nil {
|
||||
|
@ -244,7 +243,7 @@ func validatePatchApplication(t *testing.T, req *http.Request) {
|
|||
}
|
||||
|
||||
annotationsMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
||||
if _, ok := annotationsMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||
if _, ok := annotationsMap[corev1.LastAppliedConfigAnnotation]; !ok {
|
||||
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
||||
}
|
||||
|
||||
|
@ -408,9 +407,9 @@ func TestRunApplyViewLastApplied(t *testing.T) {
|
|||
bodyRC := ioutil.NopCloser(bytes.NewReader(test.respBytes))
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: bodyRC}, nil
|
||||
case p == "/namespaces/test/replicationcontrollers/no-match" && m == "GET":
|
||||
return &http.Response{StatusCode: 404, Header: defaultHeader(), Body: objBody(codec, &api.Pod{})}, nil
|
||||
return &http.Response{StatusCode: 404, Header: defaultHeader(), Body: objBody(codec, &corev1.Pod{})}, nil
|
||||
case p == "/api/v1/namespaces/test" && m == "GET":
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &corev1.Namespace{})}, nil
|
||||
default:
|
||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||
return nil, nil
|
||||
|
@ -895,7 +894,7 @@ func TestApplyNULLPreservation(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
annotationMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
||||
if _, ok := annotationMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||
if _, ok := annotationMap[corev1.LastAppliedConfigAnnotation]; !ok {
|
||||
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
||||
}
|
||||
strategy := walkMapPath(t, patchMap, []string{"spec", "strategy"})
|
||||
|
@ -1135,13 +1134,13 @@ func TestRunApplySetLastApplied(t *testing.T) {
|
|||
bodyRC := ioutil.NopCloser(bytes.NewReader(noAnnotationRC))
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: bodyRC}, nil
|
||||
case p == noExistPath && m == "GET":
|
||||
return &http.Response{StatusCode: 404, Header: defaultHeader(), Body: objBody(codec, &api.Pod{})}, nil
|
||||
return &http.Response{StatusCode: 404, Header: defaultHeader(), Body: objBody(codec, &corev1.Pod{})}, nil
|
||||
case p == pathRC && m == "PATCH":
|
||||
checkPatchString(t, req)
|
||||
bodyRC := ioutil.NopCloser(bytes.NewReader(currentRC))
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: bodyRC}, nil
|
||||
case p == "/api/v1/namespaces/test" && m == "GET":
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &corev1.Namespace{})}, nil
|
||||
default:
|
||||
t.Fatalf("unexpected request: %#v\n%#v", req.URL, req)
|
||||
return nil, nil
|
||||
|
@ -1183,7 +1182,7 @@ func checkPatchString(t *testing.T, req *http.Request) {
|
|||
}
|
||||
|
||||
annotationsMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
||||
if _, ok := annotationsMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||
if _, ok := annotationsMap[corev1.LastAppliedConfigAnnotation]; !ok {
|
||||
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
||||
}
|
||||
|
||||
|
@ -1230,7 +1229,7 @@ func TestForceApply(t *testing.T) {
|
|||
var bodyRC io.ReadCloser
|
||||
if isScaledDownToZero {
|
||||
rcObj := readReplicationControllerFromFile(t, filenameRC)
|
||||
rcObj.Spec.Replicas = 0
|
||||
rcObj.Spec.Replicas = int32ptr(0)
|
||||
rcBytes, err := runtime.Encode(testapi.Default.Codec(), rcObj)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"github.com/golang/glog"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
|
@ -71,9 +71,9 @@ type AttachOptions struct {
|
|||
CommandName string
|
||||
SuggestedCmdUsage string
|
||||
|
||||
Pod *apiv1.Pod
|
||||
Pod *corev1.Pod
|
||||
|
||||
AttachFunc func(*AttachOptions, *apiv1.Container, bool, remotecommand.TerminalSizeQueue) func() error
|
||||
AttachFunc func(*AttachOptions, *corev1.Container, bool, remotecommand.TerminalSizeQueue) func() error
|
||||
Resources []string
|
||||
Builder func() *resource.Builder
|
||||
AttachablePodFn polymorphichelpers.AttachableLogsForObjectFunc
|
||||
|
@ -119,7 +119,7 @@ type RemoteAttach interface {
|
|||
Attach(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool, terminalSizeQueue remotecommand.TerminalSizeQueue) error
|
||||
}
|
||||
|
||||
func defaultAttachFunc(o *AttachOptions, containerToAttach *apiv1.Container, raw bool, sizeQueue remotecommand.TerminalSizeQueue) func() error {
|
||||
func defaultAttachFunc(o *AttachOptions, containerToAttach *corev1.Container, raw bool, sizeQueue remotecommand.TerminalSizeQueue) func() error {
|
||||
return func() error {
|
||||
restClient, err := restclient.RESTClientFor(o.Config)
|
||||
if err != nil {
|
||||
|
@ -130,7 +130,7 @@ func defaultAttachFunc(o *AttachOptions, containerToAttach *apiv1.Container, raw
|
|||
Name(o.Pod.Name).
|
||||
Namespace(o.Pod.Namespace).
|
||||
SubResource("attach")
|
||||
req.VersionedParams(&apiv1.PodAttachOptions{
|
||||
req.VersionedParams(&corev1.PodAttachOptions{
|
||||
Container: containerToAttach.Name,
|
||||
Stdin: o.Stdin,
|
||||
Stdout: o.Out != nil,
|
||||
|
@ -241,7 +241,7 @@ func (o *AttachOptions) Run() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if o.Pod.Status.Phase == apiv1.PodSucceeded || o.Pod.Status.Phase == apiv1.PodFailed {
|
||||
if o.Pod.Status.Phase == corev1.PodSucceeded || o.Pod.Status.Phase == corev1.PodFailed {
|
||||
return fmt.Errorf("cannot attach a container in a completed pod; current phase is %s", o.Pod.Status.Phase)
|
||||
}
|
||||
// TODO: convert this to a clean "wait" behavior
|
||||
|
@ -289,13 +289,13 @@ func (o *AttachOptions) Run() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if o.Stdin && t.Raw && o.Pod.Spec.RestartPolicy == apiv1.RestartPolicyAlways {
|
||||
if o.Stdin && t.Raw && o.Pod.Spec.RestartPolicy == corev1.RestartPolicyAlways {
|
||||
fmt.Fprintf(o.Out, "Session ended, resume using '%s %s -c %s -i -t' command when the pod is running\n", o.CommandName, o.Pod.Name, containerToAttach.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *AttachOptions) findAttachablePod(obj runtime.Object) (*apiv1.Pod, error) {
|
||||
func (o *AttachOptions) findAttachablePod(obj runtime.Object) (*corev1.Pod, error) {
|
||||
attachablePod, err := o.AttachablePodFn(o.restClientGetter, obj, o.GetPodTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -307,7 +307,7 @@ func (o *AttachOptions) findAttachablePod(obj runtime.Object) (*apiv1.Pod, error
|
|||
|
||||
// containerToAttach returns a reference to the container to attach to, given
|
||||
// by name or the first container if name is empty.
|
||||
func (o *AttachOptions) containerToAttachTo(pod *apiv1.Pod) (*apiv1.Container, error) {
|
||||
func (o *AttachOptions) containerToAttachTo(pod *corev1.Pod) (*corev1.Container, error) {
|
||||
if len(o.ContainerName) > 0 {
|
||||
for i := range pod.Spec.Containers {
|
||||
if pod.Spec.Containers[i].Name == o.ContainerName {
|
||||
|
@ -332,7 +332,7 @@ func (o *AttachOptions) containerToAttachTo(pod *apiv1.Pod) (*apiv1.Container, e
|
|||
}
|
||||
|
||||
// GetContainerName returns the name of the container to attach to, with a fallback.
|
||||
func (o *AttachOptions) GetContainerName(pod *apiv1.Pod) (string, error) {
|
||||
func (o *AttachOptions) GetContainerName(pod *corev1.Pod) (string, error) {
|
||||
c, err := o.containerToAttachTo(pod)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -23,10 +23,10 @@ import (
|
|||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
genericprinters "k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
"k8s.io/kubernetes/pkg/printers"
|
||||
)
|
||||
|
||||
|
@ -84,7 +84,7 @@ func TestIllegalPackageSourceCheckerThroughPrintFlags(t *testing.T) {
|
|||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
printFlags := genericclioptions.NewPrintFlags("succeeded").WithTypeSetter(scheme.Scheme)
|
||||
printFlags := genericclioptions.NewPrintFlags("succeeded").WithTypeSetter(legacyscheme.Scheme)
|
||||
printFlags.OutputFormat = &tc.output
|
||||
|
||||
printer, err := printFlags.ToPrinter()
|
||||
|
@ -132,7 +132,7 @@ func TestIllegalPackageSourceCheckerDirectlyThroughPrinters(t *testing.T) {
|
|||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
customColumns, err := printers.NewCustomColumnsPrinterFromSpec("NAME:.metadata.name", scheme.Codecs.UniversalDecoder(), true)
|
||||
customColumns, err := printers.NewCustomColumnsPrinterFromSpec("NAME:.metadata.name", legacyscheme.Codecs.UniversalDecoder(), true)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
|
|
@ -26,27 +26,20 @@ import (
|
|||
"reflect"
|
||||
stdstrings "strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
)
|
||||
|
||||
// This init should be removed after switching this command and its tests to user external types.
|
||||
func init() {
|
||||
utilruntime.Must(api.AddToScheme(scheme.Scheme))
|
||||
}
|
||||
|
||||
func initTestErrorHandler(t *testing.T) {
|
||||
cmdutil.BehaviorOnFatal(func(str string, code int) {
|
||||
t.Errorf("Error running command (exit code %d): %s", code, str)
|
||||
|
@ -70,45 +63,45 @@ func defaultClientConfig() *restclient.Config {
|
|||
}
|
||||
}
|
||||
|
||||
func testData() (*api.PodList, *api.ServiceList, *api.ReplicationControllerList) {
|
||||
pods := &api.PodList{
|
||||
func testData() (*corev1.PodList, *corev1.ServiceList, *corev1.ReplicationControllerList) {
|
||||
pods := &corev1.PodList{
|
||||
ListMeta: metav1.ListMeta{
|
||||
ResourceVersion: "15",
|
||||
},
|
||||
Items: []api.Pod{
|
||||
Items: []corev1.Pod{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "test", ResourceVersion: "10"},
|
||||
Spec: apitesting.DeepEqualSafePodSpec(),
|
||||
Spec: apitesting.V1DeepEqualSafePodSpec(),
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "bar", Namespace: "test", ResourceVersion: "11"},
|
||||
Spec: apitesting.DeepEqualSafePodSpec(),
|
||||
Spec: apitesting.V1DeepEqualSafePodSpec(),
|
||||
},
|
||||
},
|
||||
}
|
||||
svc := &api.ServiceList{
|
||||
svc := &corev1.ServiceList{
|
||||
ListMeta: metav1.ListMeta{
|
||||
ResourceVersion: "16",
|
||||
},
|
||||
Items: []api.Service{
|
||||
Items: []corev1.Service{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.ServiceSpec{
|
||||
Spec: corev1.ServiceSpec{
|
||||
SessionAffinity: "None",
|
||||
Type: api.ServiceTypeClusterIP,
|
||||
Type: corev1.ServiceTypeClusterIP,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
rc := &api.ReplicationControllerList{
|
||||
rc := &corev1.ReplicationControllerList{
|
||||
ListMeta: metav1.ListMeta{
|
||||
ResourceVersion: "17",
|
||||
},
|
||||
Items: []api.ReplicationController{
|
||||
Items: []corev1.ReplicationController{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "rc1", Namespace: "test", ResourceVersion: "18"},
|
||||
Spec: api.ReplicationControllerSpec{
|
||||
Replicas: 1,
|
||||
Spec: corev1.ReplicationControllerSpec{
|
||||
Replicas: int32ptr(1),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -116,6 +109,11 @@ func testData() (*api.PodList, *api.ServiceList, *api.ReplicationControllerList)
|
|||
return pods, svc, rc
|
||||
}
|
||||
|
||||
func int32ptr(val int) *int32 {
|
||||
t := int32(val)
|
||||
return &t
|
||||
}
|
||||
|
||||
func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
|
||||
return ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, obj))))
|
||||
}
|
||||
|
@ -132,98 +130,6 @@ func stringBody(body string) io.ReadCloser {
|
|||
return ioutil.NopCloser(bytes.NewReader([]byte(body)))
|
||||
}
|
||||
|
||||
func newAllPhasePodList() *api.PodList {
|
||||
nodeName := "kubernetes-node-abcd"
|
||||
return &api.PodList{
|
||||
Items: []api.Pod{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test1",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: make([]api.Container, 2),
|
||||
NodeName: nodeName,
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodPending,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test2",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: make([]api.Container, 2),
|
||||
NodeName: nodeName,
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test3",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: make([]api.Container, 2),
|
||||
NodeName: nodeName,
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodSucceeded,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test4",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: make([]api.Container, 2),
|
||||
NodeName: nodeName,
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodFailed,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test5",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now().AddDate(-10, 0, 0)},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: make([]api.Container, 2),
|
||||
NodeName: nodeName,
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodUnknown,
|
||||
ContainerStatuses: []api.ContainerStatus{
|
||||
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
|
||||
{RestartCount: 3},
|
||||
},
|
||||
},
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizationFuncGlobalExistence(t *testing.T) {
|
||||
// This test can be safely deleted when we will not support multiple flag formats
|
||||
root := NewKubectlCommand(os.Stdin, os.Stdout, os.Stderr)
|
||||
|
|
|
@ -26,10 +26,10 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
|
||||
|
@ -274,7 +274,7 @@ func TestDeleteObjectGraceZero(t *testing.T) {
|
|||
return &http.Response{StatusCode: 404, Header: defaultHeader(), Body: objBody(codec, &metav1.Status{})}, nil
|
||||
}
|
||||
case p == "/api/v1/namespaces/test" && m == "GET":
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &corev1.Namespace{})}, nil
|
||||
case p == "/namespaces/test/pods/nginx" && m == "DELETE":
|
||||
return &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, &pods.Items[0])}, nil
|
||||
default:
|
||||
|
@ -371,8 +371,8 @@ func TestDeleteAllNotFound(t *testing.T) {
|
|||
initTestErrorHandler(t)
|
||||
_, svc, _ := testData()
|
||||
// Add an item to the list which will result in a 404 on delete
|
||||
svc.Items = append(svc.Items, api.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
||||
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus
|
||||
svc.Items = append(svc.Items, corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
||||
notFoundError := &errors.NewNotFound(corev1.Resource("services"), "foo").ErrStatus
|
||||
|
||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||
defer tf.Cleanup()
|
||||
|
@ -426,8 +426,8 @@ func TestDeleteAllIgnoreNotFound(t *testing.T) {
|
|||
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||
|
||||
// Add an item to the list which will result in a 404 on delete
|
||||
svc.Items = append(svc.Items, api.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
||||
notFoundError := &errors.NewNotFound(api.Resource("services"), "foo").ErrStatus
|
||||
svc.Items = append(svc.Items, corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
||||
notFoundError := &errors.NewNotFound(corev1.Resource("services"), "foo").ErrStatus
|
||||
|
||||
tf.UnstructuredClient = &fake.RESTClient{
|
||||
NegotiatedSerializer: unstructuredSerializer,
|
||||
|
|
|
@ -29,11 +29,11 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
|
@ -172,7 +172,7 @@ func TestExec(t *testing.T) {
|
|||
version := "v1"
|
||||
tests := []struct {
|
||||
name, podPath, execPath string
|
||||
pod *api.Pod
|
||||
pod *corev1.Pod
|
||||
execErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -251,20 +251,20 @@ func TestExec(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func execPod() *api.Pod {
|
||||
return &api.Pod{
|
||||
func execPod() *corev1.Pod {
|
||||
return &corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "test", ResourceVersion: "10"},
|
||||
Spec: api.PodSpec{
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
Containers: []api.Container{
|
||||
Spec: corev1.PodSpec{
|
||||
RestartPolicy: corev1.RestartPolicyAlways,
|
||||
DNSPolicy: corev1.DNSClusterFirst,
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: api.PodStatus{
|
||||
Phase: api.PodRunning,
|
||||
Status: corev1.PodStatus{
|
||||
Phase: corev1.PodRunning,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,19 +27,12 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
)
|
||||
|
||||
// This init should be removed after switching this command and its tests to user external types.
|
||||
func init() {
|
||||
utilruntime.Must(api.AddToScheme(scheme.Scheme))
|
||||
}
|
||||
|
||||
func TestRunExposeService(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
|
@ -68,7 +68,6 @@ go_test(
|
|||
deps = [
|
||||
"//pkg/api/testing:go_default_library",
|
||||
"//pkg/apis/core:go_default_library",
|
||||
"//pkg/apis/core/v1:go_default_library",
|
||||
"//pkg/kubectl/cmd/testing:go_default_library",
|
||||
"//pkg/kubectl/cmd/util:go_default_library",
|
||||
"//pkg/kubectl/cmd/util/openapi:go_default_library",
|
||||
|
@ -88,7 +87,6 @@ go_test(
|
|||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer/streaming:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/rest:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/rest/fake:go_default_library",
|
||||
|
|
|
@ -39,14 +39,12 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime/serializer/json"
|
||||
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
restclientwatch "k8s.io/client-go/rest/watch"
|
||||
"k8s.io/kube-openapi/pkg/util/proto"
|
||||
apitesting "k8s.io/kubernetes/pkg/api/testing"
|
||||
"k8s.io/kubernetes/pkg/apis/core/v1"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
|
||||
|
@ -58,13 +56,6 @@ import (
|
|||
|
||||
var openapiSchemaPath = filepath.Join("..", "..", "..", "..", "api", "openapi-spec", "swagger.json")
|
||||
|
||||
// This init should be removed after switching this command and its tests to user external types.
|
||||
func init() {
|
||||
utilruntime.Must(api.AddToScheme(scheme.Scheme))
|
||||
utilruntime.Must(scheme.Scheme.AddConversionFuncs(v1.Convert_core_PodSpec_To_v1_PodSpec))
|
||||
utilruntime.Must(scheme.Scheme.AddConversionFuncs(v1.Convert_v1_PodSecurityContext_To_core_PodSecurityContext))
|
||||
}
|
||||
|
||||
var unstructuredSerializer = resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer
|
||||
|
||||
func defaultHeader() http.Header {
|
||||
|
|
|
@ -25,12 +25,10 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
|
@ -54,7 +52,7 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
|
|||
tests := []struct {
|
||||
name string
|
||||
podPath, pfPath string
|
||||
pod *api.Pod
|
||||
pod *corev1.Pod
|
||||
pfErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -77,12 +75,12 @@ func testPortForward(t *testing.T, flags map[string]string, args []string) {
|
|||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||
defer tf.Cleanup()
|
||||
|
||||
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||
ns := legacyscheme.Codecs
|
||||
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||
ns := scheme.Codecs
|
||||
|
||||
tf.Client = &fake.RESTClient{
|
||||
VersionedAPIPath: "/api/v1",
|
||||
GroupVersion: schema.GroupVersion{Group: ""},
|
||||
GroupVersion: schema.GroupVersion{Group: "", Version: "v1"},
|
||||
NegotiatedSerializer: ns,
|
||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
switch p, m := req.URL.Path, req.Method; {
|
||||
|
@ -146,17 +144,17 @@ func TestPortForward(t *testing.T) {
|
|||
func TestTranslateServicePortToTargetPort(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
svc v1.Service
|
||||
pod v1.Pod
|
||||
svc corev1.Service
|
||||
pod corev1.Pod
|
||||
ports []string
|
||||
translated []string
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
name: "test success 1 (int port)",
|
||||
svc: v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
svc: corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(8080),
|
||||
|
@ -164,11 +162,11 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
pod: v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
pod: corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []v1.ContainerPort{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
Name: "http",
|
||||
ContainerPort: int32(8080)},
|
||||
|
@ -183,10 +181,10 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "test success 2 (clusterIP: None)",
|
||||
svc: v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
svc: corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
ClusterIP: "None",
|
||||
Ports: []v1.ServicePort{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromInt(8080),
|
||||
|
@ -194,11 +192,11 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
pod: v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
pod: corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []v1.ContainerPort{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
Name: "http",
|
||||
ContainerPort: int32(8080)},
|
||||
|
@ -213,9 +211,9 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "test success 3 (named port)",
|
||||
svc: v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
svc: corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromString("http"),
|
||||
|
@ -227,11 +225,11 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
pod: v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
pod: corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []v1.ContainerPort{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
Name: "http",
|
||||
ContainerPort: int32(8080)},
|
||||
|
@ -249,20 +247,20 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "test success (targetPort omitted)",
|
||||
svc: v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
svc: corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pod: v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
pod: corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []v1.ContainerPort{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
Name: "http",
|
||||
ContainerPort: int32(80)},
|
||||
|
@ -277,9 +275,9 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "test failure 1 (named port lookup failure)",
|
||||
svc: v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
svc: corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromString("http"),
|
||||
|
@ -287,11 +285,11 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
pod: v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
pod: corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []v1.ContainerPort{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
Name: "https",
|
||||
ContainerPort: int32(443)},
|
||||
|
@ -306,9 +304,9 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "test failure 2 (service port not declared)",
|
||||
svc: v1.Service{
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
svc: corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
TargetPort: intstr.FromString("http"),
|
||||
|
@ -316,11 +314,11 @@ func TestTranslateServicePortToTargetPort(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
pod: v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
pod: corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []v1.ContainerPort{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{
|
||||
Name: "https",
|
||||
ContainerPort: int32(443)},
|
||||
|
|
|
@ -21,8 +21,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
|
@ -41,7 +41,7 @@ func TestReplaceObject(t *testing.T) {
|
|||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
switch p, m := req.URL.Path, req.Method; {
|
||||
case p == "/api/v1/namespaces/test" && m == http.MethodGet:
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &corev1.Namespace{})}, nil
|
||||
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == http.MethodDelete:
|
||||
deleted = true
|
||||
fallthrough
|
||||
|
@ -98,7 +98,7 @@ func TestReplaceMultipleObject(t *testing.T) {
|
|||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
switch p, m := req.URL.Path, req.Method; {
|
||||
case p == "/api/v1/namespaces/test" && m == http.MethodGet:
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &corev1.Namespace{})}, nil
|
||||
case p == "/namespaces/test/replicationcontrollers/redis-master" && m == http.MethodDelete:
|
||||
redisMasterDeleted = true
|
||||
fallthrough
|
||||
|
@ -167,7 +167,7 @@ func TestReplaceDirectory(t *testing.T) {
|
|||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
switch p, m := req.URL.Path, req.Method; {
|
||||
case p == "/api/v1/namespaces/test" && m == http.MethodGet:
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &corev1.Namespace{})}, nil
|
||||
case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers/") && m == http.MethodPut:
|
||||
created[p] = true
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &rc.Items[0])}, nil
|
||||
|
@ -223,7 +223,7 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
|
|||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
switch p, m := req.URL.Path, req.Method; {
|
||||
case p == "/api/v1/namespaces/test" && m == http.MethodGet:
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
|
||||
return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &corev1.Namespace{})}, nil
|
||||
case p == "/namespaces/test/replicationcontrollers/redis-master" && (m == http.MethodGet || m == http.MethodDelete):
|
||||
return &http.Response{StatusCode: http.StatusNotFound, Header: defaultHeader(), Body: stringBody("")}, nil
|
||||
case p == "/namespaces/test/replicationcontrollers" && m == http.MethodPost:
|
||||
|
|
|
@ -34,7 +34,6 @@ import (
|
|||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
|
@ -46,11 +45,6 @@ import (
|
|||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||
)
|
||||
|
||||
// This init should be removed after switching this command and its tests to user external types.
|
||||
func init() {
|
||||
utilruntime.Must(api.AddToScheme(scheme.Scheme))
|
||||
}
|
||||
|
||||
func TestGetRestartPolicy(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
|
|
|
@ -30,7 +30,6 @@ import (
|
|||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/apimachinery/pkg/util/validation"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
|
@ -164,7 +163,7 @@ func (o *TaintOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
|
|||
return cmdutil.UsageErrorf(cmd, err.Error())
|
||||
}
|
||||
o.builder = f.NewBuilder().
|
||||
WithScheme(legacyscheme.Scheme).
|
||||
WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).
|
||||
ContinueOnError().
|
||||
NamespaceParam(namespace).DefaultNamespace()
|
||||
if o.selector != "" {
|
||||
|
@ -246,11 +245,7 @@ func (o TaintOptions) RunTaint() error {
|
|||
return err
|
||||
}
|
||||
|
||||
obj, err := legacyscheme.Scheme.ConvertToVersion(info.Object, v1.SchemeGroupVersion)
|
||||
if err != nil {
|
||||
glog.V(1).Info(err)
|
||||
return fmt.Errorf("object was not a node.v1.: %T", info.Object)
|
||||
}
|
||||
obj := info.Object
|
||||
name, namespace := info.Name, info.Namespace
|
||||
oldData, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
|
|
|
@ -23,31 +23,30 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
||||
)
|
||||
|
||||
func generateNodeAndTaintedNode(oldTaints []v1.Taint, newTaints []v1.Taint) (*v1.Node, *v1.Node) {
|
||||
var taintedNode *v1.Node
|
||||
func generateNodeAndTaintedNode(oldTaints []corev1.Taint, newTaints []corev1.Taint) (*corev1.Node, *corev1.Node) {
|
||||
var taintedNode *corev1.Node
|
||||
|
||||
// Create a node.
|
||||
node := &v1.Node{
|
||||
node := &corev1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "node-name",
|
||||
CreationTimestamp: metav1.Time{Time: time.Now()},
|
||||
},
|
||||
Spec: v1.NodeSpec{
|
||||
Spec: corev1.NodeSpec{
|
||||
Taints: oldTaints,
|
||||
},
|
||||
Status: v1.NodeStatus{},
|
||||
Status: corev1.NodeStatus{},
|
||||
}
|
||||
|
||||
// A copy of the same node, but tainted.
|
||||
|
@ -57,7 +56,7 @@ func generateNodeAndTaintedNode(oldTaints []v1.Taint, newTaints []v1.Taint) (*v1
|
|||
return node, taintedNode
|
||||
}
|
||||
|
||||
func equalTaints(taintsA, taintsB []v1.Taint) bool {
|
||||
func equalTaints(taintsA, taintsB []corev1.Taint) bool {
|
||||
if len(taintsA) != len(taintsB) {
|
||||
return false
|
||||
}
|
||||
|
@ -80,8 +79,8 @@ func equalTaints(taintsA, taintsB []v1.Taint) bool {
|
|||
func TestTaint(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
oldTaints []v1.Taint
|
||||
newTaints []v1.Taint
|
||||
oldTaints []corev1.Taint
|
||||
newTaints []corev1.Taint
|
||||
args []string
|
||||
expectFatal bool
|
||||
expectTaint bool
|
||||
|
@ -89,7 +88,7 @@ func TestTaint(t *testing.T) {
|
|||
// success cases
|
||||
{
|
||||
description: "taints a node with effect NoSchedule",
|
||||
newTaints: []v1.Taint{{
|
||||
newTaints: []corev1.Taint{{
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
Effect: "NoSchedule",
|
||||
|
@ -100,7 +99,7 @@ func TestTaint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
description: "taints a node with effect PreferNoSchedule",
|
||||
newTaints: []v1.Taint{{
|
||||
newTaints: []corev1.Taint{{
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
Effect: "PreferNoSchedule",
|
||||
|
@ -111,12 +110,12 @@ func TestTaint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
description: "update an existing taint on the node, change the value from bar to barz",
|
||||
oldTaints: []v1.Taint{{
|
||||
oldTaints: []corev1.Taint{{
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
Effect: "NoSchedule",
|
||||
}},
|
||||
newTaints: []v1.Taint{{
|
||||
newTaints: []corev1.Taint{{
|
||||
Key: "foo",
|
||||
Value: "barz",
|
||||
Effect: "NoSchedule",
|
||||
|
@ -127,7 +126,7 @@ func TestTaint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
description: "taints a node with two taints",
|
||||
newTaints: []v1.Taint{{
|
||||
newTaints: []corev1.Taint{{
|
||||
Key: "dedicated",
|
||||
Value: "namespaceA",
|
||||
Effect: "NoSchedule",
|
||||
|
@ -142,7 +141,7 @@ func TestTaint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
description: "node has two taints with the same key but different effect, remove one of them by indicating exact key and effect",
|
||||
oldTaints: []v1.Taint{{
|
||||
oldTaints: []corev1.Taint{{
|
||||
Key: "dedicated",
|
||||
Value: "namespaceA",
|
||||
Effect: "NoSchedule",
|
||||
|
@ -151,7 +150,7 @@ func TestTaint(t *testing.T) {
|
|||
Value: "namespaceA",
|
||||
Effect: "PreferNoSchedule",
|
||||
}},
|
||||
newTaints: []v1.Taint{{
|
||||
newTaints: []corev1.Taint{{
|
||||
Key: "dedicated",
|
||||
Value: "namespaceA",
|
||||
Effect: "PreferNoSchedule",
|
||||
|
@ -162,7 +161,7 @@ func TestTaint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
description: "node has two taints with the same key but different effect, remove all of them with wildcard",
|
||||
oldTaints: []v1.Taint{{
|
||||
oldTaints: []corev1.Taint{{
|
||||
Key: "dedicated",
|
||||
Value: "namespaceA",
|
||||
Effect: "NoSchedule",
|
||||
|
@ -171,14 +170,14 @@ func TestTaint(t *testing.T) {
|
|||
Value: "namespaceA",
|
||||
Effect: "PreferNoSchedule",
|
||||
}},
|
||||
newTaints: []v1.Taint{},
|
||||
newTaints: []corev1.Taint{},
|
||||
args: []string{"node", "node-name", "dedicated-"},
|
||||
expectFatal: false,
|
||||
expectTaint: true,
|
||||
},
|
||||
{
|
||||
description: "node has two taints, update one of them and remove the other",
|
||||
oldTaints: []v1.Taint{{
|
||||
oldTaints: []corev1.Taint{{
|
||||
Key: "dedicated",
|
||||
Value: "namespaceA",
|
||||
Effect: "NoSchedule",
|
||||
|
@ -187,7 +186,7 @@ func TestTaint(t *testing.T) {
|
|||
Value: "bar",
|
||||
Effect: "PreferNoSchedule",
|
||||
}},
|
||||
newTaints: []v1.Taint{{
|
||||
newTaints: []corev1.Taint{{
|
||||
Key: "foo",
|
||||
Value: "barz",
|
||||
Effect: "PreferNoSchedule",
|
||||
|
@ -218,12 +217,12 @@ func TestTaint(t *testing.T) {
|
|||
},
|
||||
{
|
||||
description: "can't update existing taint on the node, since 'overwrite' flag is not set",
|
||||
oldTaints: []v1.Taint{{
|
||||
oldTaints: []corev1.Taint{{
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
Effect: "NoSchedule",
|
||||
}},
|
||||
newTaints: []v1.Taint{{
|
||||
newTaints: []corev1.Taint{{
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
Effect: "NoSchedule",
|
||||
|
@ -237,16 +236,17 @@ func TestTaint(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
oldNode, expectNewNode := generateNodeAndTaintedNode(test.oldTaints, test.newTaints)
|
||||
new_node := &v1.Node{}
|
||||
new_node := &corev1.Node{}
|
||||
tainted := false
|
||||
tf := cmdtesting.NewTestFactory()
|
||||
defer tf.Cleanup()
|
||||
|
||||
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||
ns := legacyscheme.Codecs
|
||||
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||
ns := scheme.Codecs
|
||||
|
||||
tf.Client = &fake.RESTClient{
|
||||
NegotiatedSerializer: ns,
|
||||
GroupVersion: corev1.SchemeGroupVersion,
|
||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
m := &MyReq{req}
|
||||
switch {
|
||||
|
@ -267,7 +267,7 @@ func TestTaint(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
||||
}
|
||||
appliedPatch, err := strategicpatch.StrategicMergePatch(oldJSON, data, &v1.Node{})
|
||||
appliedPatch, err := strategicpatch.StrategicMergePatch(oldJSON, data, &corev1.Node{})
|
||||
if err != nil {
|
||||
t.Fatalf("%s: unexpected error: %v", test.description, err)
|
||||
}
|
||||
|
@ -308,7 +308,10 @@ func TestTaint(t *testing.T) {
|
|||
func() {
|
||||
defer func() {
|
||||
// Recover from the panic below.
|
||||
_ = recover()
|
||||
if r := recover(); r != nil {
|
||||
t.Logf("Recovered: %v", r)
|
||||
}
|
||||
|
||||
// Restore cmdutil behavior
|
||||
cmdutil.DefaultBehaviorOnFatal()
|
||||
}()
|
||||
|
|
|
@ -94,14 +94,10 @@ func (c *RESTClient) request(verb string) *restclient.Request {
|
|||
|
||||
ns := c.NegotiatedSerializer
|
||||
info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
||||
internalVersion := schema.GroupVersion{
|
||||
Group: c.GroupVersion.Group,
|
||||
Version: runtime.APIVersionInternal,
|
||||
}
|
||||
serializers := restclient.Serializers{
|
||||
// TODO this was hardcoded before, but it doesn't look right
|
||||
Encoder: ns.EncoderForVersion(info.Serializer, c.GroupVersion),
|
||||
Decoder: ns.DecoderToVersion(info.Serializer, internalVersion),
|
||||
Decoder: ns.DecoderToVersion(info.Serializer, c.GroupVersion),
|
||||
}
|
||||
if info.StreamSerializer != nil {
|
||||
serializers.StreamingSerializer = info.StreamSerializer.Serializer
|
||||
|
|
Loading…
Reference in New Issue