Skip to content

Commit c6e04f8

Browse files
committed
Use helper to get type
1 parent bb16739 commit c6e04f8

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

internal/actions/create_handler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package actions
33
import (
44
"context"
55
"fmt"
6-
"reflect"
76

87
jsonpatch "github.com/evanphx/json-patch"
98
"github.com/sirupsen/logrus"
@@ -45,7 +44,7 @@ func (h *CreateHandler) Handle(ctx context.Context, action *castai.ClusterAction
4544

4645
log := h.log.WithFields(logrus.Fields{
4746
ActionIDLogField: action.ID,
48-
"action": reflect.TypeOf(action.Data()).String(),
47+
"action": action.GetType(),
4948
"gvr": req.GroupVersionResource.String(),
5049
"name": newObj.GetName(),
5150
})

internal/actions/delete_handler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package actions
33
import (
44
"context"
55
"fmt"
6-
"reflect"
76

87
"github.com/sirupsen/logrus"
98
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -36,7 +35,7 @@ func (h *DeleteHandler) Handle(ctx context.Context, action *castai.ClusterAction
3635

3736
log := h.log.WithFields(logrus.Fields{
3837
"id": action.ID,
39-
"action": reflect.TypeOf(action.Data()).String(),
38+
"action": action.GetType(),
4039
"gvr": req.ID.GroupVersionResource.String(),
4140
"name": req.ID.Name,
4241
})

internal/actions/patch_handler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package actions
33
import (
44
"context"
55
"fmt"
6-
"reflect"
76

87
"github.com/samber/lo"
98
"github.com/sirupsen/logrus"
@@ -43,7 +42,7 @@ func (h *PatchHandler) Handle(ctx context.Context, action *castai.ClusterAction)
4342

4443
log := h.log.WithFields(logrus.Fields{
4544
ActionIDLogField: action.ID,
46-
"action": reflect.TypeOf(action.Data()).String(),
45+
"action": action.GetType(),
4746
"gvr": req.ID.GroupVersionResource.String(),
4847
"name": req.ID.Name,
4948
})

internal/actions/patch_node_handler.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package actions
33
import (
44
"context"
55
"encoding/json"
6-
"errors"
76
"fmt"
87
"reflect"
98
"strconv"
@@ -30,8 +29,6 @@ type PatchNodeHandler struct {
3029
clientset kubernetes.Interface
3130
}
3231

33-
var errAction = errors.New("not valid action")
34-
3532
func (h *PatchNodeHandler) Handle(ctx context.Context, action *castai.ClusterAction) error {
3633
req, ok := action.Data().(*castai.ActionPatchNode)
3734
if !ok {

internal/actions/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package actions
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910

1011
"github.com/castai/cluster-controller/internal/castai"
@@ -16,6 +17,8 @@ const (
1617
ActionIDLogField = "id"
1718
)
1819

20+
var errAction = errors.New("not valid action")
21+
1922
func newUnexpectedTypeErr(value, expectedType interface{}) error {
2023
return fmt.Errorf("unexpected type %T, expected %T %w", value, expectedType, errAction)
2124
}

0 commit comments

Comments
 (0)