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

Fix Subnet update error detection #991

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yanjunz97
Copy link
Contributor

@yanjunz97 yanjunz97 commented Jan 6, 2025

Operator modifies the existing Subnet in store before updating the NSX Subnet,
which results in the next reconcile will find the updated Subnet already in store,
skip the update, and overwrite the Status as Ready.
This PR uses a copy when updating the Subnet to avoid this issue.

@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 84.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 74.19%. Comparing base (e06b12f) to head (61f5514).

Files with missing lines Patch % Lines
pkg/nsx/services/subnet/subnet.go 77.77% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #991      +/-   ##
==========================================
+ Coverage   74.10%   74.19%   +0.09%     
==========================================
  Files         118      118              
  Lines       16371    16373       +2     
==========================================
+ Hits        12131    12148      +17     
+ Misses       3466     3454      -12     
+ Partials      774      771       -3     
Flag Coverage Δ
unit-tests 74.19% <84.00%> (+0.09%) ⬆️
Files with missing lines Coverage Δ
pkg/nsx/services/subnet/builder.go 88.60% <100.00%> (+1.10%) ⬆️
pkg/nsx/services/subnet/subnet.go 69.25% <77.77%> (+3.95%) ⬆️

}
}
if !changed {
log.Info("Subnet not changed, skip updating", "SubnetId", uid)
return existingSubnet, nil
}
}
return service.createOrUpdateSubnet(obj, nsxSubnet, &vpcInfo)
return service.createOrUpdateSubnet(obj, nsxSubnet, &vpcInfo, isUpdate)
Copy link
Contributor

Choose a reason for hiding this comment

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

it is a little confusing to have both changed and isUpdate, maybe just use changed & !existingSubnet to pass to the parameter in createOrUpdateSubnet

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, thanks!

pkg/nsx/services/subnet/subnet.go Show resolved Hide resolved
@@ -398,7 +398,7 @@ func TestSubnetService_UpdateSubnetSet(t *testing.T) {
})

patchesCreateOrUpdateSubnet := gomonkey.ApplyFunc((*SubnetService).createOrUpdateSubnet,
func(r *SubnetService, obj client.Object, nsxSubnet *model.VpcSubnet, vpcInfo *common.VPCResourceInfo) (*model.VpcSubnet, error) {
func(r *SubnetService, obj client.Object, nsxSubnet *model.VpcSubnet, vpcInfo *common.VPCResourceInfo, isUpdate bool) (*model.VpcSubnet, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we need a new UT for createOrUpdateSubnet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, some part of the code in createOrUpdateSubnet is not covered yet. Added the unit test, thanks

// For update case, wait for some time to make sure the realized state is updated.
if isUpdate {
time.Sleep(1 * time.Second)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

it's better that NSX fix that issue. After NSX patch API called, the realized status should be updated in sync mode instead

Copy link
Contributor Author

@yanjunz97 yanjunz97 Jan 7, 2025

Choose a reason for hiding this comment

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

Opened a bug for NSX team, let's see how they reply on this observations, thanks

@yanjunz97 yanjunz97 force-pushed the fix-subnet-update branch 4 times, most recently from ecf2948 to eca3d76 Compare January 13, 2025 03:35
dantingl
dantingl previously approved these changes Jan 15, 2025
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.

5 participants