Skip to content

Use kubernetes shared informers in OpenShift network plugins #14030

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

Merged
merged 9 commits into from
May 18, 2017

Conversation

pravisankar
Copy link

Changed network policy plugin to do pod watch for all namespaces (one go routine for the cluster) instead of pod watch for each namespace (go routine for each namespace).

@pravisankar
Copy link
Author

@openshift/networking PTAL

var expectedObjType interface{}

switch resourceName {
case Nodes:
Copy link
Contributor

Choose a reason for hiding this comment

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

You call this func with 4 different ResourceName values (Namespaces, Services, Pods, Nodes) but only support Nodes?

Copy link
Author

Choose a reason for hiding this comment

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

oops, missed updating this method for the other resource names. Updated

@pravisankar pravisankar force-pushed the sdn-use-shared-informers branch from 3630f4e to 60dfe15 Compare May 3, 2017 18:16
@pravisankar
Copy link
Author

[testextended][extended:networking]

@pravisankar
Copy link
Author

[test]

@pravisankar pravisankar force-pushed the sdn-use-shared-informers branch 3 times, most recently from 9e50cb2 to 4089a7a Compare May 4, 2017 19:51
Copy link
Contributor

@dcbw dcbw left a comment

Choose a reason for hiding this comment

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

Generally LGTM.

// threads modify this map.
oldPod, podExisted := np.pods[pod.UID]
if (podExisted && oldPod.Status.PodIP == pod.Status.PodIP && reflect.DeepEqual(oldPod.Labels, pod.Labels)) ||
(pod.Status.PodIP == "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could there ever be a pod Update event where PodIP = ""? Likely not probably, but maybe we should handle that as a pod deletion?

Copy link
Author

Choose a reason for hiding this comment

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

I realized deleting pod in this case is not a good idea. Pod network plugin setup is only called for pods with HostNetwork=false but watch pods do get pods that has HostNetwork=true and podIP is not set in this case. Since HostNetwork check was missing in watch pods, we could have deleted a valid pod. I will add HostNetwork check in watch pods and will log a warning if podIP is not set.

log.Errorf("Error creating subnet for node %s, ip %s: %v", node.Name, nodeIP, err)
return
}
master.hostSubnetNodeIPs[node.UID] = usedNodeIP
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this map need locking at all? I guess we're guaranteed that the shared informer will call add/del in the same goroutine, so we probably don't. Right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, add/update/del events are serially processed from the shared informer queue. So no additional locking required.

Copy link
Contributor

@danwinship danwinship left a comment

Choose a reason for hiding this comment

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

also mostly lgtm

@@ -364,7 +278,7 @@ func (np *networkPolicyPlugin) selectPods(npns *npNamespace, lsel *metav1.LabelS
glog.Errorf("ValidateNetworkPolicy() failure! Invalid PodSelector: %v", err)
return ips
}
for _, pod := range npns.pods {
for _, pod := range np.pods {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're looping over all pods now you need to check pod.Namespace explicitly

Copy link
Author

Choose a reason for hiding this comment

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

yes, thx

}
nodeInformer := master.informers.InternalKubernetesInformers().Core().InternalVersion().Nodes()
nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add a helper function that takes a shared.InformerFactory, a "handleAddOrUpdateFunc" and a "handleDeleteFunc", and creates a cache.ResourceEventHandlerFuncs (doing the DeletedFinalStateUnknown handling) and calls AddEventHandler on it?

Copy link
Author

Choose a reason for hiding this comment

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

ok

@pravisankar pravisankar force-pushed the sdn-use-shared-informers branch 3 times, most recently from b927bde to 6afa0ff Compare May 11, 2017 01:36
@pravisankar
Copy link
Author

@openshift/networking Updated, PTAL

Ravi Sankar Penta added 9 commits May 11, 2017 11:45
This will help sdn watch resources to reuse the existing shared informers
instead of creating a new watch routine for the resource.
This will help sdn watch resources to reuse the existing shared informers
instead of creating a new watch routine for the resource.
- Create pod watch for all namespaces instead of pod watch for each namespace
- Use shared informers for pod watch
…EventQueue()

These resources can use shared informers if needed.
If we get a pod with out any IP set then log warning and bail out.
@pravisankar pravisankar force-pushed the sdn-use-shared-informers branch from 6afa0ff to abc81c6 Compare May 11, 2017 18:45
@openshift-bot
Copy link
Contributor

Evaluated for origin testextended up to abc81c6

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/testextended SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin_extended/375/) (Base Commit: 2628c77) (Extended Tests: networking)

@dcbw
Copy link
Contributor

dcbw commented May 15, 2017

@openshift-bot test this issue #13977

@dcbw
Copy link
Contributor

dcbw commented May 15, 2017

Latest changes LGTM too.

@dcbw
Copy link
Contributor

dcbw commented May 15, 2017

[test] issue #13977

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to abc81c6

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/1432/) (Base Commit: b38274c)

Copy link
Contributor

@knobunc knobunc left a comment

Choose a reason for hiding this comment

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

LGTM

@knobunc
Copy link
Contributor

knobunc commented May 16, 2017

[merge]

@knobunc knobunc requested a review from smarterclayton May 16, 2017 14:36
@danwinship
Copy link
Contributor

flake #14229 [merge]

@danwinship
Copy link
Contributor

flake #14197, [merge]

@smarterclayton
Copy link
Contributor

smarterclayton commented May 18, 2017 via email

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to abc81c6

@openshift-bot
Copy link
Contributor

openshift-bot commented May 18, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/687/) (Base Commit: 2ea9f5a) (Image: devenv-rhel7_6239)

@openshift-bot openshift-bot merged commit fb92178 into openshift:master May 18, 2017
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