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

Put pod full name, namespace and uid into docker label #16414

Merged

Conversation

Random-Liu
Copy link
Member

This PR mainly did 3 things:

  1. Add file container_labels.go, and move label and filter functions into it, so as to simplify the label related code and prepare for adding more labels in the future.
  2. Add pod full name filter in GetPodStatus() so that ListContainers() will only list containers belong to the target pod.
  3. Add related test case and make fakeDockerContainer support label filter.

Some questions or TODOs:

  1. A lot of manually initialized containers in old test cases of dockertools don't have docker labels, if they use functions using label filter (current now only GetPodStatus() uses label filter), the test case may get unexpected result. I added a simple function to set default labels, but it is still inconvenient to add label for each test case. In this PR I just modified test cases which went wrong. Should I add label for each test case? Or should I think a better way?
  2. In fact, pod full name label was added before https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockertools/manager.go#L701. Can I assume that even old containers have pod name label? If not, I should comment my filter code and uncomment it in the future.

(For issue #15089)

@Random-Liu Random-Liu changed the title Put pod full name into dockerlabel Put pod full name into docker label and use label filter to simplify GetPodStatus() Oct 28, 2015
@k8s-github-robot
Copy link

Labelling this PR as size/L

@k8s-github-robot k8s-github-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 28, 2015
@k8s-bot
Copy link

k8s-bot commented Oct 28, 2015

GCE e2e test build/test passed for commit 998413c4ccc83748273b4f5fbfda06e71c30193f.

@k8s-bot
Copy link

k8s-bot commented Oct 28, 2015

GCE e2e test build/test passed for commit 99b9207798f0876c64b8ba198fad8e3d5a224d8c.

@ncdc
Copy link
Member

ncdc commented Oct 28, 2015

@kubernetes/rh-cluster-infra @mfojtik @smarterclayton

@k8s-bot
Copy link

k8s-bot commented Oct 28, 2015

GCE e2e test build/test passed for commit 99b9207798f0876c64b8ba198fad8e3d5a224d8c.

@ashcrow
Copy link
Contributor

ashcrow commented Oct 28, 2015

Shippable failure is likely a flake:

FAIL    k8s.io/kubernetes/pkg/storage/etcd  14.651s

@Random-Liu
Copy link
Member Author

Yeah, maybe. I passed the test locally.

@k8s-bot
Copy link

k8s-bot commented Oct 28, 2015

GCE e2e test build/test passed for commit 99b9207798f0876c64b8ba198fad8e3d5a224d8c.

@k8s-bot
Copy link

k8s-bot commented Oct 28, 2015

GCE e2e test build/test passed for commit 99b9207798f0876c64b8ba198fad8e3d5a224d8c.

@Random-Liu
Copy link
Member Author

@ashcrow Thanks! :)

@k8s-bot
Copy link

k8s-bot commented Oct 28, 2015

GCE e2e test build/test passed for commit f22dbc26286164356e191d48527a9e87ea134112.

@k8s-bot
Copy link

k8s-bot commented Oct 29, 2015

GCE e2e test build/test passed for commit f22dbc26286164356e191d48527a9e87ea134112.

@Random-Liu Random-Liu closed this Oct 29, 2015
@Random-Liu Random-Liu reopened this Oct 29, 2015
@@ -211,6 +211,7 @@ func (p throttledDockerPuller) IsImagePresent(name string) (bool, error) {
return p.puller.IsImagePresent(name)
}

// TODO (random-liu) Almost never used, should we remove this?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is used by GetKubeletDockerContainers. Do you want to rewrite the function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha, what I mean is that we defined the the type "DockerContainers", and defined the function "FindPodContainer". But it seems that we just use "DockerContainers" as slice of APIcontainers (https://github.com/kubernetes/kubernetes/search?utf8=%E2%9C%93&q=GetKubeletDockerContainers&type=Code), never use function like FindPodContainer. So I just wonder whether we should remove this type, :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Just curious when reading the code, so add a comment here. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it was used in other places but we gradually migrated off. Personally I'd be happy to see the type be removed. Feel free to send a PR for this :)

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. :) Thanks! Haha~

@yujuhong
Copy link
Contributor

@Random-Liu, could you remove the "label filtering" code from this PR? I think this PR should focus on writing the labels :-)

kubernetesPodNameLabel = "io.kubernetes.pod.name"
kubernetesPodNamespaceLabel = "io.kubernetes.pod.namespace"

kubernetesPodLabel = "io.kubernetes.pod.data"
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this meant for? It is not clear from the variable name. Can you add comments?

Copy link
Contributor

Choose a reason for hiding this comment

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

@vishh, @Random-Liu didn't add this. This was added for PreStop hook and the label contains the entire serialized pod... I want to remove this. See #/14768 for the details.

edit: we only found out about this label yesterday

Copy link
Member Author

Choose a reason for hiding this comment

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

@yujuhong I read code about this yesterday, it seems that one of the options is to add some "better-formatted" labels on each container (rather than add the whole pod data), for example add a label like "container_metadata" and write all needed data like PreStop handler into it...

@Random-Liu
Copy link
Member Author

OK. I'll remove the filter related code in this PR. :)

@Random-Liu Random-Liu changed the title Put pod full name into docker label and use label filter to simplify GetPodStatus() Put pod full name, namespace and uid into docker label Oct 29, 2015
@k8s-bot
Copy link

k8s-bot commented Oct 29, 2015

GCE e2e test build/test passed for commit 68dab7f0b430421f3f4c3a0008ccb67be2932b14.

// Get restartCount from docker label. If there is no restart count label in an container,
// it should be an old container or an invalid container, we just set restart count to 0.
// Don't report error, because there must be many old containers without the label now
glog.V(3).Infof("Container doesn't have label %s, it may be an old or invalid container", kubernetesContainerRestartCountLabel)
Copy link
Contributor

Choose a reason for hiding this comment

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

For the logging message to be meaningful in anyway, we need the container id. I'd suggest returning (int, error) and let the caller handle the error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok!

@@ -1643,8 +1620,8 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubetypes.Docker
return "", err
}

// There is no meaningful labels for infraContainer now, so just pass nil.
id, err := dm.runContainerInPod(pod, container, netNamespace, getIPCMode(pod), getPidMode(pod), nil)
// Current now we don't care about restart count of infra container, just set it to 0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove "Current now"

FYI, you can use "currently" or not use it at all (implied). "Current now" is not grammatically correct :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops(corrected)...I don't even know where I learned it. I really need more suggestions like this about my grammar, words etc. Thank you very much! :)

@yujuhong
Copy link
Contributor

lgtm with some nits :)

@k8s-bot
Copy link

k8s-bot commented Oct 29, 2015

GCE e2e test build/test passed for commit 29bb7941200da8923895f5f7bd31afb9400de8c6.

@yujuhong
Copy link
Contributor

lgtm. please squash.

@Random-Liu
Copy link
Member Author

Sure. Thanks :)

@Random-Liu Random-Liu force-pushed the put-podname-into-label branch from 29bb794 to b3585a5 Compare October 30, 2015 05:43
@Random-Liu
Copy link
Member Author

Squashed. :)

@k8s-bot
Copy link

k8s-bot commented Oct 30, 2015

GCE e2e build/test failed for commit b3585a5.

@k8s-bot
Copy link

k8s-bot commented Oct 30, 2015

GCE e2e test build/test passed for commit b3585a5.

@yujuhong yujuhong added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 30, 2015
@a-robinson
Copy link
Contributor

@k8s-bot unit test this

@k8s-github-robot
Copy link

The author of this PR is not in the whitelist for merge, can one of the admins add the 'ok-to-merge' label?

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Oct 30, 2015

GCE e2e test build/test passed for commit b3585a5.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants