Skip to content

Commit 2ba1292

Browse files
fix panic error when scope obj is nil (#1406)
Signed-off-by: Prajyot-Parab <[email protected]> Co-authored-by: Prajyot-Parab <[email protected]>
1 parent bb31df8 commit 2ba1292

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

controllers/ibmpowervscluster_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ func (r *IBMPowerVSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re
8888
ServiceEndpoint: r.ServiceEndpoint,
8989
})
9090

91-
// Always close the scope when exiting this function so we can persist any GCPMachine changes.
91+
// Always close the scope when exiting this function so we can persist any IBMPowerVSCluster changes.
9292
defer func() {
93-
if err := clusterScope.Close(); err != nil && reterr == nil {
94-
reterr = err
93+
if clusterScope != nil {
94+
if err := clusterScope.Close(); err != nil && reterr == nil {
95+
reterr = err
96+
}
9597
}
9698
}()
9799

controllers/ibmpowervsimage_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
7979
if err != nil {
8080
return ctrl.Result{}, errors.Errorf("failed to create scope: %+v", err)
8181
}
82-
// Always close the scope when exiting this function so we can persist any IBM PowerVS Image changes.
82+
83+
// Always close the scope when exiting this function so we can persist any IBMPowerVSImage changes.
8384
defer func() {
84-
if err := imageScope.Close(); err != nil && reterr == nil {
85-
reterr = err
85+
if imageScope != nil {
86+
if err := imageScope.Close(); err != nil && reterr == nil {
87+
reterr = err
88+
}
8689
}
8790
}()
8891

controllers/ibmpowervsmachine_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ func (r *IBMPowerVSMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
137137
if err != nil {
138138
return ctrl.Result{}, errors.Errorf("failed to create scope: %v", err)
139139
}
140-
// Always close the scope when exiting this function so we can persist any GCPMachine changes.
141140

141+
// Always close the scope when exiting this function so we can persist any IBMPowerVSMachine changes.
142142
defer func() {
143-
if err := machineScope.Close(); err != nil && reterr == nil {
144-
reterr = err
143+
if machineScope != nil {
144+
if err := machineScope.Close(); err != nil && reterr == nil {
145+
reterr = err
146+
}
145147
}
146148
}()
147149

controllers/ibmvpccluster_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ func (r *IBMVPCClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques
8989
ServiceEndpoint: r.ServiceEndpoint,
9090
})
9191

92-
// Always close the scope when exiting this function so we can persist any GCPMachine changes.
92+
// Always close the scope when exiting this function so we can persist any IBMVPCCluster changes.
9393
defer func() {
94-
if err := clusterScope.Close(); err != nil && reterr == nil {
95-
reterr = err
94+
if clusterScope != nil {
95+
if err := clusterScope.Close(); err != nil && reterr == nil {
96+
reterr = err
97+
}
9698
}
9799
}()
98100

controllers/ibmvpcmachine_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ func (r *IBMVPCMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques
114114
if err != nil {
115115
return ctrl.Result{}, errors.Errorf("failed to create scope: %+v", err)
116116
}
117-
// Always close the scope when exiting this function, so we can persist any IBMVPCMachine changes.
118117

118+
// Always close the scope when exiting this function, so we can persist any IBMVPCMachine changes.
119119
defer func() {
120-
if err := machineScope.Close(); err != nil && reterr == nil {
121-
reterr = err
120+
if machineScope != nil {
121+
if err := machineScope.Close(); err != nil && reterr == nil {
122+
reterr = err
123+
}
122124
}
123125
}()
124126

0 commit comments

Comments
 (0)