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

kubelet/kubenet: split hostport handling into separate module #26934

Merged
merged 2 commits into from
Jun 18, 2016

Conversation

dcbw
Copy link
Member

@dcbw dcbw commented Jun 7, 2016

This pulls the hostport functionality of kubenet out into a separate module so that it can be more easily tested and potentially used from other code (maybe CNI, maybe downstream consumers like OpenShift, etc). Couldn't find a mock iptables so I wrote one, but I didn't look very hard.

@freehan @thockin @bprashanth

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note-label-needed labels Jun 7, 2016
@dcbw
Copy link
Member Author

dcbw commented Jun 7, 2016

2016/06/07 07:20:44 e2e.go:212: Running: build-release
ERROR: gcloud crashed (error): [Errno 111] Connection refused

@dcbw
Copy link
Member Author

dcbw commented Jun 7, 2016

@k8s-bot test this issue: #23545

@dcbw
Copy link
Member Author

dcbw commented Jun 7, 2016

Sigh... a couple instances of:

  Timed out after 300.000s.
  Expected
      <*errors.errorString | 0xc820acd9b0>: {
          s: "expected metrics for kubelet",
      }
  to be nil

which seems to be flake #26431

@dcbw
Copy link
Member Author

dcbw commented Jun 7, 2016

@k8s-bot test this issue: #26431

@dcbw
Copy link
Member Author

dcbw commented Jun 7, 2016

cc @danwinship @pravisankar

// Open any hostports the pod's containers want
runningPods, err := plugin.getRunningPods()
if err == nil {
err = plugin.hostportHandler.OpenPodHostportsAndSync(pod, BridgeName, runningPods)
Copy link
Contributor

@freehan freehan Jun 7, 2016

Choose a reason for hiding this comment

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

Say if the CNI ADD succeeded, but port is in use. SetUpPod will end up setting up the veth but fail at opening hostport. IIUC, kubelet will just kill infra container without calling TearDownPod (it assumes SetUpPod won't be partially successful). Then this Pod will stuck, because CNI ADD will always return failure since eth0 has been setup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Need some restructure. Other parts looks good overall.

Copy link
Member Author

Choose a reason for hiding this comment

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

Say if the CNI ADD succeeded, but port is in use. SetUpPod will end up setting up the veth but fail at opening hostport. IIUC, kubelet will just kill infra container without calling TearDownPod (it assumes SetUpPod won't be partially successful). Then this Pod will stuck, because CNI ADD will always return failure since eth0 has been setup.

You are correct that this PR will exacerbate the situation a bit, so I'll try to fix that. However, it looks like all the network plugins have problems with this, since they don't necessarily clean up after themselves on errors in SetUpPod(). And since (at least) dockertools/manager.go never calls TearDownPod() when setup fails, I think there are already cases where failures will leave the pod network configured... I'll try to figure something out here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think the pod will actually get stuck, since eth0 will get destroyed along with the infra container's network namespace. But what won't be cleaned up is any IPAM leases or shaper stuff.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh that is even worse, because kubelet will keep retry and used up all IPs. :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Researching this more indicates that the docker runtime will eventually tear down the infra container. I'm not sure about the rkt runtime. But depending on the runtime to call TearDownPod() on a SetUpPod() failure seems pretty fragile, and I think the plugins should do it themsevles if they can.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. That is mostly because network plugin is event triggered.

I was thinking adding a Reconcile interface into network plugin. It can be triggered periodically and do whatever it want to ensure/cleanup network configuration.

@dcbw
Copy link
Member Author

dcbw commented Jun 7, 2016

Still flaking on #26431...

@freehan freehan self-assigned this Jun 7, 2016
return false, nil
}

func normalizeRule(rule string) (string, error) {
Copy link
Contributor

@danwinship danwinship Jun 9, 2016

Choose a reason for hiding this comment

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

do we have a shell-command-line-parsing utility somewhere?

maybe this function should panic/fail if it hits something that it's not going to parse correctly (eg, '\"' or '\' [that's backslash space])

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, or just fix it to normalize the []string form rather than the string form

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not easy to do []string normalization, because the rules coming from Save()/SaveAll() are already in string-form, and we'd need to split them apart into []string and handle quoted comments.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 10, 2016
@dcbw
Copy link
Member Author

dcbw commented Jun 13, 2016

@freehan @danwinship PTAL, thanks!

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 13, 2016
@dcbw dcbw force-pushed the split-hostport branch 3 times, most recently from 200f879 to 841e320 Compare June 14, 2016 17:59
@dcbw
Copy link
Member Author

dcbw commented Jun 15, 2016

  • go install ./cmd/...
    Build was aborted
    Aborted by Mike Danese
    [xUnit] [INFO] - Starting to record.

@dcbw
Copy link
Member Author

dcbw commented Jun 15, 2016

@k8s-bot test this issue: #IGNORE

}
}

func NewTestHostportHandler(iptables utiliptables.Interface, portOpener hostportOpener) HostportHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe put this in hostport_test?

@dcbw
Copy link
Member Author

dcbw commented Jun 15, 2016

@freehan @danwinship PTAL, thanks!

runningPods := make([]*hostport.RunningPod, 0)
for _, p := range pods {
for _, c := range p.Containers {
if c.Name != dockertools.PodInfraContainerName {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment here for something like "Assuming pod specs yield by runtime.GetPods include name and ID of containers in pod"

if err := plugin.setup(namespace, name, id, pod); err != nil {
// Make sure everything gets cleaned up on errors
podIP, _ := plugin.podIPs[id]
plugin.teardown(namespace, name, id, podIP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe log the err from teardown ?

@freehan
Copy link
Contributor

freehan commented Jun 15, 2016

I just have a bunch of nits.

dcbw added 2 commits June 16, 2016 13:44
Relying on the runtime to later call cleanup is fragile, so make sure
that everything gets nicely cleaned up when setup errors occur.
@dcbw
Copy link
Member Author

dcbw commented Jun 16, 2016

@freehan updated for your comments, PTAL

@freehan
Copy link
Contributor

freehan commented Jun 16, 2016

LGTM. This is great! We should get it in. Maybe for 1.3.1
Pending on tests.

@k8s-bot
Copy link

k8s-bot commented Jun 16, 2016

GCE e2e build/test passed for commit a519e8a.

@freehan freehan added cherrypick-candidate release-note-none Denotes a PR that doesn't merit a release note. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. and removed release-note-label-needed labels Jun 16, 2016
@freehan freehan added this to the v1.3 milestone Jun 16, 2016
@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 Jun 18, 2016

GCE e2e build/test passed for commit a519e8a.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

@k8s-github-robot k8s-github-robot merged commit d80b60e into kubernetes:master Jun 18, 2016
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. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants