From 240d9623a2659cb7f57d36528bb0d515528aa324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Burzy=C5=84ski?= Date: Tue, 30 May 2023 16:22:57 +0200 Subject: [PATCH] chore: enable golang-ci errorlint (#923) --- .golangci.yml | 3 +- cmd/common_konnect.go | 2 +- cmd/convert.go | 4 +-- cmd/root.go | 3 +- diff/diff.go | 4 +-- dump/dump.go | 4 ++- dump/dump_konnect.go | 6 ++-- file/builder.go | 56 +++++++++++++++---------------- file/writer.go | 3 +- konnect/error.go | 17 +++------- state/aclgroup.go | 5 +-- state/builder.go | 7 ++-- state/cacert.go | 5 +-- state/certificate.go | 3 +- state/consumer.go | 5 +-- state/consumer_group.go | 7 ++-- state/consumer_group_consumers.go | 3 +- state/consumer_group_plugin.go | 3 +- state/credentials.go | 5 +-- state/document.go | 3 +- state/plugin.go | 5 +-- state/rbac_endpoint_permission.go | 5 +-- state/rbac_role.go | 5 +-- state/route.go | 5 +-- state/service.go | 5 +-- state/service_package.go | 5 +-- state/service_version.go | 3 +- state/sni.go | 5 +-- state/target.go | 3 +- state/upstream.go | 7 ++-- state/vault.go | 7 ++-- types/aclgroup.go | 5 +-- types/basicauth.go | 5 +-- types/ca_cert.go | 5 +-- types/certificate.go | 5 +-- types/consumer.go | 7 ++-- types/consumer_group.go | 5 +-- types/consumer_group_consumer.go | 5 +-- types/consumer_group_plugin.go | 3 +- types/document.go | 5 +-- types/hmacauth.go | 5 +-- types/jwtauth.go | 5 +-- types/keyauth.go | 5 +-- types/mtlsauth.go | 5 +-- types/oauth2.go | 5 +-- types/plugin.go | 5 +-- types/rbac_endpoint_permission.go | 5 +-- types/rbac_role.go | 5 +-- types/route.go | 7 ++-- types/service.go | 7 ++-- types/service_package.go | 5 +-- types/service_version.go | 5 +-- types/sni.go | 5 +-- types/target.go | 5 +-- types/upstream.go | 5 +-- types/vault.go | 5 +-- utils/defaulter.go | 14 ++++---- validate/validate.go | 3 +- 58 files changed, 197 insertions(+), 152 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c02df57c5..f99d645b0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,6 +27,7 @@ linters: - unconvert - unparam - wastedassign + - errorlint issues: exclude-rules: - linters: @@ -80,4 +81,4 @@ linters-settings: - sigs.k8s.io/yaml - gopkg.in/yaml.v3: recommendations: - - sigs.k8s.io/yaml \ No newline at end of file + - sigs.k8s.io/yaml diff --git a/cmd/common_konnect.go b/cmd/common_konnect.go index fbe4a1feb..f6a2b5f1b 100644 --- a/cmd/common_konnect.go +++ b/cmd/common_konnect.go @@ -74,7 +74,7 @@ func GetKongClientForKonnectMode( } parsedAddress, err = url.Parse(address) if err != nil { - return nil, fmt.Errorf("parsing %s address: %v", address, err) + return nil, fmt.Errorf("parsing %s address: %w", address, err) } _, err = authenticate(ctx, konnectClient, parsedAddress.Host, *konnectConfig) if err == nil { diff --git a/cmd/convert.go b/cmd/convert.go index 5240db2ff..0476ab2e2 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -48,7 +48,7 @@ can be converted into a 'kong-gateway-3.x' configuration file.`, err = convert.Convert(convertCmdInputFile, convertCmdOutputFile, sourceFormat, destinationFormat) if err != nil { - return fmt.Errorf("converting file: %v", err) + return fmt.Errorf("converting file: %w", err) } } else if is2xTo3xConversion() { path, err := os.Getwd() @@ -62,7 +62,7 @@ can be converted into a 'kong-gateway-3.x' configuration file.`, for _, filename := range files { err = convert.Convert(filename, filename, sourceFormat, destinationFormat) if err != nil { - return fmt.Errorf("converting '%s' file: %v", filename, err) + return fmt.Errorf("converting '%s' file: %w", filename, err) } } } diff --git a/cmd/root.go b/cmd/root.go index 72d0ad2b4..a14748744 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "fmt" "io/ioutil" "net/url" @@ -250,7 +251,7 @@ func initConfig() { viper.AutomaticEnv() // read in environment variables that match // If a config file is found, read it in. if err := viper.ReadInConfig(); err != nil { - if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + if !errors.As(err, &viper.ConfigFileNotFoundError{}) { fmt.Println(err) os.Exit(1) } diff --git a/diff/diff.go b/diff/diff.go index 214945ffd..85ce902b2 100644 --- a/diff/diff.go +++ b/diff/diff.go @@ -339,7 +339,7 @@ func (sc *Syncer) Run(ctx context.Context, parallelism int, d Do) []error { errs = append(errs, fmt.Errorf("failed to sync all entities: %w", ctx.Err())) case err, ok := <-sc.errChan: if ok && err != nil { - if err != errEnqueueFailed { + if !errors.Is(err, errEnqueueFailed) { errs = append(errs, err) } } @@ -350,7 +350,7 @@ func (sc *Syncer) Run(ctx context.Context, parallelism int, d Do) []error { // collect errors for err := range sc.errChan { - if err != errEnqueueFailed { + if !errors.Is(err, errEnqueueFailed) { errs = append(errs, err) } } diff --git a/dump/dump.go b/dump/dump.go index 901026432..51fa2e7d7 100644 --- a/dump/dump.go +++ b/dump/dump.go @@ -2,6 +2,7 @@ package dump import ( "context" + "errors" "fmt" "net/http" @@ -829,7 +830,8 @@ func GetAllMTLSAuths(ctx context.Context, // but this is currently necessary for compatibility. We need a better approach // before adding other Enterprise resources that decK handles by default (versus, // for example, RBAC roles, which require the --rbac-resources-only flag). - if kongErr, ok := err.(*kong.APIError); ok { + var kongErr *kong.APIError + if errors.As(err, &kongErr) { if kongErr.Code() == http.StatusForbidden { return mtlsAuths, nil } diff --git a/dump/dump_konnect.go b/dump/dump_konnect.go index a823c4c6c..3e8b50d59 100644 --- a/dump/dump_konnect.go +++ b/dump/dump_konnect.go @@ -56,7 +56,7 @@ func GetFromKonnect(ctx context.Context, konnectClient *konnect.Client, // the number of parallel requests err := semaphore.Acquire(ctx, 2) if err != nil { - return fmt.Errorf("acquire semaphore: %v", err) + return fmt.Errorf("acquire semaphore: %w", err) } go func(i int) { defer semaphore.Release(1) @@ -81,7 +81,7 @@ func GetFromKonnect(ctx context.Context, konnectClient *konnect.Client, for _, version := range servicePackages[i].Versions { err := semaphore.Acquire(ctx, 1) if err != nil { - return fmt.Errorf("acquire semaphore: %v", err) + return fmt.Errorf("acquire semaphore: %w", err) } go func(version konnect.ServiceVersion) { defer semaphore.Release(1) @@ -96,7 +96,7 @@ func GetFromKonnect(ctx context.Context, konnectClient *konnect.Client, } err = semaphore.Acquire(ctx, concurrency) if err != nil { - return fmt.Errorf("acquire semaphore: %v", err) + return fmt.Errorf("acquire semaphore: %w", err) } close(errChan) semaphore.Release(concurrency) diff --git a/file/builder.go b/file/builder.go index ffdcaed76..a0286e215 100644 --- a/file/builder.go +++ b/file/builder.go @@ -101,7 +101,7 @@ func (b *stateBuilder) consumerGroups() { cg := cg if utils.Empty(cg.ID) { current, err := b.currentState.ConsumerGroups.Get(*cg.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { cg.ID = uuid() } else if err != nil { b.err = err @@ -121,7 +121,7 @@ func (b *stateBuilder) consumerGroups() { current, err := b.currentState.ConsumerGroupPlugins.Get( *plugin.Name, *cg.ConsumerGroup.ID, ) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { plugin.ID = uuid() } else if err != nil { b.err = err @@ -147,7 +147,7 @@ func (b *stateBuilder) certificates() { if utils.Empty(c.ID) { cert, err := b.currentState.Certificates.GetByCertKey(*c.Cert, *c.Key) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { c.ID = uuid() } else if err != nil { b.err = err @@ -187,7 +187,7 @@ func (b *stateBuilder) ingestSNIs(snis []kong.SNI) error { sni := sni if utils.Empty(sni.ID) { currentSNI, err := b.currentState.SNIs.Get(*sni.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { sni.ID = uuid() } else if err != nil { return err @@ -210,7 +210,7 @@ func (b *stateBuilder) caCertificates() { c := c if utils.Empty(c.ID) { cert, err := b.currentState.CACertificates.Get(*c.Cert) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { c.ID = uuid() } else if err != nil { b.err = err @@ -235,7 +235,7 @@ func (b *stateBuilder) consumers() { c := c if utils.Empty(c.ID) { consumer, err := b.currentState.Consumers.Get(*c.Username) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { if c.CustomID != nil { consumer, err = b.currentState.Consumers.Get(*c.CustomID) if err == nil { @@ -384,7 +384,7 @@ func (b *stateBuilder) ingestKeyAuths(creds []kong.KeyAuth) error { cred := cred if utils.Empty(cred.ID) { existingCred, err := b.currentState.KeyAuths.Get(*cred.Key) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { cred.ID = uuid() } else if err != nil { return err @@ -405,7 +405,7 @@ func (b *stateBuilder) ingestBasicAuths(creds []kong.BasicAuth) error { cred := cred if utils.Empty(cred.ID) { existingCred, err := b.currentState.BasicAuths.Get(*cred.Username) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { cred.ID = uuid() } else if err != nil { return err @@ -426,7 +426,7 @@ func (b *stateBuilder) ingestHMACAuths(creds []kong.HMACAuth) error { cred := cred if utils.Empty(cred.ID) { existingCred, err := b.currentState.HMACAuths.Get(*cred.Username) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { cred.ID = uuid() } else if err != nil { return err @@ -447,7 +447,7 @@ func (b *stateBuilder) ingestJWTAuths(creds []kong.JWTAuth) error { cred := cred if utils.Empty(cred.ID) { existingCred, err := b.currentState.JWTAuths.Get(*cred.Key) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { cred.ID = uuid() } else if err != nil { return err @@ -468,7 +468,7 @@ func (b *stateBuilder) ingestOauth2Creds(creds []kong.Oauth2Credential) error { cred := cred if utils.Empty(cred.ID) { existingCred, err := b.currentState.Oauth2Creds.Get(*cred.ClientID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { cred.ID = uuid() } else if err != nil { return err @@ -491,7 +491,7 @@ func (b *stateBuilder) ingestACLGroups(creds []kong.ACLGroup) error { existingCred, err := b.currentState.ACLGroups.Get( *cred.Consumer.ID, *cred.Group) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { cred.ID = uuid() } else if err != nil { return err @@ -532,7 +532,7 @@ func (b *stateBuilder) konnect() { targetSP := b.targetContent.ServicePackages[i] if utils.Empty(targetSP.ID) { currentSP, err := b.currentState.ServicePackages.Get(*targetSP.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { targetSP.ID = uuid() } else if err != nil { b.err = err @@ -558,7 +558,7 @@ func (b *stateBuilder) konnect() { } if utils.Empty(targetKonnectDoc.ID) { currentDoc, err := b.currentState.Documents.GetByParent(&targetKonnectSP, *targetKonnectDoc.Path) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { targetKonnectDoc.ID = uuid() } else if err != nil { b.err = err @@ -579,7 +579,7 @@ func (b *stateBuilder) konnect() { targetRelationID := "" if utils.Empty(targetKonnectSV.ID) { currentSV, err := b.currentState.ServiceVersions.Get(*targetKonnectSP.ID, *targetKonnectSV.Version) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { targetKonnectSV.ID = uuid() } else if err != nil { b.err = err @@ -615,7 +615,7 @@ func (b *stateBuilder) konnect() { } if utils.Empty(targetKonnectDoc.ID) { currentDoc, err := b.currentState.Documents.GetByParent(&targetKonnectSV, *targetKonnectDoc.Path) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { targetKonnectDoc.ID = uuid() } else if err != nil { b.err = err @@ -652,7 +652,7 @@ func (b *stateBuilder) services() { func (b *stateBuilder) ingestService(s *FService) error { if utils.Empty(s.ID) { svc, err := b.currentState.Services.Get(*s.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { s.ID = uuid() } else if err != nil { return err @@ -736,7 +736,7 @@ func (b *stateBuilder) vaults() { v := v if utils.Empty(v.ID) { vault, err := b.currentState.Vaults.Get(*v.Prefix) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { v.ID = uuid() } else if err != nil { b.err = err @@ -760,7 +760,7 @@ func (b *stateBuilder) rbacRoles() { r := r if utils.Empty(r.ID) { role, err := b.currentState.RBACRoles.Get(*r.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { r.ID = uuid() } else if err != nil { b.err = err @@ -788,7 +788,7 @@ func (b *stateBuilder) upstreams() { u := u if utils.Empty(u.ID) { ups, err := b.currentState.Upstreams.Get(*u.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { u.ID = uuid() } else if err != nil { b.err = err @@ -820,7 +820,7 @@ func (b *stateBuilder) ingestTargets(targets []kong.Target) error { t := t if utils.Empty(t.ID) { target, err := b.currentState.Targets.Get(*t.Upstream.ID, *t.Target) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { t.ID = uuid() } else if err != nil { return err @@ -845,7 +845,7 @@ func (b *stateBuilder) plugins() { p := p if p.Consumer != nil && !utils.Empty(p.Consumer.ID) { c, err := b.intermediate.Consumers.Get(*p.Consumer.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { b.err = fmt.Errorf("consumer %v for plugin %v: %w", p.Consumer.FriendlyName(), *p.Name, err) @@ -858,7 +858,7 @@ func (b *stateBuilder) plugins() { } if p.Service != nil && !utils.Empty(p.Service.ID) { s, err := b.intermediate.Services.Get(*p.Service.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { b.err = fmt.Errorf("service %v for plugin %v: %w", p.Service.FriendlyName(), *p.Name, err) @@ -871,7 +871,7 @@ func (b *stateBuilder) plugins() { } if p.Route != nil && !utils.Empty(p.Route.ID) { r, err := b.intermediate.Routes.Get(*p.Route.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { b.err = fmt.Errorf("route %v for plugin %v: %w", p.Route.FriendlyName(), *p.Name, err) @@ -911,7 +911,7 @@ func getStripPathBasedOnProtocols(route kong.Route) (*bool, error) { func (b *stateBuilder) ingestRoute(r FRoute) error { if utils.Empty(r.ID) { route, err := b.currentState.Routes.Get(*r.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { r.ID = uuid() } else if err != nil { return err @@ -988,7 +988,7 @@ func (b *stateBuilder) addPluginDefaults(plugin *FPlugin) error { if errors.Is(err, ErrWorkspaceNotFound) { return nil } - return fmt.Errorf("retrieve schema for %v from Kong: %v", *plugin.Name, err) + return fmt.Errorf("retrieve schema for %v from Kong: %w", *plugin.Name, err) } return kong.FillPluginsDefaults(&plugin.Plugin, schema) } @@ -1000,7 +1000,7 @@ func (b *stateBuilder) ingestPlugins(plugins []FPlugin) error { cID, rID, sID := pluginRelations(&p.Plugin) plugin, err := b.currentState.Plugins.GetByProp(*p.Name, sID, rID, cID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { p.ID = uuid() } else if err != nil { return err @@ -1017,7 +1017,7 @@ func (b *stateBuilder) ingestPlugins(plugins []FPlugin) error { return err } if err := b.addPluginDefaults(&p); err != nil { - return fmt.Errorf("add defaults to plugin '%v': %v", *p.Name, err) + return fmt.Errorf("add defaults to plugin '%v': %w", *p.Name, err) } utils.MustMergeTags(&p, b.selectTags) b.rawState.Plugins = append(b.rawState.Plugins, &p.Plugin) diff --git a/file/writer.go b/file/writer.go index fba59da24..4905f046c 100644 --- a/file/writer.go +++ b/file/writer.go @@ -2,6 +2,7 @@ package file import ( "encoding/json" + "errors" "fmt" "io/ioutil" "os" @@ -651,7 +652,7 @@ func populateConsumers(kongState *state.KongState, file *Content, cg := *cg _, err := kongState.ConsumerGroupConsumers.Get(*c.ID, *cg.ID) if err != nil { - if err != state.ErrNotFound { + if !errors.Is(err, state.ErrNotFound) { return err } continue diff --git a/konnect/error.go b/konnect/error.go index 1bb1fa73e..1c12d16c5 100644 --- a/konnect/error.go +++ b/konnect/error.go @@ -2,6 +2,7 @@ package konnect import ( "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -49,21 +50,13 @@ func (e *APIError) Code() int { // IsNotFoundErr returns true if the error or it's cause is // a 404 response from Kong. func IsNotFoundErr(e error) bool { - switch e := e.(type) { - case *APIError: - return e.httpCode == http.StatusNotFound - default: - return false - } + var apiErr *APIError + return errors.As(e, &apiErr) && apiErr.httpCode == http.StatusNotFound } // IsUnauthorizedErr returns true if the error or it's cause is // a 401 response from Konnect. func IsUnauthorizedErr(e error) bool { - switch e := e.(type) { - case *APIError: - return e.httpCode == http.StatusUnauthorized - default: - return false - } + var apiErr *APIError + return errors.As(e, &apiErr) && apiErr.httpCode == http.StatusUnauthorized } diff --git a/state/aclgroup.go b/state/aclgroup.go index 7f090e8a5..c3531e518 100644 --- a/state/aclgroup.go +++ b/state/aclgroup.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -77,7 +78,7 @@ func insertACLGroup(txn *memdb.Txn, aclGroup ACLGroup) error { _, err := getACLGroupByID(txn, *aclGroup.ID) if err == nil { return fmt.Errorf("inserting acl-group %v: %w", aclGroup.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -91,7 +92,7 @@ func insertACLGroup(txn *memdb.Txn, aclGroup ACLGroup) error { _, err = getACLGroup(txn, *aclGroup.Consumer.ID, *aclGroup.Group) if err == nil { return fmt.Errorf("inserting acl-group %v: %w", aclGroup.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/builder.go b/state/builder.go index e48333023..cf7e1c20a 100644 --- a/state/builder.go +++ b/state/builder.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" "github.com/kong/deck/utils" @@ -23,7 +24,7 @@ func Get(raw *utils.KongRawState) (*KongState, error) { func ensureService(kongState *KongState, serviceID string) (bool, *kong.Service, error) { s, err := kongState.Services.Get(serviceID) if err != nil { - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { return false, nil, nil } return false, nil, fmt.Errorf("looking up service %q: %w", serviceID, err) @@ -35,7 +36,7 @@ func ensureService(kongState *KongState, serviceID string) (bool, *kong.Service, func ensureRoute(kongState *KongState, routeID string) (bool, *kong.Route, error) { r, err := kongState.Routes.Get(routeID) if err != nil { - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { return false, nil, nil } return false, nil, fmt.Errorf("looking up route %q: %w", routeID, err) @@ -47,7 +48,7 @@ func ensureRoute(kongState *KongState, routeID string) (bool, *kong.Route, error func ensureConsumer(kongState *KongState, consumerID string) (bool, *kong.Consumer, error) { c, err := kongState.Consumers.Get(consumerID) if err != nil { - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { return false, nil, nil } return false, nil, fmt.Errorf("looking up consumer %q: %w", consumerID, err) diff --git a/state/cacert.go b/state/cacert.go index c7dd3e9e1..a14786429 100644 --- a/state/cacert.go +++ b/state/cacert.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -51,7 +52,7 @@ func (k *CACertificatesCollection) Add(caCert CACertificate) error { _, err := getCACert(txn, searchBy...) if err == nil { return fmt.Errorf("inserting ca-cert %v: %w", caCert.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -67,7 +68,7 @@ func getCACert(txn *memdb.Txn, IDs ...string) (*CACertificate, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, caCertTableName, []string{"cert", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/certificate.go b/state/certificate.go index 57ae61c7b..a2f472d6e 100644 --- a/state/certificate.go +++ b/state/certificate.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -60,7 +61,7 @@ func (k *CertificatesCollection) Add(certificate Certificate) error { _, err := getCertificate(txn, *certificate.ID) if err == nil { return fmt.Errorf("inserting certificate %v: %w", certificate.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/consumer.go b/state/consumer.go index 869362b15..d2542c8ee 100644 --- a/state/consumer.go +++ b/state/consumer.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -59,7 +60,7 @@ func (k *ConsumersCollection) Add(consumer Consumer) error { _, err := getConsumer(txn, searchBy...) if err == nil { return fmt.Errorf("inserting consumer %v: %w", consumer.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -75,7 +76,7 @@ func getConsumer(txn *memdb.Txn, IDs ...string) (*Consumer, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, consumerTableName, []string{"Username", "id", "CustomID"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/consumer_group.go b/state/consumer_group.go index 823d122f0..7b1c6ff8c 100644 --- a/state/consumer_group.go +++ b/state/consumer_group.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -48,7 +49,7 @@ func (k *ConsumerGroupsCollection) Add(consumerGroup ConsumerGroup) error { _, err := getConsumerGroup(txn, searchBy...) if err == nil { return fmt.Errorf("inserting consumerGroup %v: %w", consumerGroup.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -64,7 +65,7 @@ func getConsumerGroup(txn *memdb.Txn, IDs ...string) (*ConsumerGroup, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, consumerGroupTableName, []string{"name", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { @@ -90,7 +91,7 @@ func (k *ConsumerGroupsCollection) Get(nameOrID string) (*ConsumerGroup, error) defer txn.Abort() consumerGroup, err := getConsumerGroup(txn, nameOrID) if err != nil { - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { return nil, ErrNotFound } return nil, err diff --git a/state/consumer_group_consumers.go b/state/consumer_group_consumers.go index cb9ee267c..c05adea1c 100644 --- a/state/consumer_group_consumers.go +++ b/state/consumer_group_consumers.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -94,7 +95,7 @@ func (k *ConsumerGroupConsumersCollection) Add(consumer ConsumerGroupConsumer) e _, err := getConsumerGroupConsumer(txn, *consumer.ConsumerGroup.ID, searchBy...) if err == nil { return fmt.Errorf("inserting consumerGroupConsumer %v: %w", consumer.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/consumer_group_plugin.go b/state/consumer_group_plugin.go index d70381d27..f313219be 100644 --- a/state/consumer_group_plugin.go +++ b/state/consumer_group_plugin.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -92,7 +93,7 @@ func (k *ConsumerGroupPluginsCollection) Add(plugin ConsumerGroupPlugin) error { _, err := getConsumerGroupPlugin(txn, *plugin.ConsumerGroup.ID, searchBy...) if err == nil { return fmt.Errorf("inserting consumerGroupPlugin %v: %w", plugin.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/credentials.go b/state/credentials.go index 953f7d97f..ec5d534dd 100644 --- a/state/credentials.go +++ b/state/credentials.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -52,7 +53,7 @@ func (k *credentialsCollection) getCred(txn *memdb.Txn, IDs ...string) (entity, for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, k.CredType, []string{"id", "id2"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { @@ -80,7 +81,7 @@ func (k *credentialsCollection) Add(cred entity) error { _, err := k.getCred(txn, cred.GetID(), cred.GetID2()) if err == nil { return fmt.Errorf("inserting credential %v: %w", cred.GetID(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/document.go b/state/document.go index 8b659d6a5..d5eb1c9ea 100644 --- a/state/document.go +++ b/state/document.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" "github.com/hashicorp/go-memdb" @@ -66,7 +67,7 @@ func (k *DocumentsCollection) Add(document Document) error { _, err := getDocument(txn, document.ParentKey(), searchBy...) if err == nil { return fmt.Errorf("inserting document %v: %w", document.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/plugin.go b/state/plugin.go index b88b2fa6d..841ac1d6f 100644 --- a/state/plugin.go +++ b/state/plugin.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -127,7 +128,7 @@ func insertPlugin(txn *memdb.Txn, plugin Plugin) error { _, err := getPluginByID(txn, *plugin.ID) if err == nil { return fmt.Errorf("inserting plugin %v: %w", plugin.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -145,7 +146,7 @@ func insertPlugin(txn *memdb.Txn, plugin Plugin) error { _, err = getPluginBy(txn, *plugin.Name, sID, rID, cID) if err == nil { return fmt.Errorf("inserting plugin %v: %w", plugin.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/rbac_endpoint_permission.go b/state/rbac_endpoint_permission.go index 2d0c4b1ea..87da91ed1 100644 --- a/state/rbac_endpoint_permission.go +++ b/state/rbac_endpoint_permission.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -68,7 +69,7 @@ func (k *RBACEndpointPermissionsCollection) Add(rbacEndpointPermission RBACEndpo _, err := getRBACEndpointPermission(txn, searchBy...) if err == nil { return fmt.Errorf("inserting rbacEndpointPermission %v: %w", rbacEndpointPermission.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } rbacEndpointPermission.ID = rbacEndpointPermission.FriendlyName() @@ -84,7 +85,7 @@ func getRBACEndpointPermission(txn *memdb.Txn, IDs ...string) (*RBACEndpointPerm for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, rbacEndpointPermissionTableName, []string{"id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/rbac_role.go b/state/rbac_role.go index 3084344d8..bd6f31d90 100644 --- a/state/rbac_role.go +++ b/state/rbac_role.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -50,7 +51,7 @@ func (k *RBACRolesCollection) Add(rbacRole RBACRole) error { _, err := getRBACRole(txn, searchBy...) if err == nil { return fmt.Errorf("inserting rbacRole %v: %w", rbacRole.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -66,7 +67,7 @@ func getRBACRole(txn *memdb.Txn, IDs ...string) (*RBACRole, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, rbacRoleTableName, []string{"name", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/route.go b/state/route.go index 1ed9478f8..dfd3f229e 100644 --- a/state/route.go +++ b/state/route.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -66,7 +67,7 @@ func (k *RoutesCollection) Add(route Route) error { _, err := getRoute(txn, searchBy...) if err == nil { return fmt.Errorf("inserting route %v: %w", route.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -82,7 +83,7 @@ func getRoute(txn *memdb.Txn, IDs ...string) (*Route, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, routeTableName, []string{"name", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/service.go b/state/service.go index a3845d227..5b6d05a83 100644 --- a/state/service.go +++ b/state/service.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -50,7 +51,7 @@ func (k *ServicesCollection) Add(service Service) error { _, err := getService(txn, searchBy...) if err == nil { return fmt.Errorf("inserting service %v: %w", service.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -66,7 +67,7 @@ func getService(txn *memdb.Txn, IDs ...string) (*Service, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, serviceTableName, []string{"name", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/service_package.go b/state/service_package.go index d11a00f0c..c10dcfd05 100644 --- a/state/service_package.go +++ b/state/service_package.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -49,7 +50,7 @@ func (k *ServicePackagesCollection) Add(servicePackage ServicePackage) error { _, err := getServicePackage(txn, searchBy...) if err == nil { return fmt.Errorf("inserting servicePackage %v: %w", servicePackage.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -65,7 +66,7 @@ func getServicePackage(txn *memdb.Txn, IDs ...string) (*ServicePackage, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, servicePackageTableName, []string{"name", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/service_version.go b/state/service_version.go index c5210ff73..af0b9810f 100644 --- a/state/service_version.go +++ b/state/service_version.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" "github.com/hashicorp/go-memdb" @@ -73,7 +74,7 @@ func (k *ServiceVersionsCollection) Add(serviceVersion ServiceVersion) error { _, err := getServiceVersion(txn, *serviceVersion.ServicePackage.ID, searchBy...) if err == nil { return fmt.Errorf("inserting serviceVersion %v: %w", serviceVersion.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/sni.go b/state/sni.go index ab1cc5616..280dae9be 100644 --- a/state/sni.go +++ b/state/sni.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -79,7 +80,7 @@ func (k *SNIsCollection) Add(sni SNI) error { _, err := getSNI(txn, searchBy...) if err == nil { return fmt.Errorf("inserting sni %v: %w", sni.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -95,7 +96,7 @@ func getSNI(txn *memdb.Txn, IDs ...string) (*SNI, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, sniTableName, []string{"name", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { diff --git a/state/target.go b/state/target.go index 17c92f896..b75f801d6 100644 --- a/state/target.go +++ b/state/target.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -73,7 +74,7 @@ func (k *TargetsCollection) Add(target Target) error { _, err := getTarget(txn, *target.Upstream.ID, searchBy...) if err == nil { return fmt.Errorf("inserting target %v: %w", target.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } diff --git a/state/upstream.go b/state/upstream.go index f045bf084..f22884191 100644 --- a/state/upstream.go +++ b/state/upstream.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -49,7 +50,7 @@ func (k *UpstreamsCollection) Add(upstream Upstream) error { _, err := getUpstream(txn, searchBy...) if err == nil { return fmt.Errorf("inserting upstream %v: %w", upstream.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -65,7 +66,7 @@ func getUpstream(txn *memdb.Txn, IDs ...string) (*Upstream, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, upstreamTableName, []string{"name", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { @@ -91,7 +92,7 @@ func (k *UpstreamsCollection) Get(nameOrID string) (*Upstream, error) { defer txn.Abort() upstream, err := getUpstream(txn, nameOrID) if err != nil { - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { return nil, ErrNotFound } return nil, err diff --git a/state/vault.go b/state/vault.go index 56d46c143..b0c1fa436 100644 --- a/state/vault.go +++ b/state/vault.go @@ -1,6 +1,7 @@ package state import ( + "errors" "fmt" memdb "github.com/hashicorp/go-memdb" @@ -48,7 +49,7 @@ func (k *VaultsCollection) Add(vault Vault) error { _, err := getVault(txn, searchBy...) if err == nil { return fmt.Errorf("inserting vault %v: %w", vault.Console(), ErrAlreadyExists) - } else if err != ErrNotFound { + } else if !errors.Is(err, ErrNotFound) { return err } @@ -64,7 +65,7 @@ func getVault(txn *memdb.Txn, IDs ...string) (*Vault, error) { for _, id := range IDs { res, err := multiIndexLookupUsingTxn(txn, vaultTableName, []string{"prefix", "id"}, id) - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { continue } if err != nil { @@ -90,7 +91,7 @@ func (k *VaultsCollection) Get(prefixOrID string) (*Vault, error) { defer txn.Abort() vault, err := getVault(txn, prefixOrID) if err != nil { - if err == ErrNotFound { + if errors.Is(err, ErrNotFound) { return nil, ErrNotFound } return nil, err diff --git a/types/aclgroup.go b/types/aclgroup.go index 9bcaa3212..2b5c20193 100644 --- a/types/aclgroup.go +++ b/types/aclgroup.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -119,7 +120,7 @@ func (d *aclGroupDiffer) Deletes(handler func(crud.Event) error) error { func (d *aclGroupDiffer) deleteACLGroup(aclGroup *state.ACLGroup) (*crud.Event, error) { // lookup by consumerID and Group _, err := d.targetState.ACLGroups.Get(*aclGroup.Consumer.ID, *aclGroup.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -157,7 +158,7 @@ func (d *aclGroupDiffer) createUpdateACLGroup(aclGroup *state.ACLGroup) (*crud.E aclGroup = &state.ACLGroup{ACLGroup: *aclGroup.DeepCopy()} currentACLGroup, err := d.currentState.ACLGroups.Get( *aclGroup.Consumer.ID, *aclGroup.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // aclGroup not present, create it return &crud.Event{ diff --git a/types/basicauth.go b/types/basicauth.go index 9d6a7bdaa..fbdaea24a 100644 --- a/types/basicauth.go +++ b/types/basicauth.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "sync" @@ -132,7 +133,7 @@ func (d *basicAuthDiffer) Deletes(handler func(crud.Event) error) error { func (d *basicAuthDiffer) deleteBasicAuth(basicAuth *state.BasicAuth) (*crud.Event, error) { d.warnBasicAuth() _, err := d.targetState.BasicAuths.Get(*basicAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -171,7 +172,7 @@ func (d *basicAuthDiffer) createUpdateBasicAuth(basicAuth *state.BasicAuth) (*cr d.warnBasicAuth() basicAuth = &state.BasicAuth{BasicAuth: *basicAuth.DeepCopy()} currentBasicAuth, err := d.currentState.BasicAuths.Get(*basicAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // basicAuth not present, create it return &crud.Event{ diff --git a/types/ca_cert.go b/types/ca_cert.go index 995cba144..62f09cd7a 100644 --- a/types/ca_cert.go +++ b/types/ca_cert.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -97,7 +98,7 @@ func (d *caCertificateDiffer) deleteCACertificate( caCert *state.CACertificate, ) (*crud.Event, error) { _, err := d.targetState.CACertificates.Get(*caCert.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -138,7 +139,7 @@ func (d *caCertificateDiffer) createUpdateCACertificate( caCertCopy := &state.CACertificate{CACertificate: *caCert.DeepCopy()} currentCACert, err := d.currentState.CACertificates.Get(*caCert.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // caCertificate not present, create it return &crud.Event{ Op: crud.Create, diff --git a/types/certificate.go b/types/certificate.go index ddbab616e..5349c7ad9 100644 --- a/types/certificate.go +++ b/types/certificate.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -96,7 +97,7 @@ func (d *certificateDiffer) deleteCertificate( certificate *state.Certificate, ) (*crud.Event, error) { _, err := d.targetState.Certificates.Get(*certificate.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -137,7 +138,7 @@ func (d *certificateDiffer) createUpdateCertificate( certificateCopy := &state.Certificate{Certificate: *certificate.DeepCopy()} currentCertificate, err := d.currentState.Certificates.Get(*certificate.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // certificate not present, create it return &crud.Event{ Op: crud.Create, diff --git a/types/consumer.go b/types/consumer.go index 6af6b2f8a..65a1092d2 100644 --- a/types/consumer.go +++ b/types/consumer.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -95,7 +96,7 @@ func (d *consumerDiffer) Deletes(handler func(crud.Event) error) error { func (d *consumerDiffer) deleteConsumer(consumer *state.Consumer) (*crud.Event, error) { _, err := d.targetState.Consumers.Get(*consumer.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -134,7 +135,7 @@ func (d *consumerDiffer) createUpdateConsumer(consumer *state.Consumer) (*crud.E consumerCopy := &state.Consumer{Consumer: *consumer.DeepCopy()} currentConsumer, err := d.currentState.Consumers.Get(*consumer.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // consumer not present, create it return &crud.Event{ Op: crud.Create, @@ -181,7 +182,7 @@ func (d *consumerDiffer) DuplicatesDeletes() ([]crud.Event, error) { func (d *consumerDiffer) deleteDuplicateConsumer(targetConsumer *state.Consumer) (*crud.Event, error) { currentConsumer, err := d.currentState.Consumers.Get(*targetConsumer.Username) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return nil, nil } if err != nil { diff --git a/types/consumer_group.go b/types/consumer_group.go index 9f88ee987..772a4546e 100644 --- a/types/consumer_group.go +++ b/types/consumer_group.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -116,7 +117,7 @@ func (d *consumerGroupDiffer) Deletes(handler func(crud.Event) error) error { func (d *consumerGroupDiffer) deleteConsumerGroup(consumerGroup *state.ConsumerGroup) (*crud.Event, error) { _, err := d.targetState.ConsumerGroups.Get(*consumerGroup.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: "consumer-group", @@ -157,7 +158,7 @@ func (d *consumerGroupDiffer) createUpdateConsumerGroup(consumerGroup *state.Con consumerGroupCopy := &state.ConsumerGroup{ConsumerGroup: *consumerGroup.DeepCopy()} currentconsumerGroup, err := d.currentState.ConsumerGroups.Get(*consumerGroup.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "consumer-group", diff --git a/types/consumer_group_consumer.go b/types/consumer_group_consumer.go index 23cdfc7a3..6daee6675 100644 --- a/types/consumer_group_consumer.go +++ b/types/consumer_group_consumer.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -152,7 +153,7 @@ func (d *consumerGroupConsumerDiffer) deleteConsumerGroupConsumer( _, err := d.targetState.ConsumerGroupConsumers.Get( *consumer.Consumer.Username, *consumer.ConsumerGroup.ID, ) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: "consumer-group-consumer", @@ -194,7 +195,7 @@ func (d *consumerGroupConsumerDiffer) createUpdateConsumerGroupConsumer( currentConsumer, err := d.currentState.ConsumerGroupConsumers.Get( *consumer.Consumer.Username, *consumer.ConsumerGroup.ID, ) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "consumer-group-consumer", diff --git a/types/consumer_group_plugin.go b/types/consumer_group_plugin.go index 4290e5c66..4d37c4703 100644 --- a/types/consumer_group_plugin.go +++ b/types/consumer_group_plugin.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -151,7 +152,7 @@ func (d *consumerGroupPluginDiffer) createUpdateConsumerGroupPlugin( currentPlugin, err := d.currentState.ConsumerGroupPlugins.Get( *plugin.Name, *plugin.ConsumerGroup.ID, ) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "consumer-group-plugin", diff --git a/types/document.go b/types/document.go index 3c75b5cff..8e4e5d180 100644 --- a/types/document.go +++ b/types/document.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -115,7 +116,7 @@ func (d *documentDiffer) Deletes(handler func(crud.Event) error) error { func (d *documentDiffer) deleteDocument(doc *state.Document) (*crud.Event, error) { _, err := d.targetState.Documents.GetByParent(doc.Parent, *doc.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: "document", @@ -154,7 +155,7 @@ func (d *documentDiffer) createUpdateDocument(doc *state.Document) (*crud.Event, dCopy := &state.Document{Document: *doc.ShallowCopy()} currentDoc, err := d.currentState.Documents.GetByParent(doc.Parent, *doc.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "document", diff --git a/types/hmacauth.go b/types/hmacauth.go index 97195498c..553a5500e 100644 --- a/types/hmacauth.go +++ b/types/hmacauth.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -118,7 +119,7 @@ func (d *hmacAuthDiffer) Deletes(handler func(crud.Event) error) error { func (d *hmacAuthDiffer) deleteHMACAuth(hmacAuth *state.HMACAuth) (*crud.Event, error) { _, err := d.targetState.HMACAuths.Get(*hmacAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -156,7 +157,7 @@ func (d *hmacAuthDiffer) CreateAndUpdates(handler func(crud.Event) error) error func (d *hmacAuthDiffer) createUpdateHMACAuth(hmacAuth *state.HMACAuth) (*crud.Event, error) { hmacAuth = &state.HMACAuth{HMACAuth: *hmacAuth.DeepCopy()} currentHMACAuth, err := d.currentState.HMACAuths.Get(*hmacAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // hmacAuth not present, create it return &crud.Event{ diff --git a/types/jwtauth.go b/types/jwtauth.go index 6b6018608..8ceba6ff7 100644 --- a/types/jwtauth.go +++ b/types/jwtauth.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -118,7 +119,7 @@ func (d *jwtAuthDiffer) Deletes(handler func(crud.Event) error) error { func (d *jwtAuthDiffer) deleteJWTAuth(jwtAuth *state.JWTAuth) (*crud.Event, error) { _, err := d.targetState.JWTAuths.Get(*jwtAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -155,7 +156,7 @@ func (d *jwtAuthDiffer) CreateAndUpdates(handler func(crud.Event) error) error { func (d *jwtAuthDiffer) createUpdateJWTAuth(jwtAuth *state.JWTAuth) (*crud.Event, error) { jwtAuth = &state.JWTAuth{JWTAuth: *jwtAuth.DeepCopy()} currentJWTAuth, err := d.currentState.JWTAuths.Get(*jwtAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // jwtAuth not present, create it return &crud.Event{ diff --git a/types/keyauth.go b/types/keyauth.go index 50ec81cd4..ad6ff00d8 100644 --- a/types/keyauth.go +++ b/types/keyauth.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -105,7 +106,7 @@ func (d *keyAuthDiffer) Deletes(handler func(crud.Event) error) error { func (d *keyAuthDiffer) deleteKeyAuth(keyAuth *state.KeyAuth) (*crud.Event, error) { _, err := d.targetState.KeyAuths.Get(*keyAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -142,7 +143,7 @@ func (d *keyAuthDiffer) CreateAndUpdates(handler func(crud.Event) error) error { func (d *keyAuthDiffer) createUpdateKeyAuth(keyAuth *state.KeyAuth) (*crud.Event, error) { keyAuth = &state.KeyAuth{KeyAuth: *keyAuth.DeepCopy()} currentKeyAuth, err := d.currentState.KeyAuths.Get(*keyAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // keyAuth not present, create it return &crud.Event{ diff --git a/types/mtlsauth.go b/types/mtlsauth.go index a7e73c136..4e4f3108c 100644 --- a/types/mtlsauth.go +++ b/types/mtlsauth.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -105,7 +106,7 @@ func (d *mtlsAuthDiffer) Deletes(handler func(crud.Event) error) error { func (d *mtlsAuthDiffer) deleteMTLSAuth(mtlsAuth *state.MTLSAuth) (*crud.Event, error) { _, err := d.targetState.MTLSAuths.Get(*mtlsAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -142,7 +143,7 @@ func (d *mtlsAuthDiffer) CreateAndUpdates(handler func(crud.Event) error) error func (d *mtlsAuthDiffer) createUpdateMTLSAuth(mtlsAuth *state.MTLSAuth) (*crud.Event, error) { mtlsAuth = &state.MTLSAuth{MTLSAuth: *mtlsAuth.DeepCopy()} currentMTLSAuth, err := d.currentState.MTLSAuths.Get(*mtlsAuth.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // mtlsAuth not present, create it return &crud.Event{ diff --git a/types/oauth2.go b/types/oauth2.go index 31a673321..9f447b867 100644 --- a/types/oauth2.go +++ b/types/oauth2.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -121,7 +122,7 @@ func (d *oauth2CredDiffer) deleteOauth2Cred(oauth2Cred *state.Oauth2Credential) *crud.Event, error, ) { _, err := d.targetState.Oauth2Creds.Get(*oauth2Cred.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -158,7 +159,7 @@ func (d *oauth2CredDiffer) CreateAndUpdates(handler func(crud.Event) error) erro func (d *oauth2CredDiffer) createUpdateOauth2Cred(oauth2Cred *state.Oauth2Credential) (*crud.Event, error) { oauth2Cred = &state.Oauth2Credential{Oauth2Credential: *oauth2Cred.DeepCopy()} currentOauth2Cred, err := d.currentState.Oauth2Creds.Get(*oauth2Cred.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // oauth2Cred not present, create it return &crud.Event{ diff --git a/types/plugin.go b/types/plugin.go index 4a3683553..44339c0f2 100644 --- a/types/plugin.go +++ b/types/plugin.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -113,7 +114,7 @@ func (d *pluginDiffer) deletePlugin(plugin *state.Plugin) (*crud.Event, error) { serviceID, routeID, consumerID := foreignNames(plugin) _, err := d.targetState.Plugins.GetByProp(name, serviceID, routeID, consumerID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -153,7 +154,7 @@ func (d *pluginDiffer) createUpdatePlugin(plugin *state.Plugin) (*crud.Event, er serviceID, routeID, consumerID := foreignNames(plugin) currentPlugin, err := d.currentState.Plugins.GetByProp(name, serviceID, routeID, consumerID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // plugin not present, create it return &crud.Event{ diff --git a/types/rbac_endpoint_permission.go b/types/rbac_endpoint_permission.go index 20f594b0a..e72aff227 100644 --- a/types/rbac_endpoint_permission.go +++ b/types/rbac_endpoint_permission.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "strings" @@ -107,7 +108,7 @@ func (d *rbacEndpointPermissionDiffer) deleteRBACEndpointPermission(ep *state.RB *crud.Event, error, ) { _, err := d.targetState.RBACEndpointPermissions.Get(ep.FriendlyName()) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -148,7 +149,7 @@ func (d *rbacEndpointPermissionDiffer) createUpdateRBACEndpointPermission(ep *st epCopy := &state.RBACEndpointPermission{RBACEndpointPermission: *ep.DeepCopy()} currentEp, err := d.currentState.RBACEndpointPermissions.Get(ep.FriendlyName()) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: d.kind, diff --git a/types/rbac_role.go b/types/rbac_role.go index c89ed76ac..dfede9a0d 100644 --- a/types/rbac_role.go +++ b/types/rbac_role.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -96,7 +97,7 @@ func (d *rbacRoleDiffer) Deletes(handler func(crud.Event) error) error { func (d *rbacRoleDiffer) deleteRBACRole(role *state.RBACRole) (*crud.Event, error) { _, err := d.targetState.RBACRoles.Get(*role.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -135,7 +136,7 @@ func (d *rbacRoleDiffer) createUpdateRBACRole(role *state.RBACRole) (*crud.Event roleCopy := &state.RBACRole{RBACRole: *role.DeepCopy()} currentRole, err := d.currentState.RBACRoles.Get(*role.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: d.kind, diff --git a/types/route.go b/types/route.go index b672fae75..97d493dc7 100644 --- a/types/route.go +++ b/types/route.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -102,7 +103,7 @@ func (d *routeDiffer) Deletes(handler func(crud.Event) error) error { func (d *routeDiffer) deleteRoute(route *state.Route) (*crud.Event, error) { _, err := d.targetState.Routes.Get(*route.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -140,7 +141,7 @@ func (d *routeDiffer) CreateAndUpdates(handler func(crud.Event) error) error { func (d *routeDiffer) createUpdateRoute(route *state.Route) (*crud.Event, error) { route = &state.Route{Route: *route.DeepCopy()} currentRoute, err := d.currentState.Routes.Get(*route.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // route not present, create it return &crud.Event{ @@ -188,7 +189,7 @@ func (d *routeDiffer) DuplicatesDeletes() ([]crud.Event, error) { func (d *routeDiffer) deleteDuplicateRoute(targetRoute *state.Route) (*crud.Event, error) { currentRoute, err := d.currentState.Routes.Get(*targetRoute.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return nil, nil } if err != nil { diff --git a/types/service.go b/types/service.go index b44c35553..5eea70833 100644 --- a/types/service.go +++ b/types/service.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -95,7 +96,7 @@ func (d *serviceDiffer) Deletes(handler func(crud.Event) error) error { func (d *serviceDiffer) deleteService(service *state.Service) (*crud.Event, error) { _, err := d.targetState.Services.Get(*service.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -134,7 +135,7 @@ func (d *serviceDiffer) createUpdateService(service *state.Service) (*crud.Event serviceCopy := &state.Service{Service: *service.DeepCopy()} currentService, err := d.currentState.Services.Get(*service.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "service", @@ -177,7 +178,7 @@ func (d *serviceDiffer) DuplicatesDeletes() ([]crud.Event, error) { func (d *serviceDiffer) deleteDuplicateService(targetService *state.Service) ([]crud.Event, error) { currentService, err := d.currentState.Services.Get(*targetService.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return nil, nil } if err != nil { diff --git a/types/service_package.go b/types/service_package.go index 7db06c3dd..c768d7ff6 100644 --- a/types/service_package.go +++ b/types/service_package.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -95,7 +96,7 @@ func (d *servicePackageDiffer) Deletes(handler func(crud.Event) error) error { func (d *servicePackageDiffer) deleteServicePackage(sp *state.ServicePackage) (*crud.Event, error) { _, err := d.targetState.ServicePackages.Get(*sp.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: "service-package", @@ -134,7 +135,7 @@ func (d *servicePackageDiffer) createUpdateServicePackage(sp *state.ServicePacka spCopy := &state.ServicePackage{ServicePackage: *sp.DeepCopy()} currentSP, err := d.currentState.ServicePackages.Get(*sp.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "service-package", diff --git a/types/service_version.go b/types/service_version.go index d67b24943..b6590135e 100644 --- a/types/service_version.go +++ b/types/service_version.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "reflect" @@ -167,7 +168,7 @@ func (d *serviceVersionDiffer) Deletes(handler func(crud.Event) error) error { func (d *serviceVersionDiffer) deleteServiceVersion(sv *state.ServiceVersion) (*crud.Event, error) { _, err := d.targetState.ServiceVersions.Get(*sv.ServicePackage.ID, *sv.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -206,7 +207,7 @@ func (d *serviceVersionDiffer) createUpdateServiceVersion(sv *state.ServiceVersi svCopy := &state.ServiceVersion{ServiceVersion: *sv.DeepCopy()} currentSV, err := d.currentState.ServiceVersions.Get(*sv.ServicePackage.ID, *sv.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: d.kind, diff --git a/types/sni.go b/types/sni.go index 3c5b89ab3..f5eb59a7d 100644 --- a/types/sni.go +++ b/types/sni.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -95,7 +96,7 @@ func (d *sniDiffer) Deletes(handler func(crud.Event) error) error { func (d *sniDiffer) deleteSNI(sni *state.SNI) (*crud.Event, error) { _, err := d.targetState.SNIs.Get(*sni.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -132,7 +133,7 @@ func (d *sniDiffer) CreateAndUpdates(handler func(crud.Event) error) error { func (d *sniDiffer) createUpdateSNI(sni *state.SNI) (*crud.Event, error) { sni = &state.SNI{SNI: *sni.DeepCopy()} currentSNI, err := d.currentState.SNIs.Get(*sni.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // sni not present, create it return &crud.Event{ diff --git a/types/target.go b/types/target.go index ed00722c8..28b7416f3 100644 --- a/types/target.go +++ b/types/target.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -102,7 +103,7 @@ func (d *targetDiffer) Deletes(handler func(crud.Event) error) error { func (d *targetDiffer) deleteTarget(target *state.Target) (*crud.Event, error) { _, err := d.targetState.Targets.Get(*target.Upstream.ID, *target.Target.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: d.kind, @@ -141,7 +142,7 @@ func (d *targetDiffer) createUpdateTarget(target *state.Target) (*crud.Event, er target = &state.Target{Target: *target.DeepCopy()} currentTarget, err := d.currentState.Targets.Get(*target.Upstream.ID, *target.Target.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { // target not present, create it return &crud.Event{ diff --git a/types/upstream.go b/types/upstream.go index b0343c3c6..2e888dda8 100644 --- a/types/upstream.go +++ b/types/upstream.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -95,7 +96,7 @@ func (d *upstreamDiffer) Deletes(handler func(crud.Event) error) error { func (d *upstreamDiffer) deleteUpstream(upstream *state.Upstream) (*crud.Event, error) { _, err := d.targetState.Upstreams.Get(*upstream.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: "upstream", @@ -136,7 +137,7 @@ func (d *upstreamDiffer) createUpdateUpstream(upstream *state.Upstream) (*crud.E upstreamCopy := &state.Upstream{Upstream: *upstream.DeepCopy()} currentUpstream, err := d.currentState.Upstreams.Get(*upstream.Name) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "upstream", diff --git a/types/vault.go b/types/vault.go index ab4d87f8c..e742934cc 100644 --- a/types/vault.go +++ b/types/vault.go @@ -2,6 +2,7 @@ package types import ( "context" + "errors" "fmt" "github.com/kong/deck/crud" @@ -97,7 +98,7 @@ func (d *vaultDiffer) Deletes(handler func(crud.Event) error) error { func (d *vaultDiffer) deleteVault(vault *state.Vault) (*crud.Event, error) { _, err := d.targetState.Vaults.Get(*vault.ID) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Delete, Kind: "vault", @@ -140,7 +141,7 @@ func (d *vaultDiffer) createUpdateVault(vault *state.Vault) (*crud.Event, vaultCopy := &state.Vault{Vault: *vault.DeepCopy()} currentVault, err := d.currentState.Vaults.Get(*vault.Prefix) - if err == state.ErrNotFound { + if errors.Is(err, state.ErrNotFound) { return &crud.Event{ Op: crud.Create, Kind: "vault", diff --git a/utils/defaulter.go b/utils/defaulter.go index ddb97daec..d506014d0 100644 --- a/utils/defaulter.go +++ b/utils/defaulter.go @@ -232,7 +232,7 @@ func (d *Defaulter) addEntityDefaults(entityType string, entity interface{}) err return nil } if err != nil { - return fmt.Errorf("retrieve schema for %v from Kong: %v", entityType, err) + return fmt.Errorf("retrieve schema for %v from Kong: %w", entityType, err) } return kong.FillEntityDefaults(entity, schema) } @@ -249,28 +249,28 @@ func getKongDefaulterWithClient(ctx context.Context, opts DefaulterOpts) (*Defau // fills defaults from Kong API if err := d.addEntityDefaults("services", d.service); err != nil { - return nil, fmt.Errorf("get defaults for services: %v", err) + return nil, fmt.Errorf("get defaults for services: %w", err) } if err := d.Register(d.service); err != nil { return nil, fmt.Errorf("registering service with defaulter: %w", err) } if err := d.addEntityDefaults("routes", d.route); err != nil { - return nil, fmt.Errorf("get defaults for routes: %v", err) + return nil, fmt.Errorf("get defaults for routes: %w", err) } if err := d.Register(d.route); err != nil { return nil, fmt.Errorf("registering route with defaulter: %w", err) } if err := d.addEntityDefaults("upstreams", d.upstream); err != nil { - return nil, fmt.Errorf("get defaults for upstreams: %v", err) + return nil, fmt.Errorf("get defaults for upstreams: %w", err) } if err := d.Register(d.upstream); err != nil { return nil, fmt.Errorf("registering upstream with defaulter: %w", err) } if err := d.addEntityDefaults("targets", d.target); err != nil { - return nil, fmt.Errorf("get defaults for targets: %v", err) + return nil, fmt.Errorf("get defaults for targets: %w", err) } if err := d.Register(d.target); err != nil { return nil, fmt.Errorf("registering target with defaulter: %w", err) @@ -289,7 +289,7 @@ func getKongDefaulterWithClient(ctx context.Context, opts DefaulterOpts) (*Defau } } else { if err := d.addEntityDefaults("consumer_group_plugins", d.consumerGroupPlugin); err != nil { - return nil, fmt.Errorf("get defaults for consumer-group-plugin: %v", err) + return nil, fmt.Errorf("get defaults for consumer-group-plugin: %w", err) } if err := d.Register(d.consumerGroupPlugin); err != nil { return nil, fmt.Errorf("registering consumer-group-plugin with defaulter: %w", err) @@ -374,7 +374,7 @@ func validateKongDefaults(defaults interface{}) error { err := checkEntityDefaults(object, restrictedFields) if err != nil { entityErr := fmt.Errorf( - "%s defaults %s", strings.ToLower(objectName), err) + "%s defaults %w", strings.ToLower(objectName), err) errs.Errors = append(errs.Errors, entityErr) } } diff --git a/validate/validate.go b/validate/validate.go index 939549229..ebca29813 100644 --- a/validate/validate.go +++ b/validate/validate.go @@ -2,6 +2,7 @@ package validate import ( "context" + "errors" "fmt" "net/http" "reflect" @@ -47,7 +48,7 @@ func (v ErrorsWrapper) Error() string { var errStr string for _, e := range v.Errors { errStr += e.Error() - if e != v.Errors[len(v.Errors)-1] { + if !errors.Is(e, v.Errors[len(v.Errors)-1]) { errStr += "\n" } }