Skip to content

Commit 468f567

Browse files
heypnuscursoragent
andcommitted
Implement Mixed Mode State Detection
This patch introduces the Mixed Mode state detection logic for NSX Operator to determine the network scope (T1, VPC, or VDS) it operates within. This is critical for deciding which controllers should be activated. Key features: - Introduced an informer for the NetworkSettings CR in the Controller Runtime cache to efficiently determine the global network state. - Added detection logic for VDS alongside T1 and VPC based on the NetworkSettings `provider` field. - Implemented capability checking by reading the `supports_per_namespace_network_provider` key from the `status.supervisor` path in the Capabilities CR. - Incorporated the `EnableVPCNetwork` configuration override to act as an early trigger. This solves the "chicken-and-egg" problem by allowing VPC-specific controllers to start before the NetworkSettings CRs are updated to `provider: vpc`. - Wrapped all corresponding controller capability gates to strictly use the global `config.HasVPCNamespaces()` and `config.HasT1Namespaces()` checks. After this change, the NSX-Operator will start VPC controllers as long as enable_vpc_network is true. And the T1 controllers will be started when: (supports_per_namespace_network_provider is activated) AND (at least one NetworkingSettings CR has provider=="nsx-tier1") OR (supports_per_namespace_network_provider is deactivated) AND (enable_vpc_network is false) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 128342c commit 468f567

13 files changed

Lines changed: 880 additions & 73 deletions

File tree

cmd/main.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func init() {
115115

116116
func startServiceController(mgr manager.Manager, nsxClient *nsx.Client) {
117117
// Generate webhook certificates and start refreshing webhook certificates periodically
118-
if cf.CoeConfig.EnableVPCNetwork {
118+
if config.HasVPCNamespaces() {
119119
if err := pkgutil.GenerateWebhookCerts(); err != nil {
120120
log.Error(err, "Failed to generate webhook certificates")
121121
os.Exit(1)
@@ -125,7 +125,7 @@ func startServiceController(mgr manager.Manager, nsxClient *nsx.Client) {
125125
}
126126

127127
// Initialize and start the system health reporter
128-
if cf.CoeConfig.EnableVPCNetwork && cf.EnableInventory && cf.CoeConfig.EnableSha {
128+
if config.HasVPCNamespaces() && cf.EnableInventory && cf.CoeConfig.EnableSha {
129129
health.Start(nsxClient, cf, mgr.GetClient())
130130
}
131131

@@ -138,7 +138,7 @@ func startServiceController(mgr manager.Manager, nsxClient *nsx.Client) {
138138

139139
checkLicense(nsxClient, cf.LicenseValidationInterval)
140140

141-
if cf.K8sConfig.EnableRestore && cf.CoeConfig.EnableVPCNetwork {
141+
if cf.K8sConfig.EnableRestore && config.HasVPCNamespaces() {
142142
var err error
143143
restoreMode, err = pkgutil.CompareNSXRestore(mgr.GetClient(), nsxClient)
144144
if err != nil {
@@ -155,7 +155,7 @@ func startServiceController(mgr manager.Manager, nsxClient *nsx.Client) {
155155
var hookServer webhook.Server
156156
var subnetSetReconcile *subnetset.SubnetSetReconciler
157157

158-
if cf.CoeConfig.EnableVPCNetwork {
158+
if config.HasVPCNamespaces() {
159159
// Check NSX version for VPC networking mode
160160
if !commonService.NSXClient.NSXCheckVersion(nsx.VPC) {
161161
log.Error(nil, "VPC mode cannot be enabled if NSX version is lower than 4.1.1")
@@ -300,6 +300,20 @@ func startServiceController(mgr manager.Manager, nsxClient *nsx.Client) {
300300
log.Error(err, "Failed to update Pod labels")
301301
panic(err)
302302
}
303+
304+
// Watch for mixed-mode state changes (e.g. T1-only → T1+VPC when the migration starts).
305+
// If the state changes, exit so the operator restarts with the new configuration
306+
config.StartNetworkSettingsInformer(mgr)
307+
go func() {
308+
ticker := time.NewTicker(30 * time.Second)
309+
defer ticker.Stop()
310+
for range ticker.C {
311+
if config.RefreshMixedModeState(context.Background()) {
312+
log.Info("Mixed-mode state changed; restarting NSX Operator to pick up new configuration")
313+
os.Exit(0)
314+
}
315+
}
316+
}()
303317
}
304318

305319
func electMaster(mgr manager.Manager, nsxClient *nsx.Client) {
@@ -345,6 +359,12 @@ func main() {
345359
os.Exit(1)
346360
}
347361

362+
if err := config.InitMixedMode(context.Background(), cfg, cf.CoeConfig.EnableVPCNetwork); err != nil {
363+
log.Error(err, "Failed to initialize mixed mode state")
364+
os.Exit(1)
365+
}
366+
util.SetHasVPCNamespacesFunc(config.HasVPCNamespaces)
367+
348368
if cf.HAEnabled() {
349369
go electMaster(mgr, nsxClient)
350370
} else {

0 commit comments

Comments
 (0)