-
Notifications
You must be signed in to change notification settings - Fork 45
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
OSD-26330: Refactor and add tests for egress_lists
package
#284
OSD-26330: Refactor and add tests for egress_lists
package
#284
Conversation
@@ -1,21 +1,14 @@ | |||
package egress_lists | |||
|
|||
// TRANSITIONAL IMPLEMENTATION (UNSTABLE API) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ticket was closed a while ago, this comment is no longer valid.
// Generate both egress lists for the given PlatformType. Note: the result of this is ignored by the Legacy probe. | ||
generatorVariables := map[string]string{"AWS_REGION": a.AwsClient.Region} | ||
generator := egress_lists.NewGenerator(vei.PlatformType, generatorVariables, a.Logger) | ||
|
||
egressListStr, tlsDisabledEgressListStr, err = egress_lists.EgressListToString(egressListYaml, map[string]string{"AWS_REGION": a.AwsClient.Region}) | ||
egressListStr, tlsDisabledEgressListStr, err := generator.GenerateEgressLists(vei.Ctx, vei.EgressListYaml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extraction of the fetching logic into egress_lists
essentially allows us to have this common call flow across AWS + GCP, and reads more cleanly in the scope of this already large function.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #284 +/- ##
==========================================
+ Coverage 25.81% 26.39% +0.58%
==========================================
Files 26 26
Lines 1844 1970 +126
==========================================
+ Hits 476 520 +44
- Misses 1340 1419 +79
- Partials 28 31 +3
|
@joshbranham: This pull request references OSD-26330 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
egress_lists
package
4d64a5b
to
0fec20c
Compare
path := "/pkg/data/egress_lists/" | ||
if !platformType.IsValid() { | ||
fmt.Printf("Platform type %s is invalid", platformType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described in the PR body, I removed this check, which was only printing the invalid platform and then continuing execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to change this to short circuit the execution at this point if the platform type is invalid? Worth noting there may be earlier checks before it gets this far that would short circuit already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We provide the valid platform types as global variables, and the method ByName(name string) (string, error)
, so it feels unnecessary to also then later validate a Platform
is valid since callers should be utilizing the variables or ByName...
to construct the type. This is further evident by the names
field of the struct being private so it wouldn't be possible to construct an invalid one anyways afaict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it wouldn't be possible to construct an invalid one anyways afaict
There are several points in the codebase where we return an empty (and therefore invalid) Platform{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it wouldn't be possible to construct an invalid one anyways afaict
There are several points in the codebase where we return an empty (and therefore invalid)
Platform{}
Based on my searching, this is only happening under error cases inside other functions and in tests. If an upstream caller is not handling that error, and then using the Platform{}
then that is a bug that should be fixed. Was there another example you had of this (outside of tests and errors)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, there are currently no other cases currently where Platform{}
is used in network-verifier directly but it is possible to return an invalid type (with error) through platform.ByName()
or platform.IsValid()
. As long as upstream callers handle that error I'm fine conceding the point and don't think the check is necessary here. As far as I can tell the ValidateEgress
func handles that beforehand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, there are currently no other cases currently where
Platform{}
is used in network-verifier directly but it is possible to return an invalid type (with error) throughplatform.ByName()
orplatform.IsValid()
. As long as upstream callers handle that error I'm fine conceding the point and don't think the check is necessary here. As far as I can tell theValidateEgress
func handles that beforehand.
Totally, and yup we handle the error validation already here in ValidateEgress
(for AWS as an example)
0fec20c
to
47250ab
Compare
Successfully tested locally. Good stuff @joshbranham /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: abyrne55 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
@joshbranham: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What does this PR do? / Related Issues / Jira
When working on a bugfix in #282, I wanted to consolidate duplicate code and clean up the control flow further for generating egress lists. This PR does just that, by first extracting the existing behavior into a common type, and adding tests for the various scenarios. A couple of notes:
PlatformType
as was setup before, since the caller should be using the various exportedvars
forPlatformType
and not manually constructing there own alias type with customname
values.egress_lists
to function receivers on theGenerator
struct. These functions are not used anywhere in theopenshift
organization outside of this project.See below for output of running for both AWS and GCP:
AWS
GCP
Note: The GCP failure is expected as the egress list is still being validated
Checklist
Reviewer's Checklist
How to test this PR locally / Special Instructions
You can perform a basic test locally by running the verifier and passing a custom list via the CLI
Logs