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

Refactor enirouting package to reduce code interdependence and add test coverage #11208

Merged

Conversation

christarazi
Copy link
Member

@christarazi christarazi commented Apr 28, 2020

See commit messages.

Follow-up refactor from previous PR: #11073

@christarazi christarazi added kind/cleanup This includes no functional changes. area/cni Impacts the Container Networking Interface between Cilium and the orchestrator. area/health Relates to the cilium-health component area/eni Impacts ENI based IPAM. release-note/misc This PR makes changes that have no direct user impact. backport/1.7 labels Apr 28, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.8.0 Apr 28, 2020
@christarazi
Copy link
Member Author

christarazi commented Apr 28, 2020

test-me-please

Edit: build went green, just retriggering because I needed to rebase

@coveralls
Copy link

coveralls commented Apr 28, 2020

Coverage Status

Coverage increased (+0.03%) to 44.463% when pulling fe777ed47acd9badcdb010e026ec4b6da3b206ec on christarazi:pr/christarazi/refactor-enirouting-pkg into 3ec3d25 on cilium:master.

// NewRoutingInfo creates a new RoutingInfo struct from a source which adheres
// to the getter interface. The data from the source is then parsed and
// validated.
func NewRoutingInfo(getter getter) (*RoutingInfo, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@joestringer I've tried out your suggestion from: #11073 (comment)

After implementing it, I'm not sure what benefits we get from abstracting away the source of the info via the getter interface. I think we'd get the same functionality and non-code-interdependence from just having the NewRoutingInfo take the raw values as parameters.

Is there something I'm missing that the interface would buy us?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for trying it out, good question :)

Looking closer, in this case the ability to fetch the routing info, ie the implementation of getter is trivial; it's just taking the API response structure and returning the values inside. So in this current implementation I'm inclined to agree that the benefit is not obvious. Right now, it allows pkg/aws/eni/routing to avoid importing the API structures, but I don't think that's a big deal; we're already assuming a model around the cloud IPAM API responses in all of the ENI code structure anyway so the abstraction doesn't help.

If the full implementation of that getter was more complex (For example actually involved pulling values from an API) then I think it would make a bigger difference.

Looks like we got more value out of the routingConfigurer above, which allowed us to remove ENI references from that package (module the variable names, which should probably be simplified).

Copy link
Member

Choose a reason for hiding this comment

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

Oh, perhaps the unsaid piece above: With this style of implementation, you can create your own dummy getter and actually unit-test the parse() function below trivially. In this specific case, if we remove it, then you just have to instantiate IPAM API response structures in the tests which is probably still straightforward.

If the getter was more complex then just to unit test this functionality it would be more work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right. The retrieval of these ENI routing values is trivial and will probably continue to be, since it's inherently a cloud API interaction. So our getter isn't helping by providing any useful abstraction.

I'm going to take out the getter and replace the constructor with raw string values as input instead. This will still allow us to unit-test parse easily since it will just take those values as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

(module the variable names, which should probably be simplified).

Which variable names need to be simplified?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I mean eniHealthRouting -> routeConfiguration. This assumes an eni implementation but it doesn't make sense to assume that when a generic routeConfigurer is handed down.

@christarazi christarazi changed the title Refactor enirouting package to utilize interfaces to abstract away source of routing info Refactor enirouting package to utilize interfaces to reduce code interdependence Apr 29, 2020
@christarazi christarazi changed the title Refactor enirouting package to utilize interfaces to reduce code interdependence Refactor enirouting package to reduce code interdependence Apr 29, 2020
@christarazi christarazi force-pushed the pr/christarazi/refactor-enirouting-pkg branch from 32bd730 to 7f84987 Compare April 29, 2020 01:08
@christarazi
Copy link
Member Author

test-me-please

@christarazi christarazi force-pushed the pr/christarazi/refactor-enirouting-pkg branch from 7f84987 to 0ba3950 Compare April 29, 2020 19:33
@christarazi
Copy link
Member Author

test-me-please

@joestringer joestringer added this to Needs backport from master in 1.7.4 Apr 29, 2020
@joestringer
Copy link
Member

What's the intent behind marking this for backport? Usually we have slightly stricter backport criteria for existing releases:
https://docs.cilium.io/en/v1.7/contributing/release/backports/#backport-criteria-for-current-minor-release

We may make exceptions in cases where we for example increase testing coverage, or where we expect that operating Cilium or debugging Cilium may become easier because the codepaths are more similar between versions. Just want to make sure that we've thought through why we're backporting this refactoring change.

Also is this close? Seems like the CI is passing at least, but it's currently marked as Draft.

@christarazi
Copy link
Member Author

christarazi commented May 5, 2020

The intent is to ensure the code doesn't diverge too much from master. Also, I am working on adding tests as part of this PR. I should've clarified that in the description.

Yes it is close, I'm wrapping up the tests and should have this PR done by end-of-day.

@christarazi christarazi changed the title Refactor enirouting package to reduce code interdependence Refactor enirouting package to reduce code interdependence and add test coverage May 5, 2020
@christarazi christarazi force-pushed the pr/christarazi/refactor-enirouting-pkg branch from 0ba3950 to a29480c Compare May 6, 2020 01:06
@christarazi
Copy link
Member Author

test-me-please

@christarazi
Copy link
Member Author

christarazi commented May 6, 2020

While adding test coverage, I realized that we needed to return an error if deleting a rule fails. The error is non-fatal as the deletion code is made at the endpoint-level, meaning that the scaffolding around this will aggregate all errors that occur and show a log message. The reason for adding this now is because previously, the log messages could have been misleading if an error occurs. Also, it was difficult to assert the correct behavior in all cases. See commit 7eb1c8c.

@christarazi christarazi force-pushed the pr/christarazi/refactor-enirouting-pkg branch from a29480c to fe777ed Compare May 6, 2020 01:14
@christarazi
Copy link
Member Author

test-me-please

@christarazi christarazi marked this pull request as ready for review May 6, 2020 02:05
@christarazi christarazi requested review from a team May 6, 2020 02:05
Previously, we relied on a log message to indicate whether a deletion of
a rule failed. Relying on the log message can be potentially misleading
as endpoint deletion is best-effort and errors are ignored in the end.
The user may see log message indicating a rule was deleted, but later in
the endpoint deletion it would show as an error.

This commit changes the function which deletes rules to surface the
error. This change removes the misleading log messages and allows us to
assert against this in tests.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
This commit structures the code in such a way that allows the previously
duplicated parsing/validation logic to be consolidated into one place. It also
reduces the interdependencies between packages and allows for a dummy
implementation to be used for testing purposes.

Signed-off-by: Chris Tarazi <chris@isovalent.com>
Signed-off-by: Chris Tarazi <chris@isovalent.com>
@christarazi christarazi force-pushed the pr/christarazi/refactor-enirouting-pkg branch from fe777ed to b93f4d0 Compare May 6, 2020 18:40
@christarazi
Copy link
Member Author

christarazi commented May 6, 2020

Build went green. Pushed to rebase

Edit: travis went red on this push, with this flake #11373

@christarazi
Copy link
Member Author

test-me-please

@joestringer
Copy link
Member

Hit #11373 .

@christarazi christarazi added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label May 7, 2020
@joestringer joestringer merged commit a83d538 into cilium:master May 7, 2020
1.8.0 automation moved this from In progress to Merged May 7, 2020
@christarazi christarazi deleted the pr/christarazi/refactor-enirouting-pkg branch May 7, 2020 01:29
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.7 in 1.7.4 May 8, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.7 to Backport done to v1.7 in 1.7.4 May 13, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.7 to Backport done to v1.7 in 1.7.4 May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cni Impacts the Container Networking Interface between Cilium and the orchestrator. area/eni Impacts ENI based IPAM. area/health Relates to the cilium-health component kind/cleanup This includes no functional changes. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
No open projects
1.7.4
Backport done to v1.7
1.8.0
  
Merged
Development

Successfully merging this pull request may close these issues.

None yet

4 participants