-
Notifications
You must be signed in to change notification settings - Fork 52
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
service_network_manager changes for SNVA security group API support #409
service_network_manager changes for SNVA security group API support #409
Conversation
|
||
assert.Nil(t, err) | ||
assert.Equal(t, resp.ServiceNetworkARN, meshArn) | ||
assert.Equal(t, resp.ServiceNetworkID, meshId) | ||
} | ||
|
||
func Test_CreateServiceNetwork_MeshAlreadyExist_AssociateToNotAssociate(t *testing.T) { |
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.
Did the unit test name changes: from _CreateServiceNetwork_
to _CreateOrUpdateServiceNetwork_
i.e, from Test_CreateServiceNetwork_MeshAlreadyExist_AssociateToNotAssociate
to Test_CreateOrUpdateServiceNetwork_MeshAlreadyExist_AssociateToNotAssociate
c793dba
to
e0760f8
Compare
Pull Request Test Coverage Report for Build 6331816403
💛 - Coveralls |
if err != nil { | ||
return latticemodel.ServiceNetworkStatus{ServiceNetworkARN: "", ServiceNetworkID: ""}, err | ||
} | ||
if stackSn.Spec.AssociateToVPC == true && isServiceNetworkAlreadyAssociatedWithCurrentVpc == true && |
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.
maybe you can refactor this out into a separate variable to make the condition more clear?
if service_network.Spec.AssociateToVPC == true { | ||
if isServiceNetworkAssociatedWithVPC == false { | ||
if stackSn.Spec.AssociateToVPC == true { | ||
if isServiceNetworkAlreadyAssociatedWithCurrentVpc == false { |
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.
nit: you can use the short version of the condition in if statements. like if condition
or if !condition
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.
Code looks more complex than problem. Please simplify names, use normal error handling order, cleanup logs. Also it's good time to refactor create/update function into separate create and update. For refactoring please submit PR with refactoring first, and then another PR with new feature.
@@ -53,66 +57,72 @@ type defaultServiceNetworkManager struct { | |||
// return errors.New(LATTICE_RETRY) when: | |||
// | |||
// CreateServiceNetworkVpcAssociationInput returns ServiceNetworkVpcAssociationStatusFailed/ServiceNetworkVpcAssociationStatusCreateInProgress/MeshVpcAssociationStatusDeleteInProgress | |||
func (m *defaultServiceNetworkManager) Create(ctx context.Context, service_network *latticemodel.ServiceNetwork) (latticemodel.ServiceNetworkStatus, error) { | |||
func (m *defaultServiceNetworkManager) CreateOrUpdate(ctx context.Context, stackSn *latticemodel.ServiceNetwork) (latticemodel.ServiceNetworkStatus, error) { |
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.
why stackSn, not just sn?
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.
Hope to to represent a meaning that this a the desired SN that user intend to create (refering the name stackDeployer
)
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.
looks cryptic, sn or serviceNetwork was ok
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.
I found it have to differenate desiredSN and m.cloud.Lattice().FindServiceNetwork() retrieved SN, plan to change the name stackSn
to desiredSN
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.
I believe difference is apparent, Create function accept model of service network and tries to create or update lattice resources. There is no ambiguity what kind of service network it is.
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.
Changed to serviceNetwork
return latticemodel.ServiceNetworkStatus{ | ||
ServiceNetworkID: snId, | ||
ServiceNetworkARN: snArn, | ||
SnvaSecurityGroupIds: nil, | ||
}, errors.New(LATTICE_RETRY) |
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.
when return error, dont populate fields for struct
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.
Will, retrun value latticemodel.ServiceNetworkStatus{}
only used by unit test. I intend to do assertion for this return value
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.
when you do unit test for error, you dont need to do assertion on ServiceNetworkStatus struct, it has no meaning when error returned - garbage value
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.
changed to only assert err for unhappy path unit test
9704786
to
8c055ce
Compare
bbc28e5
to
13d4cd6
Compare
be3b292
to
11710aa
Compare
11710aa
to
eb92529
Compare
What type of PR is this?
Which issue does this PR fix: feature, #199 service_network_manager changes for SNVA security group API support
If an issue # is not available please add repro steps and logs from aws-gateway-controller showing the issue:
Testing done on this change:
kubectl apply -f examples/my-hotel-gateway.yaml
, create SN and SNVA successUpdate SNVA security group success
3. apply
lattice.UpdateServiceNetworkVpcAssociationWithContext() return validation error and the controller keep LATTICE_RETRY as expected
SNVA deleted as expected
SNVA is created, (as the controller by default will create SNVA, if the policy don't have
associateWithVpc
field)Automation added to e2e: Will add new E2E test cases in a separate PR
Will this PR introduce any new dependencies?: No
Will this break upgrades or downgrades. Has updating a running cluster been tested?:
Does this PR introduce any user-facing change?: add new feature, no existing behavour changes
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.