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

fix: get container ID from kube rather than docker #371

Merged
merged 8 commits into from
Jul 23, 2019

Conversation

rudoi
Copy link
Contributor

@rudoi rudoi commented Apr 1, 2019

Issue #, if available:

#365

Description of changes:

Gets container ID from Kubernetes rather than Docker. This makes the CNI runtime-agnostic.

When using containerd instead of Docker, the CNI essentially skips allocating addresses for all pods because it can't find containers to associate them with. The current retry logic doesn't fail hard when the CNI is unable to connect to a Docker sock. New pods appear to successfully obtain IP addresses, but when the CNI pod restarts, these IPs will all be freed because the CNI will be unable to connect to Docker and therefore will skip allocating IPs for all pods on the host.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mogren mogren added this to the v1.5 milestone Apr 3, 2019
@rudoi rudoi force-pushed the fix/get-container-from-kube branch from a6ee2f9 to 827328e Compare April 4, 2019 18:52
@mogren mogren self-requested a review April 6, 2019 00:17
Copy link
Contributor

@mogren mogren left a comment

Choose a reason for hiding this comment

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

Ran conformance tests and everything looks good. Thanks, this was a nice cleanup, just a small logging comment.

I'll update our dependencies in another PR, guess we don't need the docker client import any more.

pkg/k8sapi/discovery.go Show resolved Hide resolved
@mogren mogren requested a review from nckturner April 8, 2019 22:03
@liwenwu-amazon
Copy link
Contributor

This change needs to be carefully tested out to make sure no same IP can be allocated to different Pods.
ipamD does NOT preserve IP allocations pool state through its restart
During ipamD restart, it first builds IP warm Pool info from instance metadata service, then it talks to Docker to find out the all running Pod's IPs and take running Pod IPs out of IP warm pool. After this, it then responds CNI-ADD request.

To get same info from kube, you need to make sure ipamD have learned all running Pod IPs before start accepting CNI-ADD.

@mogren
Copy link
Contributor

mogren commented Apr 8, 2019

Thanks @liwenwu-amazon, that is good to know. We won't merge this without some more testing.

@rudoi
Copy link
Contributor Author

rudoi commented Apr 9, 2019

@mogren / @liwenwu-amazon

I dumped the list of ENIs on a host running 5 pods, 3 of which were hostNetwork=true, and saw that 2 were allocated as expected. Then, I kill'd the aws-k8s-agent process, causing the pod to restart. After the CNI plugin came back online, I captured the ENI list again and there was no diff between the two ENI dumps.

FWIW, I've been running a cluster off of this branch with several nodes and several dozen pods for about 10 days. A few of the CNI daemonset pods have restarts for various reasons, but I haven't seen any issues so far with duplicate IP allocation.

If there's anything more specific I should run some tests for, please let me know. I'm curious to understand how getting the container ID from kube API vs Docker has an impact on how IPs are allocated. It doesn't seem like the container ID is ever read again after the initial fetch.

@liwenwu-amazon
Copy link
Contributor

@rudoi @mogren I think you should try to restart ipamD while Pods are being scaled up and down rapidly. And make sure there is no race condition when using kube API. Here is one example:

  • Assumes IP warm pool have 200 IPs, and have allocated 150 IPs to Pods, e.g. IP1 ... IP150
  • then ipamD restart
  • ipamD rebuild its IP warm pool to have 200 IPs
  • ipamD starts watching PODs from K8S API Server
  • it start learning pods that were using IP1 to IP 150
  • what if K8S server schedule a new Pod before ipamD finish learning pods (IP1 to IP150), then it might give one of those IP (IP1 to IP150) to this new Pod.

With Docker API, the ipamD make sure it finds out all running Pod before start accepting CNI-add request.

@rudoi
Copy link
Contributor Author

rudoi commented Apr 10, 2019

Understood, @liwenwu-amazon. Thanks for clarifying. I'll try my hardest to cause that race. 😄

@rudoi rudoi force-pushed the fix/get-container-from-kube branch from c387c66 to 574334a Compare April 15, 2019 20:15
@mogren mogren modified the milestones: v1.5, v1.6 May 9, 2019
@mogren
Copy link
Contributor

mogren commented May 10, 2019

@rudoi Hi again!

I like this change, and I think we have some great integration tests to test this. I still bumped this change out to the v1.6 Milestone since I'm trying to get v1.5 out soon. Would you care to rebase this change against the latest master?

@rudoi rudoi force-pushed the fix/get-container-from-kube branch from 574334a to 821467c Compare May 13, 2019 14:49
@rudoi rudoi force-pushed the fix/get-container-from-kube branch from f4e4ee2 to 4a30273 Compare May 13, 2019 15:57
@rudoi
Copy link
Contributor Author

rudoi commented May 13, 2019

@rudoi Hi again!

I like this change, and I think we have some great integration tests to test this. I still bumped this change out to the v1.6 Milestone since I'm trying to get v1.5 out soon. Would you care to rebase this change against the latest master?

Hi @mogren! Rebased, made sure tests are passing, etc. Looking forward to seeing the integration tests! I did some stress testing last week but I wasn't totally satisfied with my scenarios.

@dadux
Copy link

dadux commented May 14, 2019

@rudoi - thanks for this PR.

We are about to deploy some of our clusters with this fix - so hopefully we'll get some real world use case before it gets merged into 1.6.

@rudoi
Copy link
Contributor Author

rudoi commented May 14, 2019

@dadux - awesome, looking forward to seeing the results!

We've been running this for about 3 weeks in real clusters and have not run into anything yet. -fingers crossed-

@mogren mogren removed the request for review from nckturner June 19, 2019 20:32
@dadux
Copy link

dadux commented Jul 23, 2019

Hi @mogren - what is preventing this to get merged ?

Happy to provide some help if needed !

@rudoi
Copy link
Contributor Author

rudoi commented Jul 23, 2019

Happy to help out as well!

@mogren mogren merged commit 14de538 into aws:master Jul 23, 2019
@mogren
Copy link
Contributor

mogren commented Jul 23, 2019

Hey @dadux and @rudoi! I just wanted to run a few more tests to try and catch any potential edge cases. Everything looks good on my end, so thanks a lot. Sorry it took so long to verify the change.

drakedevel pushed a commit to frontapp/amazon-vpc-cni-k8s that referenced this pull request Aug 7, 2019
* fix: get container ID from kube rather than docker
* chore: add log statement when containerID is found
* fix: log containerID after assignment
* fix: update unit tests

(cherry picked from commit 14de538)
drakedevel pushed a commit to frontapp/amazon-vpc-cni-k8s that referenced this pull request Aug 12, 2019
* fix: get container ID from kube rather than docker
* chore: add log statement when containerID is found
* fix: log containerID after assignment
* fix: update unit tests

(cherry picked from commit 14de538)
(cherry picked from commit ef06ed8)
drakedevel pushed a commit to frontapp/amazon-vpc-cni-k8s that referenced this pull request Oct 11, 2019
* fix: get container ID from kube rather than docker
* chore: add log statement when containerID is found
* fix: log containerID after assignment
* fix: update unit tests

(cherry picked from commit 14de538)
(cherry picked from commit ef06ed8)
(cherry picked from commit d644610)
drakedevel added a commit to frontapp/amazon-vpc-cni-k8s that referenced this pull request Nov 12, 2019
drakedevel added a commit to frontapp/amazon-vpc-cni-k8s that referenced this pull request Nov 14, 2019
drakedevel added a commit to frontapp/amazon-vpc-cni-k8s that referenced this pull request Nov 16, 2019
drakedevel added a commit to frontapp/amazon-vpc-cni-k8s that referenced this pull request Nov 25, 2019
jaypipes pushed a commit that referenced this pull request Dec 4, 2019
* Revert "fix: get container ID from kube rather than docker (#371)"

This reverts commit 14de538.

* go mod tidy

* Add initial proof-of-concept implementation of CRI support.

* Update CRI socket path to /var/run/cri.sock

* Filter ready sandboxes and abort if there's a pod UID conflict.

* Revert "fix: get container ID from kube rather than docker (#371)"

This reverts commit 14de538.

* Address review comments, refactor to use pod sandbox nomenclature consistently.

* Bail if we can't retrieve local pod sandboxes on startup.
mogren pushed a commit to mogren/amazon-vpc-cni-k8s that referenced this pull request Dec 4, 2019
* Revert "fix: get container ID from kube rather than docker (aws#371)"

This reverts commit 14de538.

* go mod tidy

* Add initial proof-of-concept implementation of CRI support.

* Update CRI socket path to /var/run/cri.sock

* Filter ready sandboxes and abort if there's a pod UID conflict.

* Revert "fix: get container ID from kube rather than docker (aws#371)"

This reverts commit 14de538.

* Address review comments, refactor to use pod sandbox nomenclature consistently.

* Bail if we can't retrieve local pod sandboxes on startup.
jaypipes pushed a commit that referenced this pull request Dec 5, 2019
)

* Revert "fix: get container ID from kube rather than docker (#371)"

This reverts commit 14de538.

* go mod tidy

* Add initial proof-of-concept implementation of CRI support.

* Update CRI socket path to /var/run/cri.sock

* Filter ready sandboxes and abort if there's a pod UID conflict.

* Revert "fix: get container ID from kube rather than docker (#371)"

This reverts commit 14de538.

* Address review comments, refactor to use pod sandbox nomenclature consistently.

* Bail if we can't retrieve local pod sandboxes on startup.
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.

4 participants