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

Spike: disentangle the store, controllers, and annotations code for class matching #853

Closed
rainest opened this issue Sep 15, 2020 · 5 comments

Comments

@rainest
Copy link
Contributor

rainest commented Sep 15, 2020

Summary

The existing implementation for filtering resources with the correct ingress class annotation or native class has poor separation between the store and annotations code. Store loads in a lot of annotations code that it ideally shouldn't. We should explore options for making the separation cleaner, which should allow for easier changes to this implementation in the future.

Background

#843 works, but is a mess. Key pain points/oddness items for me were:

  • The verification functions are generated and exist as part of the store instance. Side effects here are sending a lot of arguments into store.New() to toggle class behavior per-object.
  • Generated function constructors only get the ingress class and aren't otherwise distinguished, as matching behavior is now mostly per-object: we pass it into the generated function along with the object details. This would be useful if we had controllers that did use multiple stores to support different classes simultaneously, but I don't think experience has shown we need that much. We do have demonstrated need for finer-grained namespace permissions within a single controller (e.g. Kong enterprise multiple ingress controllers deployment for multiple workspace support helm/charts#19091), and creating multiple stores would allow us a means around the standard K8S client "you can get resources from one namespace or ALL NAMESPACES" limitation, but in that case we'd probably use the same class throughout while creating different stores for each namespace--essentially, we'd implement support for passing multiple --watch-namespace flags to a single controller instance.
  • When testing fake_store, we must choose a specific ingress class (that's maybe fine), but have to pull that default out of annotations, which seems wrong.
  • Matching logic currently lives in annotations; it is invoked from the generated functions attached to the store instance. That's somewhat odd now that the matching is no longer entirely about annotations (Ingress V1 has that functionality bundled into the Ingress object alongside legacy annotation support, but trying to place that logic outside annotations code would require exporting or moving validIngress), and was always more related to a single specific annotation (ingress.class) than annotations in general.
  • We currently have functions for retrieving class info from object meta (annotations) and objects themselves (currently only v1 Ingresses, but maybe other stuff in the future). We also have a function that claims to handle that generically, but in practice I think it's more old code at this point, that we (probably I) forgot to rip it out after adding the object meta variant, and is now only used in tests that don't test actual in-use code.
@rainest rainest added the trello label Sep 15, 2020
@rainest
Copy link
Contributor Author

rainest commented Sep 15, 2020

Some initial comments from @mflendrich pulled out of Slack convo:

One possible way to solve this would be to make an ingress-class-aware view over store.Storer. Possibly even implementing the same interface.

@mflendrich mflendrich removed the trello label Oct 30, 2020
@stale stale bot added the stale Will be closed unless advocated for within 7 days label Mar 20, 2021
@stale stale bot closed this as completed Mar 27, 2021
@mflendrich mflendrich reopened this Mar 29, 2021
@stale stale bot removed the stale Will be closed unless advocated for within 7 days label Mar 29, 2021
@Kong Kong deleted a comment from stale bot Mar 25, 2022
@shaneutt
Copy link
Contributor

@Kong/team-k8s we recently did a code pairing that was relevant to this one, just wanted to check in on this one do we have existing code or is anyone actively working on this?

@rainest rainest changed the title Spike: disentangle the store and annotations code for class matching Spike: disentangle the store, controllers, and annotations code for class matching Mar 25, 2022
@rainest
Copy link
Contributor Author

rainest commented Mar 25, 2022

The pairing ended up addressing a different issue (testing something related). Not started yet, but I think we should keep this around because of how annoying it is.

The OP is now somewhat out of date, and doesn't cover that there's now an additional filter in the controllers, which duplicate the store's filter functionality and has its own set of helper functions, so the original in-store implementation should be possible to discard entirely.

There's hopefully a simple solution (discard filtering in the store altogether, write/review integration tests that confirm that we don't ingest wrong-class resources) so it could be a good onboarding project to gain some familiarity with the store and its relationship to the controllers. May need more in-depth assistance if it turns out being more difficult (the tests fail after removing the store filters).

@shaneutt
Copy link
Contributor

reviewing this it sounds like we need to spike this to figure out what actually should be done to solve the problem, and how long that solution will take.

@mflendrich
Copy link
Contributor

Closed because it's huge. Likely other, more narrowly targeted, efforts to improve the parser/translate code will likely partially resolve this. Let's reopen if there's a good, promising way to fix this.

@mflendrich mflendrich closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants