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

Request the pid of another container if current pid is not longer valid #3301

Merged
merged 1 commit into from
May 3, 2023

Conversation

harche
Copy link
Contributor

@harche harche commented May 3, 2023

When using CRI-O as the container runtime, the infrastructure container can be dropped. In this scenario, CRI-O provides cadvisor with the process ID (PID) of one of the containers within the pod to collect network statistics. However, if the particular container exits, cadvisor is left with an invalid PID. To address this issue, this PR makes cadvisor to switch to another PID from the same pod, ensuring the continuous collection of network statistics.

Pod used to validate this change,

apiVersion: v1
kind: Pod
metadata:
  name: init-sleep-pod
spec:
  initContainers:
  - name: init-sleep
    image: busybox
    command: ["sh", "-c", "sleep 60"]
  containers:
  - name: forever-sleep
    image: busybox
    command: ["sh", "-c", "while true; do sleep 1; done"]

@k8s-ci-robot
Copy link
Collaborator

Hi @harche. Thanks for your PR.

I'm waiting for a google member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@harche
Copy link
Contributor Author

harche commented May 3, 2023

/cc @haircommander @rphillips

@rphillips
Copy link
Contributor

/lgtm
/assign @bobbypage

Comment on lines 309 to 321
if len(stats.Network.Interfaces) == 0 {
// No network related information indicates that the pid of the
// container is not longer valid and we need to ask crio to
// provide the pid of another container from that pod
h.pidKnown = false
return stats, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should double check h.needNet() here, or else we may needlessly recall into cri-o because a container didn't provide the network stats

Copy link
Contributor

Choose a reason for hiding this comment

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

we can just combine this check as else if len(...) below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@haircommander Thanks, good point. Updated.

Comment on lines 309 to 314
if h.needNet() && len(stats.Network.Interfaces) == 0 {
// No network related information indicates that the pid of the
// container is not longer valid and we need to ask crio to
// provide the pid of another container from that pod
h.pidKnown = false
return stats, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer these two conditions are switched so we don't have to call needsNet twice:

if !h.needNet() {
....
} else if len(...) {
....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@haircommander Done. Thanks.

Signed-off-by: Harshal Patil <harpatil@redhat.com>
Co-authored-by: Ryan Phillips <rphillips@redhat.com>
@haircommander
Copy link
Contributor

/lgtm

thanks!

@rphillips
Copy link
Contributor

/assign @bobbypage @dims

Copy link
Collaborator

@dims dims left a comment

Choose a reason for hiding this comment

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

LGTM

@dims
Copy link
Collaborator

dims commented May 3, 2023

/ok-to-test

@dims
Copy link
Collaborator

dims commented May 3, 2023

/approve
/lgtm

@mrunalp mrunalp merged commit 29e8539 into google:master May 3, 2023
@bobbypage
Copy link
Collaborator

lgtm, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants