Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
Signed-off-by: Charly Molter <charly.molter@konghq.com>
  • Loading branch information
lahabana committed Oct 9, 2023
1 parent cc98b42 commit baef991
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions pkg/core/resources/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ func NewTypeRegistry() TypeRegistry {
}
}

type InvalidResourceType struct {
type InvalidResourceTypeError struct {
ResType model.ResourceType
}

func (e *InvalidResourceType) Error() string {
func (e *InvalidResourceTypeError) Error() string {
return fmt.Sprintf("invalid resource type %q", e.ResType)
}

func (e *InvalidResourceType) Is(target error) bool {
t, ok := target.(*InvalidResourceType)
func (e *InvalidResourceTypeError) Is(target error) bool {
t, ok := target.(*InvalidResourceTypeError)
if !ok {
return false
}
Expand All @@ -49,7 +49,7 @@ type typeRegistry struct {
func (t *typeRegistry) DescriptorFor(resType model.ResourceType) (model.ResourceTypeDescriptor, error) {
typDesc, ok := t.descriptors[resType]
if !ok {
return model.ResourceTypeDescriptor{}, &InvalidResourceType{ResType: resType}
return model.ResourceTypeDescriptor{}, &InvalidResourceTypeError{ResType: resType}
}
return typDesc, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/rest/errors/error_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func HandleError(ctx context.Context, response *restful.Response, err error, tit
Title: title,
Detail: "Not found",
}
case errors.Is(err, &rest.InvalidResourceError{}) || errors.Is(err, &registry.InvalidResourceType{}) || errors.Is(err, &store.PreconditionError{}):
case errors.Is(err, &rest.InvalidResourceError{}) || errors.Is(err, &registry.InvalidResourceTypeError{}) || errors.Is(err, &store.PreconditionError{}):
kumaErr = &types.Error{
Status: 400,
Title: "Bad Request",
Expand Down
5 changes: 3 additions & 2 deletions pkg/kds/server/status_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package server

import (
"context"
"errors"
"time"

"github.com/go-logr/logr"
"google.golang.org/protobuf/proto"

system_proto "github.com/kumahq/kuma/api/system/v1alpha1"
config_store "github.com/kumahq/kuma/pkg/config/core/resources/store"
Expand All @@ -15,7 +17,6 @@ import (
"github.com/kumahq/kuma/pkg/core/user"
kuma_log "github.com/kumahq/kuma/pkg/log"
"github.com/kumahq/kuma/pkg/multitenant"
"google.golang.org/protobuf/proto"
)

type ZoneInsightSink interface {
Expand Down Expand Up @@ -85,7 +86,7 @@ func (s *zoneInsightSink) Start(ctx context.Context, stop <-chan struct{}) {
}

if err := s.store.Upsert(gracefulCtx, zone, currentState); err != nil {
if store.IsResourceConflict(err) || store.IsResourceAlreadyExists(err) {
if errors.Is(err, &store.ResourceConflictError{}) {
log.V(1).Info("failed to flush ZoneInsight because it was updated in other place. Will retry in the next tick", "zone", zone)
} else {
log.Error(err, "failed to flush zone status", "zone", zone)
Expand Down

0 comments on commit baef991

Please sign in to comment.