Skip to content

Commit 106c1e6

Browse files
committed
refactor: improve error logging and clean up imports
1 parent 726af59 commit 106c1e6

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

controller/lifecycle/controllerruntime/lifecycle_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/platform-mesh/golang-commons/controller/lifecycle/runtimeobject"
1717
"github.com/platform-mesh/golang-commons/controller/lifecycle/subroutine"
1818
pmtesting "github.com/platform-mesh/golang-commons/controller/testSupport"
19-
operrors "github.com/platform-mesh/golang-commons/errors"
19+
"github.com/platform-mesh/golang-commons/errors"
2020
"github.com/platform-mesh/golang-commons/logger/testlogger"
2121
)
2222

@@ -92,7 +92,7 @@ func TestLifecycle(t *testing.T) {
9292
fakeClient := pmtesting.CreateFakeClient(t, testApiObject)
9393

9494
lm, _ := createLifecycleManager([]subroutine.Subroutine{pmtesting.ContextValueSubroutine{}}, fakeClient)
95-
lm = lm.WithPrepareContextFunc(func(ctx context.Context, instance runtimeobject.RuntimeObject) (context.Context, operrors.OperatorError) {
95+
lm = lm.WithPrepareContextFunc(func(ctx context.Context, instance runtimeobject.RuntimeObject) (context.Context, errors.OperatorError) {
9696
return context.WithValue(ctx, pmtesting.ContextValueKey, "valueFromContext"), nil
9797
})
9898
tr := &testReconciler{lifecycleManager: lm}
@@ -115,8 +115,8 @@ func TestLifecycle(t *testing.T) {
115115
fakeClient := pmtesting.CreateFakeClient(t, testApiObject)
116116

117117
lm, _ := createLifecycleManager([]subroutine.Subroutine{pmtesting.ContextValueSubroutine{}}, fakeClient)
118-
lm = lm.WithPrepareContextFunc(func(ctx context.Context, instance runtimeobject.RuntimeObject) (context.Context, operrors.OperatorError) {
119-
return nil, operrors.NewOperatorError(goerrors.New(errorMessage), true, false)
118+
lm = lm.WithPrepareContextFunc(func(ctx context.Context, instance runtimeobject.RuntimeObject) (context.Context, errors.OperatorError) {
119+
return nil, errors.NewOperatorError(goerrors.New(errorMessage), true, false)
120120
})
121121
tr := &testReconciler{lifecycleManager: lm}
122122
result, err := tr.Reconcile(ctx, controllerruntime.Request{NamespacedName: types.NamespacedName{Name: name, Namespace: namespace}})

controller/lifecycle/lifecycle.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func Reconcile(ctx context.Context, nName types.NamespacedName, instance runtime
4141

4242
log.Info().Msg("start reconcile")
4343

44-
nn := types.NamespacedName{Namespace: nName.Namespace, Name: nName.Name}
45-
err := cl.Get(ctx, nn, instance)
44+
err := cl.Get(ctx, nName, instance)
4645
if err != nil {
4746
if kerrors.IsNotFound(err) {
4847
log.Info().Msg("instance not found. It was likely deleted")
@@ -71,8 +70,7 @@ func Reconcile(ctx context.Context, nName types.NamespacedName, instance runtime
7170

7271
var condArr []v1.Condition
7372
if l.ConditionsManager() != nil {
74-
roc := util.MustToInterface[api.RuntimeObjectConditions](instance, log)
75-
condArr = roc.GetConditions()
73+
condArr = util.MustToInterface[api.RuntimeObjectConditions](instance, log).GetConditions()
7674
l.ConditionsManager().SetInstanceConditionUnknownIfNotSet(&condArr)
7775
}
7876

controller/lifecycle/util/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ func MustToInterface[T any](instance any, log *logger.Logger) T {
2525
if err == nil {
2626
return obj
2727
}
28-
log.Panic().Err(err).Msg("Failed to cast instance to RuntimeObjectSpreadReconcileStatus")
28+
log.Panic().Err(err).Msg("Failed to cast instance to target interface")
2929
panic(err)
3030
}

go.mod

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ module github.com/platform-mesh/golang-commons
22

33
go 1.24.3
44

5-
replace (
6-
k8s.io/api => k8s.io/api v0.32.3
7-
k8s.io/apimachinery => k8s.io/apimachinery v0.32.3
8-
k8s.io/client-go => k8s.io/client-go v0.32.3
9-
k8s.io/utils => k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
10-
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.20.4
11-
)
5+
replace sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.20.4
126

137
require (
148
github.com/99designs/gqlgen v0.17.76
@@ -34,6 +28,7 @@ require (
3428
github.com/vektah/gqlparser/v2 v2.5.30
3529
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0
3630
go.opentelemetry.io/otel v1.37.0
31+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0
3732
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0
3833
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.37.0
3934
go.opentelemetry.io/otel/sdk v1.37.0
@@ -71,12 +66,10 @@ require (
7166
github.com/go-openapi/swag v0.23.0 // indirect
7267
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
7368
github.com/gogo/protobuf v1.3.2 // indirect
74-
github.com/golang/protobuf v1.5.4 // indirect
7569
github.com/google/btree v1.1.3 // indirect
7670
github.com/google/cel-go v0.25.0 // indirect
7771
github.com/google/gnostic-models v0.6.9 // indirect
7872
github.com/google/go-cmp v0.7.0 // indirect
79-
github.com/google/gofuzz v1.2.0 // indirect
8073
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
8174
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 // indirect
8275
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirect
@@ -112,7 +105,6 @@ require (
112105
github.com/x448/float16 v0.8.4 // indirect
113106
github.com/zeebo/xxh3 v1.0.2 // indirect
114107
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
115-
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0 // indirect
116108
go.opentelemetry.io/otel/metric v1.37.0 // indirect
117109
go.opentelemetry.io/otel/trace v1.37.0 // indirect
118110
go.uber.org/mock v0.5.2 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,14 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
453453
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
454454
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
455455
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
456-
k8s.io/api v0.32.3 h1:Hw7KqxRusq+6QSplE3NYG4MBxZw1BZnq4aP4cJVINls=
457-
k8s.io/api v0.32.3/go.mod h1:2wEDTXADtm/HA7CCMD8D8bK4yuBUptzaRhYcYEEYA3k=
456+
k8s.io/api v0.33.0 h1:yTgZVn1XEe6opVpP1FylmNrIFWuDqe2H0V8CT5gxfIU=
457+
k8s.io/api v0.33.0/go.mod h1:CTO61ECK/KU7haa3qq8sarQ0biLq2ju405IZAd9zsiM=
458458
k8s.io/apiextensions-apiserver v0.33.0 h1:d2qpYL7Mngbsc1taA4IjJPRJ9ilnsXIrndH+r9IimOs=
459459
k8s.io/apiextensions-apiserver v0.33.0/go.mod h1:VeJ8u9dEEN+tbETo+lFkwaaZPg6uFKLGj5vyNEwwSzc=
460-
k8s.io/apimachinery v0.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U=
461-
k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
462-
k8s.io/client-go v0.32.3 h1:RKPVltzopkSgHS7aS98QdscAgtgah/+zmpAogooIqVU=
463-
k8s.io/client-go v0.32.3/go.mod h1:3v0+3k4IcT9bXTc4V2rt+d2ZPPG700Xy6Oi0Gdl2PaY=
460+
k8s.io/apimachinery v0.33.0 h1:1a6kHrJxb2hs4t8EE5wuR/WxKDwGN1FKH3JvDtA0CIQ=
461+
k8s.io/apimachinery v0.33.0/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM=
462+
k8s.io/client-go v0.33.0 h1:UASR0sAYVUzs2kYuKn/ZakZlcs2bEHaizrrHUZg0G98=
463+
k8s.io/client-go v0.33.0/go.mod h1:kGkd+l/gNGg8GYWAPr0xF1rRKvVWvzh9vmZAMXtaKOg=
464464
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
465465
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
466466
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUyGcf03XZEP0ZIKgKj35LS4=

0 commit comments

Comments
 (0)