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

print typed podlist for correct serialization #15519

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/cmd/admin/node/listpods.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
kerrors "k8s.io/apimachinery/pkg/util/errors"
kapi "k8s.io/kubernetes/pkg/api"
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
kprinters "k8s.io/kubernetes/pkg/printers"
)
Expand Down Expand Up @@ -90,7 +91,12 @@ func (l *ListPodsOptions) runListPods(node *kapi.Node, printer kprinters.Resourc
// objects for every node, into a single list. This allows output containing multiple nodes to be
// printed to a single writer, and be easily parsed as a single data format.
func (l *ListPodsOptions) handleRESTOutput(nodes []*kapi.Node, printer kprinters.ResourcePrinter) []error {
unifiedPodList := &kapi.PodList{}
unifiedPodList := &kapiv1.PodList{
TypeMeta: metav1.TypeMeta{
Kind: "List",
APIVersion: "v1",
},
}

errList := []error{}
for _, node := range nodes {
Expand All @@ -101,7 +107,7 @@ func (l *ListPodsOptions) handleRESTOutput(nodes []*kapi.Node, printer kprinters
}
fieldSelector := fields.Set{GetPodHostFieldLabel(node.TypeMeta.APIVersion): node.ObjectMeta.Name}.AsSelector()

pods, err := l.Options.KubeClient.Core().Pods(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: labelSelector.String(), FieldSelector: fieldSelector.String()})
pods, err := l.Options.ExternalKubeClient.CoreV1().Pods(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: labelSelector.String(), FieldSelector: fieldSelector.String()})
if err != nil {
errList = append(errList, err)
continue
Expand Down
22 changes: 18 additions & 4 deletions pkg/cmd/admin/node/node_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
kapi "k8s.io/kubernetes/pkg/api"
externalclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/kubectl/resource"
kprinters "k8s.io/kubernetes/pkg/printers"
Expand All @@ -24,10 +25,11 @@ import (
)

type NodeOptions struct {
DefaultNamespace string
KubeClient kclientset.Interface
Writer io.Writer
ErrWriter io.Writer
DefaultNamespace string
KubeClient kclientset.Interface
ExternalKubeClient externalclientset.Interface
Writer io.Writer
ErrWriter io.Writer

Mapper meta.RESTMapper
Typer runtime.ObjectTyper
Expand All @@ -49,10 +51,21 @@ func (n *NodeOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args []st
if err != nil {
return err
}

_, kc, err := f.Clients()
if err != nil {
return err
}

config, err := f.ClientConfig()
if err != nil {
return err
}
externalkc, err := externalclientset.NewForConfig(config)
if err != nil {
return err
}

cmdPrinter, output, err := f.PrinterForCommand(c)
if err != nil {
return err
Expand All @@ -61,6 +74,7 @@ func (n *NodeOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args []st

n.DefaultNamespace = defaultNamespace
n.KubeClient = kc
n.ExternalKubeClient = externalkc
n.Writer = out
n.ErrWriter = errout
n.Mapper = mapper
Expand Down
2 changes: 2 additions & 0 deletions test/cmd/admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ os::cmd::expect_success_and_not_text 'oadm manage-node --selector= --schedulable
os::cmd::expect_success_and_not_text 'oc get node -o yaml' 'unschedulable: true'
os::cmd::expect_success_and_text 'oadm manage-node --selector= --schedulable=false' 'SchedulingDisabled'
os::cmd::expect_success_and_text 'oc get node -o yaml' 'unschedulable: true'
# ensure correct serialization of podList output
os::cmd::expect_success_and_text "oadm manage-node --list-pods --selector= -o jsonpath='{ .kind }'" 'List'
echo "manage-node: ok"
os::test::junit::declare_suite_end

Expand Down