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

Limit label selector to Ingress factory. #3137

Conversation

timoreimann
Copy link
Contributor

What does this PR do?

Limit the Kubernetes label selector to the Ingress factory.

Motivation

Fix a regression when we switched to the newer shared informer factory.

Reviewer Notes

@yue9944882 could you please take a look and let me know if this seems good to you?

I'm also open to any suggestions how we could possibly implement this more elegantly.

Thanks!

Refs #3128

@ldez
Copy link
Contributor

ldez commented Apr 5, 2018

@timoreimann could you rebase on 1.6.

@timoreimann timoreimann changed the base branch from master to v1.6 April 5, 2018 21:31
@timoreimann timoreimann force-pushed the kubernetes-limit-labelselector-to-ingress-factory branch from 2a7fbb9 to 75856d0 Compare April 5, 2018 21:32
@timoreimann
Copy link
Contributor Author

@ldez done.

@ldez ldez added this to the 1.6 milestone Apr 5, 2018
@@ -160,7 +171,7 @@ func (c *clientImpl) WatchAll(namespaces Namespaces, labelSelector string, stopC
// GetIngresses returns all Ingresses for observed namespaces in the cluster.
func (c *clientImpl) GetIngresses() []*extensionsv1beta1.Ingress {
var result []*extensionsv1beta1.Ingress
for ns, factory := range c.factories {
for ns, factory := range c.ingressFactories {
ings, err := factory.Extensions().V1beta1().Ingresses().Lister().List(labels.Everything())
Copy link
Contributor

@yue9944882 yue9944882 Apr 6, 2018

Choose a reason for hiding this comment

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

@timoreimann It looks odd to me to keep 2 factory instances at the same time in clientImpl. How do you think about setting tweakListOptions to nil for all resources including ingresses but filtering them by selector here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, that'd be much better (and pretty much what I was longing for but failed to see).

Let me update the PR...

Copy link
Contributor

@yue9944882 yue9944882 Apr 7, 2018

Choose a reason for hiding this comment

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

@timoreimann Umm I think we should also use cache.FilteringResourceEventHandler to specify a filter func to perform label selector matching for ingress resources. Or some extra ingress events will be captured by eventHandler which may trigger some unnecessary reloads. See examples here :)
https://github.com/kubernetes/kubernetes/blob/dfd6f581b5c8830c760d2778b299c3fd5e7aa242/pkg/scheduler/factory/factory.go#L186

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR.

PTAL again.

@yue9944882
Copy link
Contributor

I didn't really notice that this labelSelector should only be applied for ingress. How about renaming the parameter to ingressLabelSelector to emphasise it?

@dtomcej
Copy link
Contributor

dtomcej commented Apr 6, 2018

Code looks good, but do you think we should have a test for this? since we merged a regression without it being caught?

@timoreimann
Copy link
Contributor Author

@dtomcej

Code looks good, but do you think we should have a test for this? since we merged a regression without it being caught?

I agree with you that we should have a test (in fact, tests for most of our low-level Kubernetes integration functionality). However, I don't think that unit tests would be really valuable in this case: The code in client.go largely depends on the client-go library, which means that any tests we write would heavily depend on the fake implementation that comes with it. IMHO, it'd be the classical case of testing against a test double without really testing the production code.

What I think we need are proper integration tests for Kubernetes. I've been working on #1889 for quite a while; it's not quite done, but I hope to finish it rather soon. Personally, I'd rather invest into these when it comes to validating our integration logic.

Copy link
Contributor

@yue9944882 yue9944882 left a comment

Choose a reason for hiding this comment

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

LGTM now

@timoreimann
Copy link
Contributor Author

I manually tested the PR both with and without a configured label selector. Looks like it's working as expected.

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

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

Many thanks @timoreimann

Only 2 suggestions. 😉

func (p *Provider) newK8sClient(ingressLabelSelector string) (Client, error) {
ingLabelSel, err := labels.Parse(ingressLabelSelector)
if err != nil {
return nil, fmt.Errorf("invalid ingress label selector: %s", ingressLabelSelector)
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about using %q instead of %s ?

if err != nil {
return nil, fmt.Errorf("invalid ingress label selector: %s", ingressLabelSelector)
}
log.Infof("ingress label selector is: %s", ingLabelSel)
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about using %q instead of %s ?

Copy link
Member

@mmatur mmatur left a comment

Choose a reason for hiding this comment

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

LGTM 👏

Copy link
Contributor

@dtomcej dtomcej left a comment

Choose a reason for hiding this comment

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

LGTM
:shipit:

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

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

LGTM

timoreimann and others added 4 commits April 12, 2018 10:57
@ldez ldez force-pushed the kubernetes-limit-labelselector-to-ingress-factory branch from 1685ff9 to 2ef023c Compare April 12, 2018 08:57
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.

8 participants