@@ -78,6 +78,8 @@ var log = logf.Log.WithName("controller_goalertintegration")
7878//
7979// For more details, check Reconcile and its Result here:
8080// - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile 81+
82+ //nolint:gocyclo // This is a marker that we should think about a refactor here.
8183func (r * GoalertIntegrationReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
8284 start := time .Now ()
8385
@@ -142,6 +144,11 @@ func (r *GoalertIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.R
142144 if err != nil {
143145 r .reqLogger .Error (err , "Failed to auth to Goalert" )
144146 }
147+ defer func () {
148+ if err := authenticateGoalert .Body .Close (); err != nil {
149+ r .reqLogger .Error (err , "Error closing http.Response Body" )
150+ }
151+ }()
145152
146153 // Read session cookie from authentication response headers
147154 sessionCookie , err := r .fetchSessionCookie (authenticateGoalert )
@@ -163,7 +170,7 @@ func (r *GoalertIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.R
163170 }
164171 }
165172
166- //If the GI is being deleted, clean up all ClusterDeployments with matching finalizers
173+ // If the GI is being deleted, clean up all ClusterDeployments with matching finalizers
167174 if gi .DeletionTimestamp != nil {
168175 if controllerutil .ContainsFinalizer (gi , goalertFinalizer ) {
169176 for i := range matchingClusterDeployments .Items {
@@ -185,7 +192,7 @@ func (r *GoalertIntegrationReconciler) Reconcile(ctx context.Context, req ctrl.R
185192 return r .doNotRequeue ()
186193 }
187194
188- //Make sure there's a finalizer on the GoalertIntegration
195+ // Make sure there's a finalizer on the GoalertIntegration
189196 if ! controllerutil .ContainsFinalizer (gi , goalertFinalizer ) {
190197 if ! controllerutil .AddFinalizer (gi , goalertFinalizer ) {
191198 if err := r .Update (ctx , gi ); err != nil {
@@ -266,8 +273,12 @@ func (r *GoalertIntegrationReconciler) authGoalert(ctx context.Context, username
266273 if err != nil {
267274 r .reqLogger .Error (err , "Error sending HTTP request" )
268275 }
276+ defer func () {
277+ if err := authResp .Body .Close (); err != nil {
278+ r .reqLogger .Error (err , "Error closing http.Response Body" )
279+ }
280+ }()
269281
270- defer authResp .Body .Close ()
271282 return authResp .Request .Response , nil
272283}
273284
0 commit comments