mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
Merge pull request #14888 from JanetKuo/kubectl-get-list
Auto commit by PR queue bot
This commit is contained in:
commit
0fb7c80edf
@ -775,8 +775,7 @@ __EOF__
|
||||
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'mock:'
|
||||
# Command
|
||||
# kubectl create -f $file "${kube_flags[@]}" # test fails here now
|
||||
# TODO: test get when PR "Fix get with List #14888" is merged
|
||||
# kubectl get -f $file "${kube_flags[@]}"
|
||||
kubectl get -f $file "${kube_flags[@]}"
|
||||
kubectl describe -f $file "${kube_flags[@]}"
|
||||
# Command
|
||||
# TODO: remove --validate=false when PR "Add validate support for list kind #14726" is merged
|
||||
|
@ -220,7 +220,7 @@ func RunGet(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
|
||||
}
|
||||
|
||||
// use the default printer for each object
|
||||
return b.Do().Visit(func(r *resource.Info, err error) error {
|
||||
return b.Flatten().Do().Visit(func(r *resource.Info, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -86,29 +86,29 @@ func testData() (*api.PodList, *api.ServiceList, *api.ReplicationControllerList)
|
||||
}
|
||||
|
||||
func testComponentStatusData() *api.ComponentStatusList {
|
||||
good := &api.ComponentStatus{
|
||||
good := api.ComponentStatus{
|
||||
Conditions: []api.ComponentCondition{
|
||||
{Type: api.ComponentHealthy, Status: api.ConditionTrue, Message: "ok", Error: "nil"},
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{Name: "servergood", Namespace: "test"},
|
||||
}
|
||||
good.Name = "servergood"
|
||||
|
||||
bad := &api.ComponentStatus{
|
||||
bad := api.ComponentStatus{
|
||||
Conditions: []api.ComponentCondition{
|
||||
{Type: api.ComponentHealthy, Status: api.ConditionFalse, Message: "", Error: "bad status: 500"},
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{Name: "serverbad", Namespace: "test"},
|
||||
}
|
||||
bad.Name = "serverbad"
|
||||
|
||||
unknown := &api.ComponentStatus{
|
||||
unknown := api.ComponentStatus{
|
||||
Conditions: []api.ComponentCondition{
|
||||
{Type: api.ComponentHealthy, Status: api.ConditionUnknown, Message: "", Error: "fizzbuzz error"},
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{Name: "serverunknown", Namespace: "test"},
|
||||
}
|
||||
unknown.Name = "serverunknown"
|
||||
|
||||
return &api.ComponentStatusList{
|
||||
Items: []api.ComponentStatus{*good, *bad, *unknown},
|
||||
Items: []api.ComponentStatus{good, bad, unknown},
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,16 +314,33 @@ func TestGetListObjects(t *testing.T) {
|
||||
cmd.SetOutput(buf)
|
||||
cmd.Run(cmd, []string{"pods"})
|
||||
|
||||
expected := []runtime.Object{pods}
|
||||
expected, err := extractResourceList([]runtime.Object{pods})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
actual := tf.Printer.(*testPrinter).Objects
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("unexpected object: %#v %#v", expected, actual)
|
||||
t.Errorf("unexpected object: expected %#v, got %#v", expected, actual)
|
||||
}
|
||||
if len(buf.String()) == 0 {
|
||||
t.Errorf("unexpected empty output")
|
||||
}
|
||||
}
|
||||
|
||||
func extractResourceList(objs []runtime.Object) ([]runtime.Object, error) {
|
||||
finalObjs := []runtime.Object{}
|
||||
for _, obj := range objs {
|
||||
items, err := runtime.ExtractList(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, item := range items {
|
||||
finalObjs = append(finalObjs, item)
|
||||
}
|
||||
}
|
||||
return finalObjs, nil
|
||||
}
|
||||
|
||||
func TestGetAllListObjects(t *testing.T) {
|
||||
pods, _, _ := testData()
|
||||
|
||||
@ -341,7 +358,10 @@ func TestGetAllListObjects(t *testing.T) {
|
||||
cmd.Flags().Set("show-all", "true")
|
||||
cmd.Run(cmd, []string{"pods"})
|
||||
|
||||
expected := []runtime.Object{pods}
|
||||
expected, err := extractResourceList([]runtime.Object{pods})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
actual := tf.Printer.(*testPrinter).Objects
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("unexpected object: %#v %#v", expected, actual)
|
||||
@ -367,10 +387,13 @@ func TestGetListComponentStatus(t *testing.T) {
|
||||
cmd.SetOutput(buf)
|
||||
cmd.Run(cmd, []string{"componentstatuses"})
|
||||
|
||||
expected := []runtime.Object{statuses}
|
||||
expected, err := extractResourceList([]runtime.Object{statuses})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
actual := tf.Printer.(*testPrinter).Objects
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("unexpected object: %#v %#v", expected, actual)
|
||||
t.Errorf("unexpected object: expected %#v, got %#v", expected, actual)
|
||||
}
|
||||
if len(buf.String()) == 0 {
|
||||
t.Errorf("unexpected empty output")
|
||||
@ -403,7 +426,10 @@ func TestGetMultipleTypeObjects(t *testing.T) {
|
||||
cmd.SetOutput(buf)
|
||||
cmd.Run(cmd, []string{"pods,services"})
|
||||
|
||||
expected := []runtime.Object{pods, svc}
|
||||
expected, err := extractResourceList([]runtime.Object{pods, svc})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
actual := tf.Printer.(*testPrinter).Objects
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("unexpected object: %#v", actual)
|
||||
@ -504,7 +530,10 @@ func TestGetMultipleTypeObjectsWithSelector(t *testing.T) {
|
||||
cmd.Flags().Set("selector", "a=b")
|
||||
cmd.Run(cmd, []string{"pods,services"})
|
||||
|
||||
expected := []runtime.Object{pods, svc}
|
||||
expected, err := extractResourceList([]runtime.Object{pods, svc})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
actual := tf.Printer.(*testPrinter).Objects
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Errorf("unexpected object: %#v", actual)
|
||||
|
Loading…
Reference in New Issue
Block a user