Skip to content

Commit 63122f1

Browse files
authored
Fix a nil pointer issue in restore (vmware-tanzu#1106)
This patch will avoid invoking function EnableRestoreMode in T1 to fix the following nil poiner issue: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0xb0 pc=0x1fba5ba] goroutine 46 [running]: github.com/vmware-tanzu/nsx-operator/pkg/controllers/subnetset.(*SubnetSetReconciler).EnableRestoreMode(...) /source/pkg/controllers/subnetset/subnetset_controller.go:313 main.startServiceController({0x2af6de8, 0xc00049a680}, 0xc000157188) /source/cmd/main.go:238 +0x127a main.electMaster({0x2af6de8, 0xc00049a680}, 0xc000157188) /source/cmd/main.go:279 +0xf9 created by main.main in goroutine 1 /source/cmd/main.go:305 +0x2df ``` Testing done: Step 1. prepare a ncpconfig CR without annotation operator_restore_end_time in T1 env. Step 2. start the NSX operator and check the operator_restore_end_time won't be annotated and the NSX operator doesn't enter the restore mode.
1 parent 4552db2 commit 63122f1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cmd/main.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,15 @@ func startServiceController(mgr manager.Manager, nsxClient *nsx.Client) {
126126

127127
checkLicense(nsxClient, cf.LicenseValidationInterval)
128128

129-
var err error
130-
restoreMode, err = pkgutil.CompareNSXRestore(mgr.GetClient(), nsxClient)
131-
if err != nil {
132-
log.Error(err, "NSX restore check failed")
133-
os.Exit(1)
129+
if cf.K8sConfig.EnableRestore && cf.CoeConfig.EnableVPCNetwork {
130+
var err error
131+
restoreMode, err = pkgutil.CompareNSXRestore(mgr.GetClient(), nsxClient)
132+
if err != nil {
133+
log.Error(err, "NSX restore check failed")
134+
os.Exit(1)
135+
}
136+
} else {
137+
restoreMode = false
134138
}
135139

136140
var reconcilerList []pkgutil.ReconcilerProvider
@@ -256,7 +260,7 @@ func startServiceController(mgr manager.Manager, nsxClient *nsx.Client) {
256260
}
257261

258262
// Update pod labels to determine if this pod is the master
259-
err = updatePodLabels(mgr)
263+
err := updatePodLabels(mgr)
260264
if err != nil {
261265
log.Error(err, "Failed to update Pod labels")
262266
panic(err)

0 commit comments

Comments
 (0)