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

group podLists from different nodes into single list #11216

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Oct 4, 2016

Related Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1381621

When listing pods as JSON or YAML for one or more nodes with oadm manage-node, the
node name is printed to stderr, while the PodList object is printed to stdout.

This patch updates the output of oadm manage-node --list-pods to join the list of
pods of every node into a single PodList, allowing the output to consist of a single
api.PodList object.

Before

$ oadm manage-node --selector="type=infra" --list-pods -o json

Listing matched pods on node: ip-172-31-53-15.ec2.internal

{
    "metadata": {
        "selfLink": "/api/v1/pods",
        "resourceVersion": "350009"
    },
    "items": [
        {
....
}

Listing matched pods on node: ip-172-31-53-16.ec2.internal

{
    "metadata": {
        "selfLink": "/api/v1/pods",
        "resourceVersion": "350009"
    },
    "items": [
        {
...
}

After

"items" will contain the pods of every node

$ oadm manage-node --selector="type=infra" --list-pods -o json
{
    "metadata": {
        "selfLink": "/api/v1/pods",
        "resourceVersion": "350009"
    },
    "items": [
        {
...
}

@openshift/cli-review

@liggitt
Copy link
Contributor

liggitt commented Oct 4, 2016

it still requires redirection of stderr to /dev/null on the cli

why?

this made-up format is not a valid API list type... and will not work with any of the other oadm/oc commands

@liggitt
Copy link
Contributor

liggitt commented Oct 4, 2016

if you want pods for a particular node, run oadm manage-node <node-name>

if you want to know what node a particular pod is on, just look at the spec.nodeName field on the pod

@juanvallejo
Copy link
Contributor Author

juanvallejo commented Oct 4, 2016

@liggitt Thanks for the feedback, I'll close this PR

EDIT: reopened PR, rather than changing the format of the output, the new commit groups the list of pods of every node into a single list to be printed by a json or yaml printer.

@juanvallejo juanvallejo closed this Oct 4, 2016
@juanvallejo juanvallejo reopened this Oct 4, 2016
@juanvallejo juanvallejo force-pushed the jvallejo/group-podlists-w-corresponding-node branch from 299fadf to 978eaf0 Compare October 4, 2016 23:16
// determine if printer kind is json or yaml and modify output
// to combine all pod lists into a single list
switch printer.(type) {
case *kubectl.JSONPrinter:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type checking these smells bad... why not flatten the list for all custom output types?

@juanvallejo
Copy link
Contributor Author

[test]

@juanvallejo juanvallejo changed the title group podLists w corresponding node in REST output group podLists from different nodes into single list Oct 5, 2016
@juanvallejo
Copy link
Contributor Author

@liggitt PTAL

}

if unifiedPodList == nil {
unifiedPodList = pods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful about using the first list as the aggregate... not sure the selfLink or resourceVersion will be right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liggitt Hm, I am not sure how to handle cases where either selfLink or resourceVersion fields are different between PodLists. Should I use the last node's PodList as the aggregate, or maybe the list with the most recent resourceVersion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or aggregate them into a newly constructed PodList without a selfLink or resourceVersion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liggitt Sounds good, thanks for the feedback 627f33e

@juanvallejo
Copy link
Contributor Author

@liggitt PTAL

// 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 kubectl.ResourcePrinter) []error {
var unifiedPodList *kapi.PodList
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not always initialize it? I'd expect an empty list if there were no pods

errList = append(errList, err)
}

if unifiedPodList == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this simplifies to a straight append, then

@juanvallejo
Copy link
Contributor Author

@liggitt Thanks for the feedback! Review comments addressed


pods, err := l.Options.Kclient.Pods(kapi.NamespaceAll).List(kapi.ListOptions{LabelSelector: labelSelector, FieldSelector: fieldSelector})
if err != nil {
errList = append(errList, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue here, don't go on to use pods, which is likely nil in this case

@liggitt
Copy link
Contributor

liggitt commented Oct 11, 2016

one last comment, @fabianofranz has final LGTM

@juanvallejo juanvallejo force-pushed the jvallejo/group-podlists-w-corresponding-node branch from 1d71d7a to d15311e Compare October 11, 2016 21:26
@juanvallejo
Copy link
Contributor Author

@liggitt Thanks for the review

@juanvallejo
Copy link
Contributor Author

integration, conformance flake on yum, #8571, re[test]

@fabianofranz
Copy link
Member

squash then LGTM

@juanvallejo juanvallejo force-pushed the jvallejo/group-podlists-w-corresponding-node branch from d15311e to 101b8de Compare October 13, 2016 20:42
@juanvallejo
Copy link
Contributor Author

@fabianofranz Done!

@fabianofranz
Copy link
Member

[merge]

@juanvallejo
Copy link
Contributor Author

conformance flaked on #11094

@fabianofranz
Copy link
Member

flaked on #11094 re[merge]

@fabianofranz
Copy link
Member

@juanvallejo

# github.com/openshift/origin/pkg/cmd/admin/node
pkg/cmd/admin/node/listpods.go:93: l.Options.Kclient undefined (type *NodeOptions has no field or method Kclient)

Related Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1381621

When listing pods as JSON or YAML for one or more nodes with `oadm manage-node`, the
node name is printed to stderr, while the PodList object is printed to stdout.

This patch updates the output of `oadm manage-node --list-pods` to join the list of
pods of every node into a single PodList, allowing the output to consist of a single
api.PodList object.

**Before**
```
$ oadm manage-node --selector="type=infra" --list-pods -o json

Listing matched pods on node: ip-172-31-53-15.ec2.internal

{
    "metadata": {
        "selfLink": "/api/v1/pods",
        "resourceVersion": "350009"
    },
    "items": [
        {
....
}

Listing matched pods on node: ip-172-31-53-16.ec2.internal

{
    "metadata": {
        "selfLink": "/api/v1/pods",
        "resourceVersion": "350009"
    },
    "items": [
        {
...
}
```

**After**

`"items" will contain the pods of every node`
```
$ oadm manage-node --selector="type=infra" --list-pods -o json
{
    "metadata": {
        "selfLink": "/api/v1/pods",
        "resourceVersion": "350009"
    },
    "items": [
        {
...
}
```
@juanvallejo juanvallejo force-pushed the jvallejo/group-podlists-w-corresponding-node branch from 101b8de to 048b9bd Compare October 20, 2016 16:01
@juanvallejo
Copy link
Contributor Author

@fabianofranz hm, looks like it was renamed to KubeClient in a recent PR, I have updated this and it's building locally once again

re[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 048b9bd

@fabianofranz
Copy link
Member

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 048b9bd

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10320/) (Base Commit: 9ef2b7f)

@openshift-bot
Copy link
Contributor

openshift-bot commented Oct 22, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10462/) (Base Commit: 8a79d34) (Image: devenv-rhel7_5222)

@openshift-bot openshift-bot merged commit f0bfbaa into openshift:master Oct 22, 2016
@juanvallejo juanvallejo deleted the jvallejo/group-podlists-w-corresponding-node branch October 24, 2016 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants