Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nats error checking logic to use new exported error type #873

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ require (
github.com/mattn/go-tty v0.0.4
github.com/mikefarah/yq/v4 v4.30.4
github.com/mitchellh/mapstructure v1.5.0
github.com/nats-io/nats.go v1.20.0
github.com/nats-io/nats.go v1.21.0
github.com/nats-io/nkeys v0.3.0
github.com/olebedev/when v0.0.0-20211212231525-59bd4edcf9d6
github.com/onsi/ginkgo/v2 v2.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2205,8 +2205,8 @@ github.com/nats-io/jwt/v2 v2.2.1-0.20220330180145-442af02fd36a/go.mod h1:0tqz9Hl
github.com/nats-io/nats-server/v2 v2.8.4 h1:0jQzze1T9mECg8YZEl8+WYUXb9JKluJfCBriPUtluB4=
github.com/nats-io/nats-server/v2 v2.8.4/go.mod h1:8zZa+Al3WsESfmgSs98Fi06dRWLH5Bnq90m5bKD/eT4=
github.com/nats-io/nats.go v1.15.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/nats.go v1.20.0 h1:T8JJnQfVSdh1CzGiwAOv5hEobYCBho/0EupGznYw0oM=
github.com/nats-io/nats.go v1.20.0/go.mod h1:tLqubohF7t4z3du1QDPYJIQQyhb4wl6DhjxEajSI7UA=
github.com/nats-io/nats.go v1.21.0 h1:kQiWyQMMMIPjDR7NanrLhTnRUxWgU04yrzmYdq9JxCU=
github.com/nats-io/nats.go v1.21.0/go.mod h1:tLqubohF7t4z3du1QDPYJIQQyhb4wl6DhjxEajSI7UA=
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/jetstream/cluster_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *JetStreamStore) CreateCluster(ctx context.Context, cluster *corev1.Clus
}
rev, err := s.kv.Clusters.Create(cluster.Id, data)
if err != nil {
if errIsKeyAlreadyExists(err) {
if errors.Is(err, nats.ErrKeyExists) {
return storage.ErrAlreadyExists
}
return fmt.Errorf("failed to create cluster: %w", err)
Expand Down
11 changes: 0 additions & 11 deletions pkg/storage/jetstream/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package jetstream

import (
"context"
"errors"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -170,13 +169,3 @@ func (s *JetStreamStore) KeyValueStore(prefix string) storage.KeyValueStore {
kv: bucket,
}
}

func errIsKeyAlreadyExists(err error) bool {
// TODO: this error code is not exported by the nats.go client
// https://github.com/nats-io/nats.go/issues/1134
apierror := &nats.APIError{}
if errors.As(err, &apierror) {
return apierror.ErrorCode == 10071
}
return false
}
4 changes: 2 additions & 2 deletions pkg/storage/jetstream/rbac_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (s *JetStreamStore) CreateRole(ctx context.Context, role *corev1.Role) erro
return err
}
_, err = s.kv.Roles.Create(role.Id, data)
if errIsKeyAlreadyExists(err) {
if errors.Is(err, nats.ErrKeyExists) {
return storage.ErrAlreadyExists
}
return err
Expand Down Expand Up @@ -53,7 +53,7 @@ func (s *JetStreamStore) CreateRoleBinding(ctx context.Context, rb *corev1.RoleB
return err
}
_, err = s.kv.RoleBindings.Create(rb.Id, data)
if errIsKeyAlreadyExists(err) {
if errors.Is(err, nats.ErrKeyExists) {
return storage.ErrAlreadyExists
}
return err
Expand Down