Fix IsDefaultNSXProject always returning false after SDK field rename#1389
Merged
timdengyun merged 1 commit intovmware-tanzu:mainfrom Mar 16, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1389 +/- ##
=======================================
Coverage 76.74% 76.75%
=======================================
Files 151 151
Lines 21307 21308 +1
=======================================
+ Hits 16353 16354 +1
Misses 3784 3784
Partials 1170 1170
🚀 New features to boost your workflow:
|
Contributor
Author
|
/e2e |
0bd4558 to
328ade0
Compare
Contributor
Author
|
/e2e |
328ade0 to
c7f4b82
Compare
Use Cluster.HttpGet to read the "default" field directly from the NSX REST API JSON response, bypassing the SDK struct deserialization which cannot populate the unexported model.Project._Default field. Co-Authored-By: Oz <oz-agent@warp.dev> Change-Id: I79cfd117c95abe17ef7032525e69cd1695e8822e
c7f4b82 to
fe8bb50
Compare
timdengyun
approved these changes
Mar 13, 2026
Contributor
|
/e2e |
TaoZou1
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ What's Changed
IsDefaultNSXProject
Cluster.HttpGet"default"field from NSX Policy API JSON response (/policy/api/v1/orgs/{orgID}/projects/{projectID})model.Project._Defaultfield that the VAPI type converter cannot populategetProjectDefault()helper andreflect/unsafeimportsTest Updates
Cluster.HttpGet:"default": true) → returnstrue"default": false) → returnsfalsedefaultfield → returnsfalse🎯 Motivation
SDK commit
7bd53190renamedmodel.Project.Default(exported) tomodel.Project._Default(unexported). The VAPI type converter usesreflectto populate struct fields, but Go reflect cannot write unexported fields (CanSet()returnsfalse) — so_Defaultis never deserialized and always nil.Issue:
IsDefaultNSXProject()always returnsfalsefor all projects including the NSX default project. This causes NetworkPolicy withnamespaceSelectorunder the default project to build incorrect share group paths (/orgs/default/projects/default/infra/...instead of/infra/...), resulting in NSX error 524297: "Invalid infra operation on default project."Solution: Use
Cluster.HttpGetto query the NSX Policy API directly and read the"default"boolean from the raw JSON response, bypassing the broken SDK struct deserialization entirely.✅ Testing
Unit Tests
TestIsDefaultNSXProjectcovers: default project, non-default project, missing field, HTTP errorIntegration Test
✅ Test Case 1: Non-Default Project (project-quality)
Purpose: Validate fix using the exact NetworkPolicy spec from the bug report under a non-default project. Shares should go to project-level path.
Configuration (same spec as bug report, namespace adapted for testbed):
Before fix (from bug report, rule_hash
1ba78f27):After fix (same spec, same rule_hash
1ba78f27): ✅ SUCCESS✅ Test Case 2: Default Project (project ID "default")
Purpose: Validate that shares go to
/infra/level when VPC is under the NSX default project. This is the exact scenario from the bug report.Setup: Created VPC under the default project (
/orgs/default/projects/default/vpcs/test-default-project_sfh7c) with a new VPCNetworkConfiguration pointing tonsxProject: /orgs/default/projects/default.Configuration:
Result: ✅ SUCCESS — Both ALLOW and ISOLATION SecurityPolicies created. Shares correctly placed at
/infra/level:Explanation:
IsDefaultNSXProject("default", "default")correctly returnstrue, routing shares to the global/infra/hierarchy instead of the invalid project-level path.NSX Project Verification
Confirmed via NSX API that the default project has
"default": trueand"_system_owned": true:SDK Root Cause Verification
Added diagnostic logging to
DataValueToNativeConverter.setStructType()and confirmed:This proves the VAPI type converter silently skips the unexported
_Defaultfield.🔄 Backward Compatibility
This change is fully backward compatible:
IsDefaultNSXProject()still returnsfalse(same behavior as before, verified withproject-quality)true(corrected from brokenfalse, verified with shares at/infra/level)(orgID, projectID)and returns(bool, error)Cluster.HttpGetwhich leverages existing NSX client connection pooling and authentication