Skip to content

Commit 9cc8fbd

Browse files
authored
Merge pull request #164 from tmilos77/fix-logging-errors
fix: ctx must be supplied to LogErrorAndReturn()
2 parents 6f9084d + 72191af commit 9cc8fbd

33 files changed

+41
-37
lines changed

pkg/common/actions/removeFinalizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func RemoveFinalizer(ctx context.Context, state composed.State) (error, context.
2323
//Remove finalizer
2424
controllerutil.RemoveFinalizer(state.Obj(), cloudresourcesv1beta1.FinalizerName)
2525
if err := state.UpdateObj(ctx); err != nil {
26-
return composed.LogErrorAndReturn(err, "Error removing Finalizer", composed.StopWithRequeue, nil)
26+
return composed.LogErrorAndReturn(err, "Error removing Finalizer", composed.StopWithRequeue, ctx)
2727
}
2828

2929
//stop reconciling loop.

pkg/composed/logger.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package composed
22

33
import (
44
"context"
5+
"errors"
56
"github.com/go-logr/logr"
67
"sigs.k8s.io/controller-runtime/pkg/log"
78
)
@@ -18,6 +19,9 @@ func LoggerIntoCtx(ctx context.Context, logger logr.Logger) context.Context {
1819

1920
func LogErrorAndReturn(err error, msg string, result error, ctx context.Context) (error, context.Context) {
2021
logger := LoggerFromCtx(ctx)
22+
if ctx == nil {
23+
logger.Error(errors.New("the ctx is not supplied to LogErrorAndReturn"), "Logical error")
24+
}
2125
logger.Error(err, msg)
2226
return result, ctx
2327
}

pkg/kcp/nfsinstance/loadIpRange.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func loadIpRange(ctx context.Context, st composed.State) (error, context.Context
2525
}, ipRange)
2626

2727
if client.IgnoreNotFound(err) != nil {
28-
return composed.LogErrorAndReturn(err, "Error loading referred IpRange", composed.StopWithRequeue, nil)
28+
return composed.LogErrorAndReturn(err, "Error loading referred IpRange", composed.StopWithRequeue, ctx)
2929
}
3030

3131
if apierrors.IsNotFound(err) {
@@ -41,7 +41,7 @@ func loadIpRange(ctx context.Context, st composed.State) (error, context.Context
4141
state.ObjAsNfsInstance().Status.State = cloudresourcesv1beta1.ErrorState
4242
err = state.UpdateObjStatus(ctx)
4343
if err != nil {
44-
return composed.LogErrorAndReturn(err, "Error updating NfsInstance status after referred IpRange not found", composed.StopWithRequeue, nil)
44+
return composed.LogErrorAndReturn(err, "Error updating NfsInstance status after referred IpRange not found", composed.StopWithRequeue, ctx)
4545
}
4646

4747
return composed.StopAndForget, nil

pkg/kcp/provider/aws/iprange/checkCidrBlockStatus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func checkCidrBlockStatus(ctx context.Context, st composed.State) (error, contex
7070
})
7171
err := state.UpdateObjStatus(ctx)
7272
if err != nil {
73-
return composed.LogErrorAndReturn(err, "Failed updating CidrAssociationFailed status", composed.StopWithRequeue, nil)
73+
return composed.LogErrorAndReturn(err, "Failed updating CidrAssociationFailed status", composed.StopWithRequeue, ctx)
7474
}
7575

7676
return composed.StopAndForget, nil

pkg/kcp/provider/aws/iprange/checkCidrOverlap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func checkCidrOverlap(ctx context.Context, st composed.State) (error, context.Co
3737
})
3838
err := state.UpdateObjStatus(ctx)
3939
if err != nil {
40-
return composed.LogErrorAndReturn(err, "Error updating IpRange status due to cidr overlap", composed.StopWithRequeue, nil)
40+
return composed.LogErrorAndReturn(err, "Error updating IpRange status due to cidr overlap", composed.StopWithRequeue, ctx)
4141
}
4242

4343
return composed.StopAndForget, nil

pkg/kcp/provider/aws/iprange/ensureShootZonesAndRangeSubnetsMatch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func ensureShootZonesAndRangeSubnetsMatch(ctx context.Context, st composed.State
3232

3333
err := state.UpdateObjStatus(ctx)
3434
if err != nil {
35-
return composed.LogErrorAndReturn(err, "Error updating IpRange status on shoot and vpc mismatch", composed.StopWithRequeue, nil)
35+
return composed.LogErrorAndReturn(err, "Error updating IpRange status on shoot and vpc mismatch", composed.StopWithRequeue, ctx)
3636
}
3737

3838
return composed.StopAndForget, nil

pkg/kcp/provider/aws/iprange/extendVpcAddressSpace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func extendVpcAddressSpace(ctx context.Context, st composed.State) (error, conte
3131
})
3232
err = state.UpdateObjStatus(ctx)
3333
if err != nil {
34-
return composed.LogErrorAndReturn(err, "Error updating status due to failed extending vpc address space", composed.StopWithRequeue, nil)
34+
return composed.LogErrorAndReturn(err, "Error updating status due to failed extending vpc address space", composed.StopWithRequeue, ctx)
3535
}
3636

3737
return composed.StopAndForget, nil

pkg/kcp/provider/aws/iprange/loadSubnets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func loadSubnets(ctx context.Context, st composed.State) (error, context.Context
1111

1212
subnetList, err := state.client.DescribeSubnets(ctx, pointer.StringDeref(state.vpc.VpcId, ""))
1313
if err != nil {
14-
return composed.LogErrorAndReturn(err, "Error loading subnets", composed.StopWithRequeue, nil)
14+
return composed.LogErrorAndReturn(err, "Error loading subnets", composed.StopWithRequeue, ctx)
1515
}
1616

1717
state.allSubnets = subnetList

pkg/kcp/provider/aws/iprange/splitRangeByZones.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func splitRangeByZones(ctx context.Context, st composed.State) (error, context.C
7272
err = state.UpdateObjStatus(ctx)
7373
if err != nil {
7474
err = fmt.Errorf("error updating IpRange status: %w", err)
75-
return composed.LogErrorAndReturn(err, "Error splitting IpRange CIDR", composed.StopWithRequeue, nil)
75+
return composed.LogErrorAndReturn(err, "Error splitting IpRange CIDR", composed.StopWithRequeue, ctx)
7676
}
7777

7878
return composed.StopWithRequeue, nil

pkg/kcp/provider/aws/iprange/updateSuccessStatus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func updateSuccessStatus(ctx context.Context, st composed.State) (error, context
2222

2323
err := state.UpdateObjStatus(ctx)
2424
if err != nil {
25-
return composed.LogErrorAndReturn(err, "Error updating IpRange success status", composed.StopWithRequeue, nil)
25+
return composed.LogErrorAndReturn(err, "Error updating IpRange success status", composed.StopWithRequeue, ctx)
2626
}
2727

2828
return nil, nil

0 commit comments

Comments
 (0)