diff --git a/CHANGELOG.md b/CHANGELOG.md index 620700628..9d1c095e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A) +- (Feature) Extract GRPC Server ## [1.2.37](https://github.com/arangodb/kube-arangodb/tree/1.2.37) (2024-01-22) - (Documentation) Improve documentation rendering for GitHub Pages diff --git a/cmd/admin.go b/cmd/admin.go index 5726f0757..decdc9f80 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -192,7 +192,7 @@ func getDeploymentAndCredentials(ctx context.Context, client, ok := kclient.GetDefaultFactory().Client() if !ok { - err = errors.Newf("Client not initialised") + err = errors.Errorf("Client not initialised") return } @@ -337,7 +337,7 @@ func getCACertificate(ctx context.Context, secrets secretv1.ReadInterface, name func getDeployment(ctx context.Context, namespace, deplName string) (api.ArangoDeployment, error) { client, ok := kclient.GetDefaultFactory().Client() if !ok { - return api.ArangoDeployment{}, errors.Newf("Client not initialised") + return api.ArangoDeployment{}, errors.Errorf("Client not initialised") } extCli := client.Arango() diff --git a/cmd/cmd.go b/cmd/cmd.go index da8c059c9..64dc4272f 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -33,7 +33,6 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/pkg/errors" "github.com/rs/zerolog" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -59,7 +58,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/server" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/constants" - utilsError "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" operatorHTTP "github.com/arangodb/kube-arangodb/pkg/util/http" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" @@ -437,7 +436,7 @@ func executeMain(cmd *cobra.Command, args []string) { if err != nil { logger.Err(err).Fatal("Failed to create API server") } - go utilsError.LogError(logger, "while running API server", apiServer.Run) + go errors.LogError(logger, "while running API server", apiServer.Run) } listenAddr := net.JoinHostPort(serverOptions.host, strconv.Itoa(serverOptions.port)) @@ -486,7 +485,7 @@ func executeMain(cmd *cobra.Command, args []string) { }); err != nil { logger.Err(err).Fatal("Failed to create HTTP server") } else { - go utilsError.LogError(logger, "error while starting server", svr.Run) + go errors.LogError(logger, "error while starting server", svr.Run) } // startChaos(context.Background(), cfg.KubeCli, cfg.Namespace, chaosLevel) diff --git a/cmd/crd.go b/cmd/crd.go index 6b95b94e7..a44329fbc 100644 --- a/cmd/crd.go +++ b/cmd/crd.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,11 +28,11 @@ import ( "strings" "time" - "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/arangodb/kube-arangodb/pkg/crd" "github.com/arangodb/kube-arangodb/pkg/crd/crds" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) diff --git a/cmd/init_container_version_check.go b/cmd/init_container_version_check.go index 35e71371a..2f0e1c7da 100644 --- a/cmd/init_container_version_check.go +++ b/cmd/init_container_version_check.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,9 +24,10 @@ import ( "encoding/json" "os" - "github.com/pkg/errors" "github.com/rs/zerolog/log" "github.com/spf13/cobra" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) const cmdVersionCheckInitContainersInvalidVersionExitCode = 11 diff --git a/cmd/lifecycle_probes.go b/cmd/lifecycle_probes.go index fa0f121c9..2dc5b3b2c 100644 --- a/cmd/lifecycle_probes.go +++ b/cmd/lifecycle_probes.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import ( "path" "strconv" - "github.com/pkg/errors" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -45,6 +44,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/resources" "github.com/arangodb/kube-arangodb/pkg/util" "github.com/arangodb/kube-arangodb/pkg/util/constants" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) const ( diff --git a/cmd/lifecycle_startup.go b/cmd/lifecycle_startup.go index a4e364f1d..788fe9534 100644 --- a/cmd/lifecycle_startup.go +++ b/cmd/lifecycle_startup.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ package cmd import ( - "errors" "fmt" "net/http" "time" @@ -29,6 +28,7 @@ import ( "github.com/spf13/cobra" shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) var cmdLifecycleStartup = &cobra.Command{ diff --git a/cmd/ml_storage.go b/cmd/ml_storage.go index 175aa75eb..50f808a14 100644 --- a/cmd/ml_storage.go +++ b/cmd/ml_storage.go @@ -25,11 +25,8 @@ import ( "github.com/rs/zerolog/log" "github.com/spf13/cobra" - "google.golang.org/grpc" - pbShutdown "github.com/arangodb/kube-arangodb/pkg/api/shutdown/v1" "github.com/arangodb/kube-arangodb/pkg/ml/storage" - "github.com/arangodb/kube-arangodb/pkg/util/probe" "github.com/arangodb/kube-arangodb/pkg/util/shutdown" "github.com/arangodb/kube-arangodb/pkg/util/svc" ) @@ -53,7 +50,7 @@ var ( } cmdMLStorageControllerOptions struct { - svc.GRPCConfig + Configuration svc.Configuration } ) @@ -62,8 +59,8 @@ func init() { cmdMLStorage.AddCommand(cmdMLStorageS3) f := cmdMLStorageS3.PersistentFlags() - f.StringVar(&cmdMLStorageControllerOptions.ListenAddress, "controller.address", "", "Address the GRPC controller service will listen on (IP:port)") - f.StringVar(&cmdMLStorageS3Options.ListenAddress, "server.address", "", "Address the GRPC service will listen on (IP:port)") + f.StringVar(&cmdMLStorageControllerOptions.Configuration.Address, "controller.address", "", "Address the GRPC controller service will listen on (IP:port)") + f.StringVar(&cmdMLStorageS3Options.Configuration.Address, "server.address", "", "Address the GRPC service will listen on (IP:port)") f.StringVar(&cmdMLStorageS3Options.S3.Endpoint, "s3.endpoint", "", "Endpoint of S3 API implementation") f.StringVar(&cmdMLStorageS3Options.S3.CACrtFile, "s3.ca-crt", "", "Path to file containing CA certificate to validate endpoint connection") @@ -84,16 +81,18 @@ func cmdMLStorageS3Run(cmd *cobra.Command, _ []string) { } func cmdMLStorageS3RunE(_ *cobra.Command) error { + health := svc.NewHealthService(cmdMLStorageControllerOptions.Configuration, svc.Readiness, shutdown.NewGlobalShutdownServer()) + + health.Start(shutdown.Context()) + storageService, err := storage.NewService(shutdown.Context(), storage.StorageTypeS3Proxy, cmdMLStorageS3Options.ServiceConfig) if err != nil { return err } - healthService := probe.NewHealthService() + svc := svc.NewService(cmdMLStorageS3Options.Configuration, storageService) - controllerService := svc.NewGRPC(cmdMLStorageControllerOptions.GRPCConfig, func(server *grpc.Server) { - pbShutdown.RegisterShutdownServer(server, shutdown.NewShutdownableShutdownServer()) - healthService.Register(server) - }) - return svc.RunServices(shutdown.Context(), healthService, storageService, controllerService) + svcRun := svc.StartWithHealth(shutdown.Context(), health) + + return svcRun.Wait() } diff --git a/cmd/uuid.go b/cmd/uuid.go index 3bc60ede2..a7d960362 100644 --- a/cmd/uuid.go +++ b/cmd/uuid.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,9 +25,10 @@ import ( "os" "strings" - "github.com/pkg/errors" "github.com/rs/zerolog/log" "github.com/spf13/cobra" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) type cmdUUIDInputStruct struct { diff --git a/internal/md/sections.go b/internal/md/sections.go index edbfb2b1a..ad46ada8a 100644 --- a/internal/md/sections.go +++ b/internal/md/sections.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -78,7 +78,7 @@ func ReplaceSection(in, replace, section string) (string, error) { endID := strings.Index(in, end) if endID == -1 { - return "", errors.Newf("END_INJECT sections is missing for section %s. Note that newline is required at the end and before tag", section) + return "", errors.Errorf("END_INJECT sections is missing for section %s. Note that newline is required at the end and before tag", section) } if strings.HasSuffix(replace, "\n\n") { diff --git a/internal/md/table.go b/internal/md/table.go index d4011cc7a..854b5c3b6 100644 --- a/internal/md/table.go +++ b/internal/md/table.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ func (t *table) AddRow(in map[Column]string) error { for k, v := range in { if _, ok := t.columns.Get(k.ID()); !ok { - return errors.Newf("Column not found") + return errors.Errorf("Column not found") } r[k.ID()] = v diff --git a/pkg/api/tls.go b/pkg/api/tls.go index 23c3c0289..fa45b37fd 100644 --- a/pkg/api/tls.go +++ b/pkg/api/tls.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,11 +56,11 @@ func loadOrSelfSignCertificate(cli typedCore.CoreV1Interface, cfg ServerConfig) } certBytes, found := s.Data[core.TLSCertKey] if !found { - return "", "", errors.Newf("No %s found in secret %s", core.TLSCertKey, cfg.TLSSecretName) + return "", "", errors.Errorf("No %s found in secret %s", core.TLSCertKey, cfg.TLSSecretName) } keyBytes, found := s.Data[core.TLSPrivateKeyKey] if !found { - return "", "", errors.Newf("No %s found in secret %s", core.TLSPrivateKeyKey, cfg.TLSSecretName) + return "", "", errors.Errorf("No %s found in secret %s", core.TLSPrivateKeyKey, cfg.TLSSecretName) } return string(certBytes), string(keyBytes), nil } diff --git a/pkg/apis/apps/v1/job_validate.go b/pkg/apis/apps/v1/job_validate.go index 6df53ad02..4509ddc37 100644 --- a/pkg/apis/apps/v1/job_validate.go +++ b/pkg/apis/apps/v1/job_validate.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -32,11 +32,11 @@ func (a *ArangoJob) Validate() error { func (a *ArangoJobSpec) Validate() error { if a.ArangoDeploymentName == "" { - return errors.Newf("deployment name can not be empty") + return errors.Errorf("deployment name can not be empty") } if a.JobTemplate == nil { - return errors.Newf("jobTemplate name can not be empty") + return errors.Errorf("jobTemplate name can not be empty") } return nil diff --git a/pkg/apis/backup/v1/backup_policy_validate.go b/pkg/apis/backup/v1/backup_policy_validate.go index c933acfeb..ba39037d4 100644 --- a/pkg/apis/backup/v1/backup_policy_validate.go +++ b/pkg/apis/backup/v1/backup_policy_validate.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,9 +38,9 @@ func (a *ArangoBackupPolicy) Validate() error { func (a *ArangoBackupPolicySpec) Validate() error { if expr, err := cron.ParseStandard(a.Schedule); err != nil { - return errors.Newf("error while parsing expr: %s", err.Error()) + return errors.Errorf("error while parsing expr: %s", err.Error()) } else if expr.Next(time.Now()).IsZero() { - return errors.Newf("invalid schedule format") + return errors.Errorf("invalid schedule format") } return nil diff --git a/pkg/apis/backup/v1/backup_validate.go b/pkg/apis/backup/v1/backup_validate.go index 65bf1efe1..94b39fbbc 100644 --- a/pkg/apis/backup/v1/backup_validate.go +++ b/pkg/apis/backup/v1/backup_validate.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ func (a *ArangoBackup) Validate() error { func (a *ArangoBackupSpec) Validate() error { if a.Deployment.Name == "" { - return errors.Newf("deployment name can not be empty") + return errors.Errorf("deployment name can not be empty") } if a.Download != nil { @@ -58,7 +58,7 @@ func (a *ArangoBackupSpec) Validate() error { func (a *ArangoBackupSpecOperation) Validate() error { if a.RepositoryURL == "" { - return errors.Newf("RepositoryURL can not be empty") + return errors.Errorf("RepositoryURL can not be empty") } return nil @@ -66,7 +66,7 @@ func (a *ArangoBackupSpecOperation) Validate() error { func (a *ArangoBackupSpecDownload) Validate() error { if a.ID == "" { - return errors.Newf("ID can not be empty") + return errors.Errorf("ID can not be empty") } return a.ArangoBackupSpecOperation.Validate() diff --git a/pkg/apis/deployment/v1/architecture.go b/pkg/apis/deployment/v1/architecture.go index 3c32d9596..033edf332 100644 --- a/pkg/apis/deployment/v1/architecture.go +++ b/pkg/apis/deployment/v1/architecture.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,10 +23,10 @@ package v1 import ( "runtime" - "github.com/pkg/errors" core "k8s.io/api/core/v1" shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) // ArangoDeploymentArchitecture defines the list of supported architectures. diff --git a/pkg/apis/deployment/v1/bootstrap.go b/pkg/apis/deployment/v1/bootstrap.go index 715c96c21..09199377b 100644 --- a/pkg/apis/deployment/v1/bootstrap.go +++ b/pkg/apis/deployment/v1/bootstrap.go @@ -92,12 +92,12 @@ func (b *BootstrapSpec) Validate() error { for username, secretname := range b.PasswordSecretNames { // Remove this restriction as soon as we can bootstrap databases if username != UserNameRoot { - return errors.Newf("only username `root` allowed in passwordSecretNames") + return errors.Errorf("only username `root` allowed in passwordSecretNames") } if secretname.IsNone() { if username != UserNameRoot { - return errors.Newf("magic value None not allowed for %s", username) + return errors.Errorf("magic value None not allowed for %s", username) } } else { if err := shared.ValidateResourceName(string(secretname)); err != nil { diff --git a/pkg/apis/deployment/v1/cluster_synchronization_spec.go b/pkg/apis/deployment/v1/cluster_synchronization_spec.go index 3539bbf49..3ad782755 100644 --- a/pkg/apis/deployment/v1/cluster_synchronization_spec.go +++ b/pkg/apis/deployment/v1/cluster_synchronization_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,9 +21,8 @@ package v1 import ( - "github.com/pkg/errors" - shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) type ArangoClusterSynchronizationSpec struct { diff --git a/pkg/apis/deployment/v1/cluster_synchronization_spec_test.go b/pkg/apis/deployment/v1/cluster_synchronization_spec_test.go index 8d97e44b8..d49fc391c 100644 --- a/pkg/apis/deployment/v1/cluster_synchronization_spec_test.go +++ b/pkg/apis/deployment/v1/cluster_synchronization_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,8 +23,9 @@ package v1 import ( "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/require" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) func Test_ACS_KubeConfigSpec(t *testing.T) { diff --git a/pkg/apis/deployment/v1/deployment_spec_image.go b/pkg/apis/deployment/v1/deployment_spec_image.go index bbe117d42..3bbb334b6 100644 --- a/pkg/apis/deployment/v1/deployment_spec_image.go +++ b/pkg/apis/deployment/v1/deployment_spec_image.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ func (d DeploymentImageDiscoveryModeSpec) Validate() error { case DeploymentImageDiscoveryDirectMode: return nil default: - return errors.Newf("mode %s is not supported", d) + return errors.Errorf("mode %s is not supported", d) } } diff --git a/pkg/apis/deployment/v1/external_access_spec.go b/pkg/apis/deployment/v1/external_access_spec.go index 67702a5d9..2b0bec774 100644 --- a/pkg/apis/deployment/v1/external_access_spec.go +++ b/pkg/apis/deployment/v1/external_access_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -100,12 +100,12 @@ func (s ExternalAccessSpec) Validate() error { if s.AdvertisedEndpoint != nil { ep := s.GetAdvertisedEndpoint() if _, err := url.Parse(ep); err != nil { - return errors.WithStack(errors.Newf("Failed to parse advertised endpoint '%s': %s", ep, err)) + return errors.WithStack(errors.Errorf("Failed to parse advertised endpoint '%s': %s", ep, err)) } } for _, x := range s.LoadBalancerSourceRanges { if _, _, err := net.ParseCIDR(x); err != nil { - return errors.WithStack(errors.Newf("Failed to parse loadbalancer source range '%s': %s", x, err)) + return errors.WithStack(errors.Errorf("Failed to parse loadbalancer source range '%s': %s", x, err)) } } return nil diff --git a/pkg/apis/deployment/v1/member_status_list.go b/pkg/apis/deployment/v1/member_status_list.go index 2c7d19a32..f158dbc05 100644 --- a/pkg/apis/deployment/v1/member_status_list.go +++ b/pkg/apis/deployment/v1/member_status_list.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -183,7 +183,7 @@ func (l MemberStatusList) SelectMemberToRemove(selectors ...MemberToRemoveSelect if member, ok := l.ElementByID(m); ok { return member, nil } else { - return MemberStatus{}, errors.Newf("Unable to find member with id %s", m) + return MemberStatus{}, errors.Errorf("Unable to find member with id %s", m) } } } diff --git a/pkg/apis/deployment/v1/server_group_index_method.go b/pkg/apis/deployment/v1/server_group_index_method.go index 58d64d274..e9b555e90 100644 --- a/pkg/apis/deployment/v1/server_group_index_method.go +++ b/pkg/apis/deployment/v1/server_group_index_method.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ func (s *ServerGroupIndexMethod) Validate() error { case ServerGroupIndexMethodRandom, ServerGroupIndexMethodOrdered: return nil default: - return errors.Newf("Unknown IndexMethod %s", v) + return errors.Errorf("Unknown IndexMethod %s", v) } } diff --git a/pkg/apis/deployment/v1/server_group_init_containers.go b/pkg/apis/deployment/v1/server_group_init_containers.go index 26b216865..abf2b3327 100644 --- a/pkg/apis/deployment/v1/server_group_init_containers.go +++ b/pkg/apis/deployment/v1/server_group_init_containers.go @@ -48,7 +48,7 @@ func IsReservedServerGroupInitContainerName(name string) bool { func ValidateServerGroupInitContainerName(name string) error { if IsReservedServerGroupInitContainerName(name) { - return errors.Newf("InitContainer name %s is restricted", name) + return errors.Errorf("InitContainer name %s is restricted", name) } return sharedApi.AsKubernetesResourceName(&name).Validate() @@ -73,7 +73,7 @@ func (s *ServerGroupInitContainerMode) Validate() error { case ServerGroupInitContainerIgnoreMode, ServerGroupInitContainerUpdateMode: return nil default: - return errors.Newf("Unknown serverGroupInitContainerMode %s", v) + return errors.Errorf("Unknown serverGroupInitContainerMode %s", v) } } diff --git a/pkg/apis/deployment/v1/server_group_spec.go b/pkg/apis/deployment/v1/server_group_spec.go index c4062e559..5d20fd1e2 100644 --- a/pkg/apis/deployment/v1/server_group_spec.go +++ b/pkg/apis/deployment/v1/server_group_spec.go @@ -563,14 +563,14 @@ func (s *ServerGroupSpec) validateVolumes() error { for _, mount := range s.VolumeMounts { if _, ok := volumes[mount.Name]; !ok { - return errors.Newf("Volume %s is not defined, but required by mount", mount.Name) + return errors.Errorf("Volume %s is not defined, but required by mount", mount.Name) } } for _, container := range s.InitContainers.GetContainers() { for _, mount := range container.VolumeMounts { if _, ok := volumes[mount.Name]; !ok { - return errors.Newf("Volume %s is not defined, but required by mount in init container %s", mount.Name, container.Name) + return errors.Errorf("Volume %s is not defined, but required by mount in init container %s", mount.Name, container.Name) } } } @@ -578,7 +578,7 @@ func (s *ServerGroupSpec) validateVolumes() error { for _, container := range s.Sidecars { for _, mount := range s.VolumeMounts { if _, ok := volumes[mount.Name]; !ok { - return errors.Newf("Volume %s is not defined, but required by mount in sidecar %s", mount.Name, container.Name) + return errors.Errorf("Volume %s is not defined, but required by mount in sidecar %s", mount.Name, container.Name) } } } diff --git a/pkg/apis/deployment/v1/server_group_spec_port_proto.go b/pkg/apis/deployment/v1/server_group_spec_port_proto.go index 2a6f8ae22..e4efc1d52 100644 --- a/pkg/apis/deployment/v1/server_group_spec_port_proto.go +++ b/pkg/apis/deployment/v1/server_group_spec_port_proto.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ package v1 -import "github.com/pkg/errors" +import "github.com/arangodb/kube-arangodb/pkg/util/errors" // ServerGroupPortProtocol define supported protocols of listeners type ServerGroupPortProtocol string diff --git a/pkg/apis/deployment/v1/server_group_volume.go b/pkg/apis/deployment/v1/server_group_volume.go index d80b64375..7c9110686 100644 --- a/pkg/apis/deployment/v1/server_group_volume.go +++ b/pkg/apis/deployment/v1/server_group_volume.go @@ -87,14 +87,14 @@ func (s ServerGroupSpecVolumes) Validate() error { for volumeName, count := range mappedVolumes { if IsRestrictedVolumeName(volumeName) { - validationErrors = append(validationErrors, errors.Newf("volume with name %s is restricted", volumeName)) + validationErrors = append(validationErrors, errors.Errorf("volume with name %s is restricted", volumeName)) } if count == 1 { continue } - validationErrors = append(validationErrors, errors.Newf("volume with name %s defined more than once: %d", volumeName, count)) + validationErrors = append(validationErrors, errors.Errorf("volume with name %s defined more than once: %d", volumeName, count)) } return shared.WithErrors(validationErrors...) @@ -202,11 +202,11 @@ func (s *ServerGroupSpecVolume) validate() error { count := s.notNilFields() if count == 0 { - return errors.Newf("at least one option need to be defined: secret, configMap or emptyDir") + return errors.Errorf("at least one option need to be defined: secret, configMap or emptyDir") } if count > 1 { - return errors.Newf("only one option can be defined: secret, configMap or emptyDir") + return errors.Errorf("only one option can be defined: secret, configMap or emptyDir") } return nil diff --git a/pkg/apis/deployment/v1/sync_external_access_spec.go b/pkg/apis/deployment/v1/sync_external_access_spec.go index 67917d4a2..686163cdd 100644 --- a/pkg/apis/deployment/v1/sync_external_access_spec.go +++ b/pkg/apis/deployment/v1/sync_external_access_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -77,19 +77,19 @@ func (s SyncExternalAccessSpec) Validate() error { } for _, ep := range s.MasterEndpoint { if u, err := url.Parse(ep); err != nil { - return errors.WithStack(errors.Newf("Failed to parse master endpoint '%s': %s", ep, err)) + return errors.WithStack(errors.Errorf("Failed to parse master endpoint '%s': %s", ep, err)) } else { if u.Scheme != "http" && u.Scheme != "https" { - return errors.WithStack(errors.Newf("Invalid scheme '%s' in master endpoint '%s'", u.Scheme, ep)) + return errors.WithStack(errors.Errorf("Invalid scheme '%s' in master endpoint '%s'", u.Scheme, ep)) } if u.Host == "" { - return errors.WithStack(errors.Newf("Missing host in master endpoint '%s'", ep)) + return errors.WithStack(errors.Errorf("Missing host in master endpoint '%s'", ep)) } } } for _, name := range s.AccessPackageSecretNames { if err := shared.ValidateResourceName(name); err != nil { - return errors.WithStack(errors.Newf("Invalid name '%s' in accessPackageSecretNames: %s", name, err)) + return errors.WithStack(errors.Errorf("Invalid name '%s' in accessPackageSecretNames: %s", name, err)) } } return nil diff --git a/pkg/apis/deployment/v1/tls_sni_spec.go b/pkg/apis/deployment/v1/tls_sni_spec.go index 911857253..4e8fc1a48 100644 --- a/pkg/apis/deployment/v1/tls_sni_spec.go +++ b/pkg/apis/deployment/v1/tls_sni_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ func (s TLSSNISpec) Validate() error { for _, value := range values { if _, exists := mapped[value]; exists { - return errors.Newf("sni for host %s is already defined", value) + return errors.Errorf("sni for host %s is already defined", value) } // Mark value as existing diff --git a/pkg/apis/deployment/v1/tls_spec.go b/pkg/apis/deployment/v1/tls_spec.go index 4bca0053f..8255a9a9a 100644 --- a/pkg/apis/deployment/v1/tls_spec.go +++ b/pkg/apis/deployment/v1/tls_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -125,7 +125,7 @@ func (s TLSSpec) GetParsedAltNames() (dnsNames, ipAddresses, emailAddresses []st } else if validation.IsValidEmailAddress(name) { emailAddresses = append(emailAddresses, name) } else { - return nil, nil, nil, errors.WithStack(errors.Newf("'%s' is not a valid alternate name", name)) + return nil, nil, nil, errors.WithStack(errors.Errorf("'%s' is not a valid alternate name", name)) } } return dnsNames, ipAddresses, emailAddresses, nil diff --git a/pkg/apis/deployment/v1/version.go b/pkg/apis/deployment/v1/version.go index 909ccac37..18e31a226 100644 --- a/pkg/apis/deployment/v1/version.go +++ b/pkg/apis/deployment/v1/version.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import ( "strconv" "strings" - "github.com/pkg/errors" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) var _ json.Marshaler = Version{} diff --git a/pkg/apis/deployment/v2alpha1/architecture.go b/pkg/apis/deployment/v2alpha1/architecture.go index 3d62dec2a..2dc02a6eb 100644 --- a/pkg/apis/deployment/v2alpha1/architecture.go +++ b/pkg/apis/deployment/v2alpha1/architecture.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,10 +23,10 @@ package v2alpha1 import ( "runtime" - "github.com/pkg/errors" core "k8s.io/api/core/v1" shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) // ArangoDeploymentArchitecture defines the list of supported architectures. diff --git a/pkg/apis/deployment/v2alpha1/bootstrap.go b/pkg/apis/deployment/v2alpha1/bootstrap.go index 2ebed9bc6..d2a637553 100644 --- a/pkg/apis/deployment/v2alpha1/bootstrap.go +++ b/pkg/apis/deployment/v2alpha1/bootstrap.go @@ -92,12 +92,12 @@ func (b *BootstrapSpec) Validate() error { for username, secretname := range b.PasswordSecretNames { // Remove this restriction as soon as we can bootstrap databases if username != UserNameRoot { - return errors.Newf("only username `root` allowed in passwordSecretNames") + return errors.Errorf("only username `root` allowed in passwordSecretNames") } if secretname.IsNone() { if username != UserNameRoot { - return errors.Newf("magic value None not allowed for %s", username) + return errors.Errorf("magic value None not allowed for %s", username) } } else { if err := shared.ValidateResourceName(string(secretname)); err != nil { diff --git a/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec.go b/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec.go index b76fb084a..0d8296d16 100644 --- a/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec.go +++ b/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,9 +21,8 @@ package v2alpha1 import ( - "github.com/pkg/errors" - shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) type ArangoClusterSynchronizationSpec struct { diff --git a/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec_test.go b/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec_test.go index a7ec8be97..ede8ac9b3 100644 --- a/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/cluster_synchronization_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,8 +23,9 @@ package v2alpha1 import ( "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/require" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) func Test_ACS_KubeConfigSpec(t *testing.T) { diff --git a/pkg/apis/deployment/v2alpha1/deployment_spec_image.go b/pkg/apis/deployment/v2alpha1/deployment_spec_image.go index 502f78eee..3819cab52 100644 --- a/pkg/apis/deployment/v2alpha1/deployment_spec_image.go +++ b/pkg/apis/deployment/v2alpha1/deployment_spec_image.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ func (d DeploymentImageDiscoveryModeSpec) Validate() error { case DeploymentImageDiscoveryDirectMode: return nil default: - return errors.Newf("mode %s is not supported", d) + return errors.Errorf("mode %s is not supported", d) } } diff --git a/pkg/apis/deployment/v2alpha1/external_access_spec.go b/pkg/apis/deployment/v2alpha1/external_access_spec.go index d3e9a8eb5..92fa5fc8a 100644 --- a/pkg/apis/deployment/v2alpha1/external_access_spec.go +++ b/pkg/apis/deployment/v2alpha1/external_access_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -100,12 +100,12 @@ func (s ExternalAccessSpec) Validate() error { if s.AdvertisedEndpoint != nil { ep := s.GetAdvertisedEndpoint() if _, err := url.Parse(ep); err != nil { - return errors.WithStack(errors.Newf("Failed to parse advertised endpoint '%s': %s", ep, err)) + return errors.WithStack(errors.Errorf("Failed to parse advertised endpoint '%s': %s", ep, err)) } } for _, x := range s.LoadBalancerSourceRanges { if _, _, err := net.ParseCIDR(x); err != nil { - return errors.WithStack(errors.Newf("Failed to parse loadbalancer source range '%s': %s", x, err)) + return errors.WithStack(errors.Errorf("Failed to parse loadbalancer source range '%s': %s", x, err)) } } return nil diff --git a/pkg/apis/deployment/v2alpha1/member_status_list.go b/pkg/apis/deployment/v2alpha1/member_status_list.go index ed9e21311..9c04e5e96 100644 --- a/pkg/apis/deployment/v2alpha1/member_status_list.go +++ b/pkg/apis/deployment/v2alpha1/member_status_list.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -183,7 +183,7 @@ func (l MemberStatusList) SelectMemberToRemove(selectors ...MemberToRemoveSelect if member, ok := l.ElementByID(m); ok { return member, nil } else { - return MemberStatus{}, errors.Newf("Unable to find member with id %s", m) + return MemberStatus{}, errors.Errorf("Unable to find member with id %s", m) } } } diff --git a/pkg/apis/deployment/v2alpha1/server_group_index_method.go b/pkg/apis/deployment/v2alpha1/server_group_index_method.go index 44eb59b2e..3b8b92867 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_index_method.go +++ b/pkg/apis/deployment/v2alpha1/server_group_index_method.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ func (s *ServerGroupIndexMethod) Validate() error { case ServerGroupIndexMethodRandom, ServerGroupIndexMethodOrdered: return nil default: - return errors.Newf("Unknown IndexMethod %s", v) + return errors.Errorf("Unknown IndexMethod %s", v) } } diff --git a/pkg/apis/deployment/v2alpha1/server_group_init_containers.go b/pkg/apis/deployment/v2alpha1/server_group_init_containers.go index 17fe3f173..9d95e9e81 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_init_containers.go +++ b/pkg/apis/deployment/v2alpha1/server_group_init_containers.go @@ -48,7 +48,7 @@ func IsReservedServerGroupInitContainerName(name string) bool { func ValidateServerGroupInitContainerName(name string) error { if IsReservedServerGroupInitContainerName(name) { - return errors.Newf("InitContainer name %s is restricted", name) + return errors.Errorf("InitContainer name %s is restricted", name) } return sharedApi.AsKubernetesResourceName(&name).Validate() @@ -73,7 +73,7 @@ func (s *ServerGroupInitContainerMode) Validate() error { case ServerGroupInitContainerIgnoreMode, ServerGroupInitContainerUpdateMode: return nil default: - return errors.Newf("Unknown serverGroupInitContainerMode %s", v) + return errors.Errorf("Unknown serverGroupInitContainerMode %s", v) } } diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec.go b/pkg/apis/deployment/v2alpha1/server_group_spec.go index 78f1e0278..6298bb70a 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec.go @@ -563,14 +563,14 @@ func (s *ServerGroupSpec) validateVolumes() error { for _, mount := range s.VolumeMounts { if _, ok := volumes[mount.Name]; !ok { - return errors.Newf("Volume %s is not defined, but required by mount", mount.Name) + return errors.Errorf("Volume %s is not defined, but required by mount", mount.Name) } } for _, container := range s.InitContainers.GetContainers() { for _, mount := range container.VolumeMounts { if _, ok := volumes[mount.Name]; !ok { - return errors.Newf("Volume %s is not defined, but required by mount in init container %s", mount.Name, container.Name) + return errors.Errorf("Volume %s is not defined, but required by mount in init container %s", mount.Name, container.Name) } } } @@ -578,7 +578,7 @@ func (s *ServerGroupSpec) validateVolumes() error { for _, container := range s.Sidecars { for _, mount := range s.VolumeMounts { if _, ok := volumes[mount.Name]; !ok { - return errors.Newf("Volume %s is not defined, but required by mount in sidecar %s", mount.Name, container.Name) + return errors.Errorf("Volume %s is not defined, but required by mount in sidecar %s", mount.Name, container.Name) } } } diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec_port_proto.go b/pkg/apis/deployment/v2alpha1/server_group_spec_port_proto.go index 88bb1c6fc..4a4cbb8c1 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec_port_proto.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec_port_proto.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ package v2alpha1 -import "github.com/pkg/errors" +import "github.com/arangodb/kube-arangodb/pkg/util/errors" // ServerGroupPortProtocol define supported protocols of listeners type ServerGroupPortProtocol string diff --git a/pkg/apis/deployment/v2alpha1/server_group_volume.go b/pkg/apis/deployment/v2alpha1/server_group_volume.go index 5491b678e..a26f15b3b 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_volume.go +++ b/pkg/apis/deployment/v2alpha1/server_group_volume.go @@ -87,14 +87,14 @@ func (s ServerGroupSpecVolumes) Validate() error { for volumeName, count := range mappedVolumes { if IsRestrictedVolumeName(volumeName) { - validationErrors = append(validationErrors, errors.Newf("volume with name %s is restricted", volumeName)) + validationErrors = append(validationErrors, errors.Errorf("volume with name %s is restricted", volumeName)) } if count == 1 { continue } - validationErrors = append(validationErrors, errors.Newf("volume with name %s defined more than once: %d", volumeName, count)) + validationErrors = append(validationErrors, errors.Errorf("volume with name %s defined more than once: %d", volumeName, count)) } return shared.WithErrors(validationErrors...) @@ -202,11 +202,11 @@ func (s *ServerGroupSpecVolume) validate() error { count := s.notNilFields() if count == 0 { - return errors.Newf("at least one option need to be defined: secret, configMap or emptyDir") + return errors.Errorf("at least one option need to be defined: secret, configMap or emptyDir") } if count > 1 { - return errors.Newf("only one option can be defined: secret, configMap or emptyDir") + return errors.Errorf("only one option can be defined: secret, configMap or emptyDir") } return nil diff --git a/pkg/apis/deployment/v2alpha1/sync_external_access_spec.go b/pkg/apis/deployment/v2alpha1/sync_external_access_spec.go index 414492720..84cbcac6e 100644 --- a/pkg/apis/deployment/v2alpha1/sync_external_access_spec.go +++ b/pkg/apis/deployment/v2alpha1/sync_external_access_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -77,19 +77,19 @@ func (s SyncExternalAccessSpec) Validate() error { } for _, ep := range s.MasterEndpoint { if u, err := url.Parse(ep); err != nil { - return errors.WithStack(errors.Newf("Failed to parse master endpoint '%s': %s", ep, err)) + return errors.WithStack(errors.Errorf("Failed to parse master endpoint '%s': %s", ep, err)) } else { if u.Scheme != "http" && u.Scheme != "https" { - return errors.WithStack(errors.Newf("Invalid scheme '%s' in master endpoint '%s'", u.Scheme, ep)) + return errors.WithStack(errors.Errorf("Invalid scheme '%s' in master endpoint '%s'", u.Scheme, ep)) } if u.Host == "" { - return errors.WithStack(errors.Newf("Missing host in master endpoint '%s'", ep)) + return errors.WithStack(errors.Errorf("Missing host in master endpoint '%s'", ep)) } } } for _, name := range s.AccessPackageSecretNames { if err := shared.ValidateResourceName(name); err != nil { - return errors.WithStack(errors.Newf("Invalid name '%s' in accessPackageSecretNames: %s", name, err)) + return errors.WithStack(errors.Errorf("Invalid name '%s' in accessPackageSecretNames: %s", name, err)) } } return nil diff --git a/pkg/apis/deployment/v2alpha1/tls_sni_spec.go b/pkg/apis/deployment/v2alpha1/tls_sni_spec.go index 9dc51bbd7..dc016a976 100644 --- a/pkg/apis/deployment/v2alpha1/tls_sni_spec.go +++ b/pkg/apis/deployment/v2alpha1/tls_sni_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ func (s TLSSNISpec) Validate() error { for _, value := range values { if _, exists := mapped[value]; exists { - return errors.Newf("sni for host %s is already defined", value) + return errors.Errorf("sni for host %s is already defined", value) } // Mark value as existing diff --git a/pkg/apis/deployment/v2alpha1/tls_spec.go b/pkg/apis/deployment/v2alpha1/tls_spec.go index a8a3914b7..0b055b127 100644 --- a/pkg/apis/deployment/v2alpha1/tls_spec.go +++ b/pkg/apis/deployment/v2alpha1/tls_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -125,7 +125,7 @@ func (s TLSSpec) GetParsedAltNames() (dnsNames, ipAddresses, emailAddresses []st } else if validation.IsValidEmailAddress(name) { emailAddresses = append(emailAddresses, name) } else { - return nil, nil, nil, errors.WithStack(errors.Newf("'%s' is not a valid alternate name", name)) + return nil, nil, nil, errors.WithStack(errors.Errorf("'%s' is not a valid alternate name", name)) } } return dnsNames, ipAddresses, emailAddresses, nil diff --git a/pkg/apis/deployment/v2alpha1/version.go b/pkg/apis/deployment/v2alpha1/version.go index 2d9ccc01f..fe2f9eb10 100644 --- a/pkg/apis/deployment/v2alpha1/version.go +++ b/pkg/apis/deployment/v2alpha1/version.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import ( "strconv" "strings" - "github.com/pkg/errors" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) var _ json.Marshaler = Version{} diff --git a/pkg/apis/ml/v1alpha1/batchjob_spec.go b/pkg/apis/ml/v1alpha1/batchjob_spec.go index 5e7638265..8378fe378 100644 --- a/pkg/apis/ml/v1alpha1/batchjob_spec.go +++ b/pkg/apis/ml/v1alpha1/batchjob_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,16 +35,16 @@ type ArangoMLBatchJobSpec struct { func (a *ArangoMLBatchJobSpec) Validate() error { if a == nil { - return errors.Newf("Spec is not defined") + return errors.Errorf("Spec is not defined") } var err []error if a.JobSpec == nil { - return shared.PrefixResourceErrors("spec", errors.Newf("JobSpec is not defined")) + return shared.PrefixResourceErrors("spec", errors.Errorf("JobSpec is not defined")) } if len(a.JobSpec.Template.Spec.Containers) != 1 { - err = append(err, shared.PrefixResourceErrors("spec.template.spec.containers", errors.Newf("Exactly one container is required"))) + err = append(err, shared.PrefixResourceErrors("spec.template.spec.containers", errors.Errorf("Exactly one container is required"))) } return shared.WithErrors(err...) diff --git a/pkg/apis/ml/v1alpha1/cronjob_spec.go b/pkg/apis/ml/v1alpha1/cronjob_spec.go index 7c41a7220..c21e112d6 100644 --- a/pkg/apis/ml/v1alpha1/cronjob_spec.go +++ b/pkg/apis/ml/v1alpha1/cronjob_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,17 +35,17 @@ type ArangoMLCronJobSpec struct { func (a *ArangoMLCronJobSpec) Validate() error { if a == nil { - return errors.Newf("Spec is not defined") + return errors.Errorf("Spec is not defined") } var err []error if a.CronJobSpec == nil { - return shared.PrefixResourceErrors("spec", errors.Newf("CronJobSpec is not defined")) + return shared.PrefixResourceErrors("spec", errors.Errorf("CronJobSpec is not defined")) } if len(a.CronJobSpec.JobTemplate.Spec.Template.Spec.Containers) != 1 { err = append(err, shared.PrefixResourceErrors("spec.jobTemplate.spec.template.spec.containers", - errors.Newf("Exactly one container is required"))) + errors.Errorf("Exactly one container is required"))) } return shared.WithErrors(err...) diff --git a/pkg/apis/ml/v1alpha1/extension_spec_deployment.go b/pkg/apis/ml/v1alpha1/extension_spec_deployment.go index dbe663499..b06064bd4 100644 --- a/pkg/apis/ml/v1alpha1/extension_spec_deployment.go +++ b/pkg/apis/ml/v1alpha1/extension_spec_deployment.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -147,7 +147,7 @@ func (s *ArangoMLExtensionSpecDeployment) Validate() error { } if s.GetReplicas() < 0 || s.GetReplicas() > 10 { - errs = append(errs, shared.PrefixResourceErrors("replicas", errors.Newf("out of range [0, 10]"))) + errs = append(errs, shared.PrefixResourceErrors("replicas", errors.Errorf("out of range [0, 10]"))) } var usedPorts util.List[int32] @@ -161,7 +161,7 @@ func (s *ArangoMLExtensionSpecDeployment) Validate() error { port := component.GetPort(GetArangoMLExtensionSpecDeploymentComponentDefaultPort(prefix)) if port == 0 { - errs = append(errs, shared.PrefixResourceErrors(prefix, errors.Newf("port not defined"))) + errs = append(errs, shared.PrefixResourceErrors(prefix, errors.Errorf("port not defined"))) continue } @@ -169,7 +169,7 @@ func (s *ArangoMLExtensionSpecDeployment) Validate() error { return i == port }) if duplicateCount > 0 { - errs = append(errs, shared.PrefixResourceErrors(prefix, errors.Newf("port %d already specified for other component", port))) + errs = append(errs, shared.PrefixResourceErrors(prefix, errors.Errorf("port %d already specified for other component", port))) } else { usedPorts.Append(port) } diff --git a/pkg/apis/ml/v1alpha1/extension_spec_metadata_service.go b/pkg/apis/ml/v1alpha1/extension_spec_metadata_service.go index 47caf3062..4cc41b727 100644 --- a/pkg/apis/ml/v1alpha1/extension_spec_metadata_service.go +++ b/pkg/apis/ml/v1alpha1/extension_spec_metadata_service.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -93,7 +93,7 @@ func (a *ArangoMLExtensionSpecMetadataServiceLocal) Validate() error { // If Nil then we use default return shared.WithErrors( - shared.PrefixResourceErrors("arangoPipeDatabase", util.BoolSwitch(a.GetArangoPipeDatabase() != ArangoMLExtensionSpecMetadataServiceLocalDefaultArangoPipeDatabase, errors.Newf("Database name is hardcoded"), nil)), - shared.PrefixResourceErrors("arangoMLFeatureStore", util.BoolSwitch(a.GetArangoMLFeatureStoreDatabase() != ArangoMLExtensionSpecMetadataServiceLocalDefaultArangoMLFeatureStoreDatabase, errors.Newf("Database name is hardcoded"), nil)), + shared.PrefixResourceErrors("arangoPipeDatabase", util.BoolSwitch(a.GetArangoPipeDatabase() != ArangoMLExtensionSpecMetadataServiceLocalDefaultArangoPipeDatabase, errors.Errorf("Database name is hardcoded"), nil)), + shared.PrefixResourceErrors("arangoMLFeatureStore", util.BoolSwitch(a.GetArangoMLFeatureStoreDatabase() != ArangoMLExtensionSpecMetadataServiceLocalDefaultArangoMLFeatureStoreDatabase, errors.Errorf("Database name is hardcoded"), nil)), ) } diff --git a/pkg/apis/ml/v1alpha1/storage_spec_backend.go b/pkg/apis/ml/v1alpha1/storage_spec_backend.go index 45571c503..4dff4e93e 100644 --- a/pkg/apis/ml/v1alpha1/storage_spec_backend.go +++ b/pkg/apis/ml/v1alpha1/storage_spec_backend.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,11 +39,11 @@ func (s *ArangoMLStorageSpecBackend) GetS3() *ArangoMLStorageSpecBackendS3 { func (s *ArangoMLStorageSpecBackend) Validate() error { if s == nil { - return errors.Newf("Backend is not specified") + return errors.Errorf("Backend is not specified") } if s.S3 == nil { - return errors.Newf("At least one backend needs to be defined") + return errors.Errorf("At least one backend needs to be defined") } return shared.WithErrors(shared.PrefixResourceError("s3", s.S3.Validate())) diff --git a/pkg/apis/ml/v1alpha1/storage_spec_backend_s3.go b/pkg/apis/ml/v1alpha1/storage_spec_backend_s3.go index 688cfab05..683eadcee 100644 --- a/pkg/apis/ml/v1alpha1/storage_spec_backend_s3.go +++ b/pkg/apis/ml/v1alpha1/storage_spec_backend_s3.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ func (s *ArangoMLStorageSpecBackendS3) Validate() error { } if _, err := url.Parse(s.GetEndpoint()); err != nil { - errs = append(errs, shared.PrefixResourceErrors("endpoint", errors.Newf("invalid URL: %s", err.Error()))) + errs = append(errs, shared.PrefixResourceErrors("endpoint", errors.Errorf("invalid URL: %s", err.Error()))) } errs = append(errs, shared.PrefixResourceErrors("credentialsSecret", s.GetCredentialsSecret().Validate())) diff --git a/pkg/apis/ml/v1alpha1/storage_spec_mode.go b/pkg/apis/ml/v1alpha1/storage_spec_mode.go index 7af1332e2..92505d791 100644 --- a/pkg/apis/ml/v1alpha1/storage_spec_mode.go +++ b/pkg/apis/ml/v1alpha1/storage_spec_mode.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ func (s *ArangoMLStorageSpecMode) GetSidecar() *ArangoMLStorageSpecModeSidecar { func (s *ArangoMLStorageSpecMode) Validate() error { if s == nil { - return errors.Newf("Mode is not defined") + return errors.Errorf("Mode is not defined") } return shared.WithErrors(shared.PrefixResourceError("sidecar", s.Sidecar.Validate())) } diff --git a/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go b/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go index 6a68f84c7..fe72eb704 100644 --- a/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go +++ b/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go @@ -55,11 +55,11 @@ func (s *ArangoMLStorageSpecModeSidecar) Validate() error { var err []error if s.GetListenPort() < 1 { - err = append(err, shared.PrefixResourceErrors("listenPort", errors.Newf("must be positive"))) + err = append(err, shared.PrefixResourceErrors("listenPort", errors.Errorf("must be positive"))) } if s.GetControllerListenPort() < 1 { - err = append(err, shared.PrefixResourceErrors("controllerListenPort", errors.Newf("must be positive"))) + err = append(err, shared.PrefixResourceErrors("controllerListenPort", errors.Errorf("must be positive"))) } err = append(err, s.GetContainerTemplate().Validate()) diff --git a/pkg/apis/shared/v1/resource.go b/pkg/apis/shared/v1/resource.go index 9ca8122c5..4fd8fcbce 100644 --- a/pkg/apis/shared/v1/resource.go +++ b/pkg/apis/shared/v1/resource.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -67,13 +67,13 @@ func (n *KubernetesResourceName) String() string { // Validate validate if name is valid kubernetes DNS_LABEL func (n *KubernetesResourceName) Validate() error { if n == nil { - return errors.Newf("cannot be undefined") + return errors.Errorf("cannot be undefined") } name := *n if name == "" { - return errors.Newf("cannot be empty") + return errors.Errorf("cannot be empty") } if err := IsValidName(name.String()); err != nil { @@ -90,11 +90,11 @@ func (n *KubernetesResourceName) Immutable(o *KubernetesResourceName) error { } if o == nil || n == nil { - return errors.Newf("field is immutable") + return errors.Errorf("field is immutable") } if *o != *n { - return errors.Newf("field is immutable") + return errors.Errorf("field is immutable") } return nil @@ -104,7 +104,7 @@ func (n *KubernetesResourceName) Immutable(o *KubernetesResourceName) error { // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names func IsValidName(name string) error { if res := validation.IsDNS1123Label(name); len(res) > 0 { - return errors.Newf("Validation of label failed: %s", strings.Join(res, ", ")) + return errors.Errorf("Validation of label failed: %s", strings.Join(res, ", ")) } return nil @@ -112,7 +112,7 @@ func IsValidName(name string) error { func IsValidDomain(name string) error { if res := validation.IsDNS1123Subdomain(name); len(res) > 0 { - return errors.Newf("validation of domain failed: %s", strings.Join(res, ", ")) + return errors.Errorf("validation of domain failed: %s", strings.Join(res, ", ")) } return nil diff --git a/pkg/apis/shared/validate.go b/pkg/apis/shared/validate.go index 8aaf5369b..08e946f2f 100644 --- a/pkg/apis/shared/validate.go +++ b/pkg/apis/shared/validate.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -40,12 +40,12 @@ var ( // See https://kubernetes.io/docs/concepts/overview/working-with-objects/names/ func ValidateResourceName(name string) error { if len(name) > 253 { - return errors.WithStack(errors.Newf("Name '%s' is too long", name)) + return errors.WithStack(errors.Errorf("Name '%s' is too long", name)) } if resourceNameRE.MatchString(name) { return nil } - return errors.WithStack(errors.Newf("Name '%s' is not a valid resource name", name)) + return errors.WithStack(errors.Errorf("Name '%s' is not a valid resource name", name)) } // ValidateOptionalResourceName validates a kubernetes resource name. @@ -73,7 +73,7 @@ func ValidatePullPolicy(in core.PullPolicy) error { return nil } - return errors.Newf("Unknown pull policy: '%s'", string(in)) + return errors.Errorf("Unknown pull policy: '%s'", string(in)) } type ValidateInterface interface { @@ -106,7 +106,7 @@ func ValidateRequired[T interface{}](in *T, validator func(T) error) error { return validator(*in) } - return errors.Newf("should be not nil") + return errors.Errorf("should be not nil") } // ValidateList validates all elements on the list @@ -123,7 +123,7 @@ func ValidateList[T interface{}](in []T, validator func(T) error) error { // ValidateImage Validates if provided image is valid func ValidateImage(image string) error { if image == "" { - return errors.Newf("Image should be not empty") + return errors.Errorf("Image should be not empty") } return nil @@ -137,7 +137,7 @@ func ValidateAnyNotNil[T any](msg string, obj ...*T) error { } } - return errors.Newf(msg) + return errors.Errorf(msg) } // ValidateServiceType checks that service type is supported @@ -149,5 +149,5 @@ func ValidateServiceType(st core.ServiceType) error { core.ServiceTypeExternalName: return nil } - return errors.Newf("Unsupported service type %s", st) + return errors.Errorf("Unsupported service type %s", st) } diff --git a/pkg/apis/storage/v1alpha/storage_class_spec.go b/pkg/apis/storage/v1alpha/storage_class_spec.go index 1c744d100..3f7c19b55 100644 --- a/pkg/apis/storage/v1alpha/storage_class_spec.go +++ b/pkg/apis/storage/v1alpha/storage_class_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ func (s StorageClassSpec) Validate() error { switch r := s.GetReclaimPolicy(); r { case core.PersistentVolumeReclaimRetain, core.PersistentVolumeReclaimDelete: default: - return errors.Newf("Unsupported ReclaimPolicy: %s", r) + return errors.Errorf("Unsupported ReclaimPolicy: %s", r) } return nil diff --git a/pkg/crd/definitions.go b/pkg/crd/definitions.go index 7e8b7f534..6135692ce 100644 --- a/pkg/crd/definitions.go +++ b/pkg/crd/definitions.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ func registerCRD(getter crdDefinitionGetter, defaultOpts crds.CRDOptions) error def := getter(nil) if _, ok := registeredCRDs[def.CRD.GetName()]; ok { - return errors.Newf("CRD %s already exists", def.CRD.GetName()) + return errors.Errorf("CRD %s already exists", def.CRD.GetName()) } registeredCRDs[def.CRD.GetName()] = crdRegistration{ getter: getter, diff --git a/pkg/debug_package/generator.go b/pkg/debug_package/generator.go index c2dbbc5cd..5ddee7610 100644 --- a/pkg/debug_package/generator.go +++ b/pkg/debug_package/generator.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -167,7 +167,7 @@ func Generate(cmd *cobra.Command, out io.Writer, factories ...shared.Factory) er } if len(fileErrors) > 0 || len(factoryErrors) > 0 { - return errors.Newf("Error while receiving data") + return errors.Errorf("Error while receiving data") } return nil diff --git a/pkg/debug_package/generators/kubernetes/agency.go b/pkg/debug_package/generators/kubernetes/agency.go index d93c9b1d7..311311cd2 100644 --- a/pkg/debug_package/generators/kubernetes/agency.go +++ b/pkg/debug_package/generators/kubernetes/agency.go @@ -49,7 +49,7 @@ func agencyDump(logger zerolog.Logger, files chan<- shared.File) error { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return errors.Newf("Client is not initialised") + return errors.Errorf("Client is not initialised") } deployments, err := listArangoDeployments(k.Arango())() @@ -100,7 +100,7 @@ func discoverExecFunc() (ArangoOperatorExecFunc, error) { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return nil, errors.Newf("Client is not initialised") + return nil, errors.Errorf("Client is not initialised") } pods, err := listPods(k.Kubernetes())() @@ -131,7 +131,7 @@ func discoverExecFunc() (ArangoOperatorExecFunc, error) { } if id == "" { - return nil, errors.Newf("Unable to find Operator pod") + return nil, errors.Errorf("Unable to find Operator pod") } return func(args ...string) ([]byte, []byte, error) { diff --git a/pkg/debug_package/generators/kubernetes/arango_deployments.go b/pkg/debug_package/generators/kubernetes/arango_deployments.go index ae446b484..78e07d039 100644 --- a/pkg/debug_package/generators/kubernetes/arango_deployments.go +++ b/pkg/debug_package/generators/kubernetes/arango_deployments.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ func listArangoDeployments(client arangoClient.Interface) func() ([]*api.ArangoD func deployments(logger zerolog.Logger, files chan<- shared.File) error { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return errors.Newf("Client is not initialised") + return errors.Errorf("Client is not initialised") } deploymentList, err := listArangoDeployments(k.Arango())() diff --git a/pkg/debug_package/generators/kubernetes/arango_ml.go b/pkg/debug_package/generators/kubernetes/arango_ml.go index d726ab834..b10ca72ca 100644 --- a/pkg/debug_package/generators/kubernetes/arango_ml.go +++ b/pkg/debug_package/generators/kubernetes/arango_ml.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ func ML() shared.Factory { func ml(logger zerolog.Logger, files chan<- shared.File) error { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return errors.Newf("Client is not initialised") + return errors.Errorf("Client is not initialised") } if err := mlExtensions(logger, files, k); err != nil { diff --git a/pkg/debug_package/generators/kubernetes/events.go b/pkg/debug_package/generators/kubernetes/events.go index 6be948ff2..5a2fdb3f4 100644 --- a/pkg/debug_package/generators/kubernetes/events.go +++ b/pkg/debug_package/generators/kubernetes/events.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ func listEvents(client kubernetes.Interface) func() ([]*core.Event, error) { func events(logger zerolog.Logger, files chan<- shared.File) error { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return errors.Newf("Client is not initialised") + return errors.Errorf("Client is not initialised") } files <- shared.NewYAMLFile("kubernetes/events.yaml", listEvents(k.Kubernetes())) diff --git a/pkg/debug_package/generators/kubernetes/pods.go b/pkg/debug_package/generators/kubernetes/pods.go index 11ce8ae69..8b86c4600 100644 --- a/pkg/debug_package/generators/kubernetes/pods.go +++ b/pkg/debug_package/generators/kubernetes/pods.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ func listPods(client kubernetes.Interface) func() ([]*core.Pod, error) { func pods(logger zerolog.Logger, files chan<- shared.File) error { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return errors.Newf("Client is not initialised") + return errors.Errorf("Client is not initialised") } pods, err := listPods(k.Kubernetes())() diff --git a/pkg/debug_package/generators/kubernetes/secrets.go b/pkg/debug_package/generators/kubernetes/secrets.go index 1a7f591a5..23c79527d 100644 --- a/pkg/debug_package/generators/kubernetes/secrets.go +++ b/pkg/debug_package/generators/kubernetes/secrets.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ func listSecrets(client kubernetes.Interface) func() ([]*core.Secret, error) { func secrets(logger zerolog.Logger, files chan<- shared.File) error { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return errors.Newf("Client is not initialised") + return errors.Errorf("Client is not initialised") } files <- shared.NewYAMLFile("kubernetes/secrets.yaml", listSecrets(k.Kubernetes())) diff --git a/pkg/debug_package/generators/kubernetes/services.go b/pkg/debug_package/generators/kubernetes/services.go index 09852da8f..a5aba02af 100644 --- a/pkg/debug_package/generators/kubernetes/services.go +++ b/pkg/debug_package/generators/kubernetes/services.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ func listServices(client kubernetes.Interface) func() ([]*core.Service, error) { func services(logger zerolog.Logger, files chan<- shared.File) error { k, ok := kclient.GetDefaultFactory().Client() if !ok { - return errors.Newf("Client is not initialised") + return errors.Errorf("Client is not initialised") } services, err := listServices(k.Kubernetes())() diff --git a/pkg/deployment/agency/cache.go b/pkg/deployment/agency/cache.go index c9e6e7678..fc53303e4 100644 --- a/pkg/deployment/agency/cache.go +++ b/pkg/deployment/agency/cache.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -93,17 +93,17 @@ func (h health) Healthy() error { } if h.election[h.leaderID] != h.agencySize { - return errors.Newf("Not all agents are in quorum") + return errors.Errorf("Not all agents are in quorum") } index := h.commitIndexes[h.leaderID] if index == 0 { - return errors.Newf("Agency CommitIndex is zero") + return errors.Errorf("Agency CommitIndex is zero") } for k, v := range h.commitIndexes { if v != index { - return errors.Newf("Agent %s is behind in CommitIndex", k) + return errors.Errorf("Agent %s is behind in CommitIndex", k) } } @@ -112,17 +112,17 @@ func (h health) Healthy() error { func (h health) Serving() error { if h.agencySize == 0 { - return errors.Newf("Empty agents list") + return errors.Errorf("Empty agents list") } if len(h.election) == 0 { - return errors.Newf("No Leader") + return errors.Errorf("No Leader") } else if len(h.election) > 1 { - return errors.Newf("Multiple leaders") + return errors.Errorf("Multiple leaders") } if len(h.leaders) <= h.agencySize/2 { - return errors.Newf("Quorum is not present") + return errors.Errorf("Quorum is not present") } return nil @@ -342,7 +342,7 @@ func (c *cache) reload(ctx context.Context, size int, clients Connections) (*sta data, index, ok := c.loader.State() if !ok { - return nil, 0, errors.Newf("State is invalid after reload") + return nil, 0, errors.Errorf("State is invalid after reload") } return data, index, nil @@ -441,5 +441,5 @@ func (c *cache) getLeader(ctx context.Context, size int, clients Connections) (c } } - return nil, h, errors.Newf("Unable to find agent") + return nil, h, errors.Errorf("Unable to find agent") } diff --git a/pkg/deployment/agency/config.go b/pkg/deployment/agency/config.go index 9bd1a57e8..d167530cd 100644 --- a/pkg/deployment/agency/config.go +++ b/pkg/deployment/agency/config.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ func GetAgencyConfig(ctx context.Context, connection conn.Connection) (*Config, } if code != http.StatusOK { - return nil, errors.Newf("Unknown response code %d", code) + return nil, errors.Errorf("Unknown response code %d", code) } return resp, nil diff --git a/pkg/deployment/agency/state.go b/pkg/deployment/agency/state.go index 15e6d1ad3..a35d6cd64 100644 --- a/pkg/deployment/agency/state.go +++ b/pkg/deployment/agency/state.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,15 +38,15 @@ func GetAgencyState[T interface{}](ctx context.Context, connection conn.Connecti } if code != http.StatusOK { - return def, errors.Newf("Unknown response code %d", code) + return def, errors.Errorf("Unknown response code %d", code) } if resp == nil { - return def, errors.Newf("Missing response body") + return def, errors.Errorf("Missing response body") } if len(*resp) != 1 { - return def, errors.Newf("Invalid response size") + return def, errors.Errorf("Invalid response size") } return (*resp)[0], nil diff --git a/pkg/deployment/agency/state/rf.go b/pkg/deployment/agency/state/rf.go index 26eb794b4..81fdfdc2d 100644 --- a/pkg/deployment/agency/state/rf.go +++ b/pkg/deployment/agency/state/rf.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,8 +23,9 @@ package state import ( "encoding/json" - "github.com/pkg/errors" "k8s.io/apimachinery/pkg/util/intstr" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) const ( diff --git a/pkg/deployment/agency/state/state_timestamp.go b/pkg/deployment/agency/state/state_timestamp.go index a566c28e9..73ef5fa91 100644 --- a/pkg/deployment/agency/state/state_timestamp.go +++ b/pkg/deployment/agency/state/state_timestamp.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -66,7 +66,7 @@ func (s *Timestamp) Time() (time.Time, bool) { func (s *Timestamp) UnmarshalJSON(bytes []byte) error { if s == nil { - return errors.Newf("Object is nil") + return errors.Errorf("Object is nil") } var t string diff --git a/pkg/deployment/client/client_cache.go b/pkg/deployment/client/client_cache.go index e2904d81d..cce921ce7 100644 --- a/pkg/deployment/client/client_cache.go +++ b/pkg/deployment/client/client_cache.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -184,7 +184,7 @@ func (cc *cache) GetAgency(_ context.Context, agencyIDs ...string) (agency.Agenc } if len(dnsNames) == 0 { - return nil, errors.Newf("There is no DNS Name") + return nil, errors.Errorf("There is no DNS Name") } c, err := cc.factory.Agency(dnsNames...) diff --git a/pkg/deployment/context_impl.go b/pkg/deployment/context_impl.go index 26a91a614..4b775062a 100644 --- a/pkg/deployment/context_impl.go +++ b/pkg/deployment/context_impl.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -146,7 +146,7 @@ func (d *Deployment) UpdateMember(ctx context.Context, member api.MemberStatus) status := d.GetStatus() _, group, found := status.Members.ElementByID(member.ID) if !found { - return errors.WithStack(errors.Newf("Member %s not found", member.ID)) + return errors.WithStack(errors.Errorf("Member %s not found", member.ID)) } if err := status.Members.Update(member, group); err != nil { return errors.WithStack(err) @@ -252,7 +252,7 @@ func (d *Deployment) getAuth() (driver.Authentication, error) { } if !d.GetCachedStatus().Initialised() { - return nil, errors.Newf("Cache is not yet started") + return nil, errors.Errorf("Cache is not yet started") } var secret string @@ -269,7 +269,7 @@ func (d *Deployment) getAuth() (driver.Authentication, error) { } if !found { - return nil, errors.Newf("JWT Secret is invalid") + return nil, errors.Errorf("JWT Secret is invalid") } jwt, err := jwt.CreateArangodJwtAuthorizationHeader(secret, "kube-arangodb") @@ -676,11 +676,11 @@ func (d *Deployment) WithMemberStatusUpdateErr(ctx context.Context, id string, g return d.WithStatusUpdateErr(ctx, func(s *api.DeploymentStatus) (bool, error) { m, g, ok := s.Members.ElementByID(id) if !ok { - return false, errors.Newf("Member %s not found", id) + return false, errors.Errorf("Member %s not found", id) } if g != group { - return false, errors.Newf("Invalid group for %s. Wanted %s, found %s", id, group.AsRole(), g.AsRole()) + return false, errors.Errorf("Invalid group for %s. Wanted %s, found %s", id, group.AsRole(), g.AsRole()) } changed, err := action(&m) diff --git a/pkg/deployment/deployment.go b/pkg/deployment/deployment.go index 9b7382db9..6edbdd13b 100644 --- a/pkg/deployment/deployment.go +++ b/pkg/deployment/deployment.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -204,7 +204,7 @@ func (d *Deployment) RefreshAgencyCache(ctx context.Context) (uint64, error) { } } - return 0, errors.Newf("Agency not yet established") + return 0, errors.Errorf("Agency not yet established") } func (d *Deployment) SetAgencyMaintenanceMode(ctx context.Context, enabled bool) error { @@ -484,7 +484,7 @@ func (d *Deployment) acceptNewSpec(ctx context.Context, depl *api.ArangoDeployme } // We have immutable fields, throw an error and proceed - return true, false, errors.Newf("Immutable fields cannot be changed: %s", strings.Join(fields, ", ")) + return true, false, errors.Errorf("Immutable fields cannot be changed: %s", strings.Join(fields, ", ")) } // Update accepted spec @@ -632,7 +632,7 @@ func (d *Deployment) applyPatch(ctx context.Context, p ...patch.Item) error { } if err != nil { d.log.Err(err).Debug("failed to patch ArangoDeployment") - return errors.WithStack(errors.Newf("failed to patch ArangoDeployment: %v", err)) + return errors.WithStack(errors.Errorf("failed to patch ArangoDeployment: %v", err)) } } } diff --git a/pkg/deployment/deployment_inspector.go b/pkg/deployment/deployment_inspector.go index c68bbbade..6c13bec99 100644 --- a/pkg/deployment/deployment_inspector.go +++ b/pkg/deployment/deployment_inspector.go @@ -279,7 +279,7 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva // Is the deployment in a good state? if status.Conditions.IsTrue(api.ConditionTypeSecretsChanged) { - return minInspectionInterval, errors.Newf("Secrets changed") + return minInspectionInterval, errors.Errorf("Secrets changed") } // Ensure we have image info diff --git a/pkg/deployment/member/state.go b/pkg/deployment/member/state.go index 1251e7935..9bba04e97 100644 --- a/pkg/deployment/member/state.go +++ b/pkg/deployment/member/state.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -258,7 +258,7 @@ func (s *stateInspector) GetMemberClient(id string) (driver.Client, error) { } } - return nil, errors.Newf("failed to get ArangoDB member client: %s", id) + return nil, errors.Errorf("failed to get ArangoDB member client: %s", id) } // GetMemberSyncClient returns member client to a server. @@ -274,7 +274,7 @@ func (s *stateInspector) GetMemberSyncClient(id string) (client.API, error) { } } - return nil, errors.Newf("failed to get ArangoSync member client: %s", id) + return nil, errors.Errorf("failed to get ArangoSync member client: %s", id) } func (s *stateInspector) MemberState(id string) (State, bool) { @@ -325,7 +325,7 @@ func (s State) GetDatabaseClient() (driver.Client, error) { return nil, s.NotReachableErr } - return nil, errors.Newf("ArangoDB is not reachable") + return nil, errors.Errorf("ArangoDB is not reachable") } func (s State) IsReachable() bool { diff --git a/pkg/deployment/members.go b/pkg/deployment/members.go index ead7c0984..a3d20daa4 100644 --- a/pkg/deployment/members.go +++ b/pkg/deployment/members.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -54,7 +54,7 @@ func (d *Deployment) createAgencyMapping(ctx context.Context) error { agents := status.Members.Agents if len(agents) > *spec.Agents.Count { - return errors.Newf("Agency size is bigger than requested size") + return errors.Errorf("Agency size is bigger than requested size") } c := api.DeploymentStatusAgencySize(*spec.Agents.Count) @@ -211,6 +211,6 @@ func (d *Deployment) renderMember(spec api.DeploymentSpec, status *api.Deploymen Architecture: &arch, }, nil default: - return nil, errors.WithStack(errors.Newf("Unknown server group %d", group)) + return nil, errors.WithStack(errors.Errorf("Unknown server group %d", group)) } } diff --git a/pkg/deployment/pod/encryption.go b/pkg/deployment/pod/encryption.go index bc89c4c15..1a5c5ab56 100644 --- a/pkg/deployment/pod/encryption.go +++ b/pkg/deployment/pod/encryption.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -85,16 +85,16 @@ func GetEncryptionKey(ctx context.Context, secrets secretv1.ReadInterface, name func GetEncryptionKeyFromSecret(keyfile *core.Secret) (string, []byte, error) { if len(keyfile.Data) == 0 { - return "", nil, errors.Newf("Current encryption key is not valid - missing data section") + return "", nil, errors.Errorf("Current encryption key is not valid - missing data section") } d, ok := keyfile.Data[constants.SecretEncryptionKey] if !ok { - return "", nil, errors.Newf("Current encryption key is not valid - missing field") + return "", nil, errors.Errorf("Current encryption key is not valid - missing field") } if len(d) != 32 { - return "", nil, errors.Newf("Current encryption key is not valid") + return "", nil, errors.Errorf("Current encryption key is not valid") } sha := fmt.Sprintf("%0x", sha256.Sum256(d)) @@ -170,7 +170,7 @@ func (e encryption) Verify(i Input, cachedStatus interfaces.Inspector) error { secret, exists := cachedStatus.Secret().V1().GetSimple(i.Deployment.RocksDB.Encryption.GetKeySecretName()) if !exists { - return errors.Newf("Encryption key secret does not exist %s", i.Deployment.RocksDB.Encryption.GetKeySecretName()) + return errors.Errorf("Encryption key secret does not exist %s", i.Deployment.RocksDB.Encryption.GetKeySecretName()) } if err := k8sutil.ValidateEncryptionKeyFromSecret(secret); err != nil { diff --git a/pkg/deployment/pod/jwt.go b/pkg/deployment/pod/jwt.go index 7746a2f77..b66385dfa 100644 --- a/pkg/deployment/pod/jwt.go +++ b/pkg/deployment/pod/jwt.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -102,7 +102,7 @@ func (e jwt) Verify(i Input, cachedStatus interfaces.Inspector) error { if !VersionHasJWTSecretKeyfolder(i.Version, i.Enterprise) { secret, exists := cachedStatus.Secret().V1().GetSimple(i.Deployment.Authentication.GetJWTSecretName()) if !exists { - return errors.Newf("Secret for JWT token is missing %s", i.Deployment.Authentication.GetJWTSecretName()) + return errors.Errorf("Secret for JWT token is missing %s", i.Deployment.Authentication.GetJWTSecretName()) } if err := k8sutil.ValidateTokenFromSecret(secret); err != nil { diff --git a/pkg/deployment/pod/sni.go b/pkg/deployment/pod/sni.go index d5479f341..4b6da103b 100644 --- a/pkg/deployment/pod/sni.go +++ b/pkg/deployment/pod/sni.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -81,12 +81,12 @@ func (s sni) Verify(i Input, cachedStatus interfaces.Inspector) error { for _, secret := range util.SortKeys(i.Deployment.TLS.GetSNI().Mapping) { kubeSecret, exists := cachedStatus.Secret().V1().GetSimple(secret) if !exists { - return errors.Newf("SNI Secret not found %s", secret) + return errors.Errorf("SNI Secret not found %s", secret) } _, ok := kubeSecret.Data[constants.SecretTLSKeyfile] if !ok { - return errors.Newf("Unable to find secret key %s/%s for SNI", secret, constants.SecretTLSKeyfile) + return errors.Errorf("Unable to find secret key %s/%s for SNI", secret, constants.SecretTLSKeyfile) } } return nil diff --git a/pkg/deployment/pod/utils.go b/pkg/deployment/pod/utils.go index 9ad4e9ba4..da5b7fd7d 100644 --- a/pkg/deployment/pod/utils.go +++ b/pkg/deployment/pod/utils.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ func GenerateMemberEndpoint(services service.Inspector, apiObject meta.Object, s memberName := member.ArangoMemberName(apiObject.GetName(), group) svc, ok := services.Service().V1().GetSimple(memberName) if !ok { - return "", errors.Newf("Service %s not found", memberName) + return "", errors.Errorf("Service %s not found", memberName) } return GenerateMemberEndpointFromService(svc, apiObject, spec, group, member) @@ -47,7 +47,7 @@ func GenerateMemberEndpointFromService(svc *core.Service, apiObject meta.Object, return k8sutil.CreateServiceDNSNameWithDomain(svc, spec.ClusterDomain), nil case api.DeploymentCommunicationMethodIP: if svc.Spec.ClusterIP == "" { - return "", errors.Newf("ClusterIP of service %s is empty", svc.GetName()) + return "", errors.Errorf("ClusterIP of service %s is empty", svc.GetName()) } if svc.Spec.ClusterIP == core.ClusterIPNone { diff --git a/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go b/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go index 71b3f4f2b..93f0416d7 100644 --- a/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go +++ b/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ func (a *actionArangoMemberUpdatePodSpec) Start(ctx context.Context) (bool, erro _, ok := cache.ArangoMember().V1().GetSimple(name) if !ok { - err := errors.Newf("ArangoMember not found") + err := errors.Errorf("ArangoMember not found") a.log.Err(err).Error("ArangoMember not found") return false, err } diff --git a/pkg/deployment/reconcile/action_arango_member_update_pod_status.go b/pkg/deployment/reconcile/action_arango_member_update_pod_status.go index cb3d5cb9b..1958f8ea3 100644 --- a/pkg/deployment/reconcile/action_arango_member_update_pod_status.go +++ b/pkg/deployment/reconcile/action_arango_member_update_pod_status.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ func (a *actionArangoMemberUpdatePodStatus) Start(ctx context.Context) (bool, er member, ok := cache.ArangoMember().V1().GetSimple(name) if !ok { - err := errors.Newf("ArangoMember not found") + err := errors.Errorf("ArangoMember not found") a.log.Err(err).Error("ArangoMember not found") return false, err } diff --git a/pkg/deployment/reconcile/action_backup_restore.go b/pkg/deployment/reconcile/action_backup_restore.go index 9505c6be5..e8be1a5c2 100644 --- a/pkg/deployment/reconcile/action_backup_restore.go +++ b/pkg/deployment/reconcile/action_backup_restore.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -96,7 +96,7 @@ func (a actionBackupRestore) Start(ctx context.Context) (bool, error) { case api.DeploymentModeCluster: return a.restoreAsync(ctx, backupResource) default: - return false, errors.Newf("Unknown mode %s", mode) + return false, errors.Errorf("Unknown mode %s", mode) } } @@ -124,7 +124,7 @@ func (a actionBackupRestore) restoreAsync(ctx context.Context, backup *backupApi } } - return false, errors.Newf("Async response not received") + return false, errors.Errorf("Async response not received") } func (a actionBackupRestore) restoreSync(ctx context.Context, backup *backupApi.ArangoBackup) (bool, error) { @@ -166,12 +166,12 @@ func (a actionBackupRestore) restoreSync(ctx context.Context, backup *backupApi. func (a actionBackupRestore) CheckProgress(ctx context.Context) (bool, bool, error) { backup, ok := a.actionCtx.Get(a.action, actionBackupRestoreLocalBackupName) if !ok { - return false, false, errors.Newf("Local Key is missing in action: %s", actionBackupRestoreLocalBackupName) + return false, false, errors.Errorf("Local Key is missing in action: %s", actionBackupRestoreLocalBackupName) } job, ok := a.actionCtx.Get(a.action, actionBackupRestoreLocalJobID) if !ok { - return false, false, errors.Newf("Local Key is missing in action: %s", actionBackupRestoreLocalJobID) + return false, false, errors.Errorf("Local Key is missing in action: %s", actionBackupRestoreLocalJobID) } ctxChild, cancel := globals.GetGlobalTimeouts().ArangoD().WithTimeout(ctx) diff --git a/pkg/deployment/reconcile/action_bootstrap_set_password.go b/pkg/deployment/reconcile/action_bootstrap_set_password.go index 35c48606e..2a1086909 100644 --- a/pkg/deployment/reconcile/action_bootstrap_set_password.go +++ b/pkg/deployment/reconcile/action_bootstrap_set_password.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -149,6 +149,6 @@ func (a actionBootstrapSetPassword) ensureUserPasswordSecret(ctx context.Context if err == nil { return pass, nil } - return "", errors.Newf("invalid secret format in secret %s", secret) + return "", errors.Errorf("invalid secret format in secret %s", secret) } } diff --git a/pkg/deployment/reconcile/action_context.go b/pkg/deployment/reconcile/action_context.go index bdcc3e876..cfb1223a6 100644 --- a/pkg/deployment/reconcile/action_context.go +++ b/pkg/deployment/reconcile/action_context.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -365,7 +365,7 @@ func (ac *actionContext) UpdateMember(ctx context.Context, member api.MemberStat status := ac.context.GetStatus() _, group, found := status.Members.ElementByID(member.ID) if !found { - return errors.WithStack(errors.Newf("Member %s not found", member.ID)) + return errors.WithStack(errors.Errorf("Member %s not found", member.ID)) } if err := status.Members.Update(member, group); err != nil { return errors.WithStack(err) diff --git a/pkg/deployment/reconcile/action_encryption_add.go b/pkg/deployment/reconcile/action_encryption_add.go index 7cb84c984..74e67f61f 100644 --- a/pkg/deployment/reconcile/action_encryption_add.go +++ b/pkg/deployment/reconcile/action_encryption_add.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,14 +37,14 @@ import ( func ensureEncryptionSupport(actionCtx ActionContext) error { if !actionCtx.GetSpec().RocksDB.IsEncrypted() { - return errors.Newf("Encryption is disabled") + return errors.Errorf("Encryption is disabled") } if image, ok := actionCtx.GetCurrentImageInfo(); !ok { - return errors.Newf("Missing image info") + return errors.Errorf("Missing image info") } else { if !features.EncryptionRotation().Supported(image.ArangoDBVersion, image.Enterprise) { - return errors.Newf("Supported only in Enterprise Edition 3.7.0+") + return errors.Errorf("Supported only in Enterprise Edition 3.7.0+") } } return nil diff --git a/pkg/deployment/reconcile/action_jwt_status_update.go b/pkg/deployment/reconcile/action_jwt_status_update.go index c1e5e4d40..b783d039e 100644 --- a/pkg/deployment/reconcile/action_jwt_status_update.go +++ b/pkg/deployment/reconcile/action_jwt_status_update.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -48,11 +48,11 @@ func ensureJWTFolderSupportFromAction(actionCtx ActionContext) (bool, error) { func ensureJWTFolderSupport(spec api.DeploymentSpec, status api.DeploymentStatus) (bool, error) { if !spec.IsAuthenticated() { - return false, errors.Newf("Authentication is disabled") + return false, errors.Errorf("Authentication is disabled") } if image := status.CurrentImage; image == nil { - return false, errors.Newf("Missing image info") + return false, errors.Errorf("Missing image info") } else { if !features.JWTRotation().Supported(image.ArangoDBVersion, image.Enterprise) { return false, nil diff --git a/pkg/deployment/reconcile/action_kill_member_pod.go b/pkg/deployment/reconcile/action_kill_member_pod.go index ee945cb9f..1d6bd88f4 100644 --- a/pkg/deployment/reconcile/action_kill_member_pod.go +++ b/pkg/deployment/reconcile/action_kill_member_pod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -64,7 +64,7 @@ func (a *actionKillMemberPod) Start(ctx context.Context) (bool, error) { cache, ok := a.actionCtx.ACS().ClusterCache(m.ClusterID) if !ok { - return true, errors.Newf("Client is not ready") + return true, errors.Errorf("Client is not ready") } if ifPodUIDMismatch(m, a.action, cache) { @@ -94,7 +94,7 @@ func (a *actionKillMemberPod) CheckProgress(ctx context.Context) (bool, bool, er cache, ok := a.actionCtx.ACS().ClusterCache(m.ClusterID) if !ok { - return false, false, errors.Newf("Client is not ready") + return false, false, errors.Errorf("Client is not ready") } p, ok := cache.Pod().V1().GetSimple(m.Pod.GetName()) diff --git a/pkg/deployment/reconcile/action_pvc_resize.go b/pkg/deployment/reconcile/action_pvc_resize.go index 93f6b6da5..eeaff9f3e 100644 --- a/pkg/deployment/reconcile/action_pvc_resize.go +++ b/pkg/deployment/reconcile/action_pvc_resize.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -76,7 +76,7 @@ func (a *actionPVCResize) Start(ctx context.Context) (bool, error) { cache, ok := a.actionCtx.ACS().ClusterCache(m.ClusterID) if !ok { - return true, errors.Newf("Cluster is not ready") + return true, errors.Errorf("Cluster is not ready") } if m.PersistentVolumeClaim.GetName() == "" { diff --git a/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go b/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go index 20904785e..a1098a1b2 100644 --- a/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go +++ b/pkg/deployment/reconcile/action_rebuild_outsynced_shards.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -119,22 +119,22 @@ func (a *actionRebuildOutSyncedShards) CheckProgress(ctx context.Context) (bool, jobID, ok := a.actionCtx.Get(a.action, actionRebuildOutSyncedShardsLocalJobID) if !ok { - return false, true, errors.Newf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsLocalJobID) + return false, true, errors.Errorf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsLocalJobID) } batchID, ok := a.actionCtx.Get(a.action, actionRebuildOutSyncedShardsBatchID) if !ok { - return false, true, errors.Newf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsBatchID) + return false, true, errors.Errorf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsBatchID) } database, ok := a.actionCtx.Get(a.action, actionRebuildOutSyncedShardsLocalDatabase) if !ok { - return false, true, errors.Newf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsLocalDatabase) + return false, true, errors.Errorf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsLocalDatabase) } shardID, ok := a.actionCtx.Get(a.action, actionRebuildOutSyncedShardsLocalShard) if !ok { - return false, true, errors.Newf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsLocalShard) + return false, true, errors.Errorf("Local Key is missing in action: %s", actionRebuildOutSyncedShardsLocalShard) } // check first if there is rebuild job running diff --git a/pkg/deployment/reconcile/action_recreate_member.go b/pkg/deployment/reconcile/action_recreate_member.go index d8ba42420..0404aaa84 100644 --- a/pkg/deployment/reconcile/action_recreate_member.go +++ b/pkg/deployment/reconcile/action_recreate_member.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -52,19 +52,19 @@ type actionRecreateMember struct { func (a *actionRecreateMember) Start(ctx context.Context) (bool, error) { m, g, ok := a.actionCtx.GetMemberStatusAndGroupByID(a.action.MemberID) if !ok { - return false, errors.Newf("expecting member to be present in list, but it is not") + return false, errors.Errorf("expecting member to be present in list, but it is not") } cache, ok := a.actionCtx.ACS().ClusterCache(m.ClusterID) if !ok { - return true, errors.Newf("Cluster is not ready") + return true, errors.Errorf("Cluster is not ready") } switch g { case api.ServerGroupDBServers, api.ServerGroupAgents: // Only DBServers and Agents use persistent data _, ok := cache.PersistentVolumeClaim().V1().GetSimple(m.PersistentVolumeClaim.GetName()) if !ok { - return false, errors.Newf("PVC is missing %s. Members won't be recreated without old PV", m.PersistentVolumeClaim.GetName()) + return false, errors.Errorf("PVC is missing %s. Members won't be recreated without old PV", m.PersistentVolumeClaim.GetName()) } } diff --git a/pkg/deployment/reconcile/action_remove_member.go b/pkg/deployment/reconcile/action_remove_member.go index 29e5da4cc..041fbfcc7 100644 --- a/pkg/deployment/reconcile/action_remove_member.go +++ b/pkg/deployment/reconcile/action_remove_member.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ func (a *actionRemoveMember) Start(ctx context.Context) (bool, error) { cache, ok := a.actionCtx.ACS().ClusterCache(m.ClusterID) if !ok { - return true, errors.Newf("Cluster is not ready") + return true, errors.Errorf("Cluster is not ready") } // For safety, remove from cluster @@ -93,7 +93,7 @@ func (a *actionRemoveMember) Start(ctx context.Context) (bool, error) { if m.Conditions.IsTrue(api.ConditionTypeTerminating) { if record.Status != driver.ServerStatusFailed { - return false, errors.WithStack(errors.Newf("can not remove server from cluster. Not yet terminated. Retry later")) + return false, errors.WithStack(errors.Errorf("can not remove server from cluster. Not yet terminated. Retry later")) } a.log.Debug("dbserver has shut down") @@ -131,7 +131,7 @@ func (a *actionRemoveMember) Start(ctx context.Context) (bool, error) { } // Check that member has been removed if _, found := a.actionCtx.GetMemberStatusByID(a.action.MemberID); found { - return false, errors.WithStack(errors.Newf("Member %s still exists", a.action.MemberID)) + return false, errors.WithStack(errors.Errorf("Member %s still exists", a.action.MemberID)) } return true, nil } diff --git a/pkg/deployment/reconcile/action_remove_member_pvc.go b/pkg/deployment/reconcile/action_remove_member_pvc.go index 6eac5eb66..91e850e01 100644 --- a/pkg/deployment/reconcile/action_remove_member_pvc.go +++ b/pkg/deployment/reconcile/action_remove_member_pvc.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -62,21 +62,21 @@ func (a *actionRemoveMemberPVC) Start(ctx context.Context) (bool, error) { pvcUID, ok := a.action.GetParam("pvc") if !ok { - return true, errors.Newf("PVC UID Parameter is missing") + return true, errors.Errorf("PVC UID Parameter is missing") } cache, ok := a.actionCtx.ACS().ClusterCache(m.ClusterID) if !ok { - return true, errors.Newf("Cluster is not ready") + return true, errors.Errorf("Cluster is not ready") } agencyCache, ok := a.actionCtx.GetAgencyCache() if !ok { - return true, errors.Newf("Agency is not ready") + return true, errors.Errorf("Agency is not ready") } if agencyCache.PlanLeaderServers().Contains(state.Server(m.ID)) { - return true, errors.Newf("Server is still used in cluster") + return true, errors.Errorf("Server is still used in cluster") } // We are safe to remove PVC diff --git a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go index e62584ab5..44f42c5d8 100644 --- a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go +++ b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,11 +25,11 @@ import ( "fmt" "strings" - "github.com/pkg/errors" core "k8s.io/api/core/v1" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/rotation" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" diff --git a/pkg/deployment/reconcile/action_runtime_container_image_update.go b/pkg/deployment/reconcile/action_runtime_container_image_update.go index 1508771fc..66c504fe0 100644 --- a/pkg/deployment/reconcile/action_runtime_container_image_update.go +++ b/pkg/deployment/reconcile/action_runtime_container_image_update.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -115,7 +115,7 @@ func (a actionRuntimeContainerImageUpdate) Post(ctx context.Context) error { _, ok = cache.ArangoMember().V1().GetSimple(name) if !ok { - err := errors.Newf("ArangoMember not found") + err := errors.Errorf("ArangoMember not found") a.log.Err(err).Error("ArangoMember not found") return err } @@ -179,7 +179,7 @@ func (a actionRuntimeContainerImageUpdate) Start(ctx context.Context) (bool, err cache, ok := a.actionCtx.ACS().ClusterCache(m.ClusterID) if !ok { - return true, errors.Newf("Client is not ready") + return true, errors.Errorf("Client is not ready") } name, image, ok := a.getContainerDetails() @@ -195,7 +195,7 @@ func (a actionRuntimeContainerImageUpdate) Start(ctx context.Context) (bool, err member, ok := a.actionCtx.ACS().CurrentClusterCache().ArangoMember().V1().GetSimple(m.ArangoMemberName(a.actionCtx.GetName(), a.action.Group)) if !ok { - err := errors.Newf("ArangoMember not found") + err := errors.Errorf("ArangoMember not found") a.log.Err(err).Error("ArangoMember not found") return false, err } @@ -250,7 +250,7 @@ func (a actionRuntimeContainerImageUpdate) Start(ctx context.Context) (bool, err a.log.Str("container", name).Str("pod", pod.GetName()).Warn("Container not found") - return false, errors.Newf("Container %s not found in Pod %s", name, pod.GetName()) + return false, errors.Errorf("Container %s not found in Pod %s", name, pod.GetName()) } func (a actionRuntimeContainerImageUpdate) CheckProgress(ctx context.Context) (bool, bool, error) { @@ -311,14 +311,14 @@ func (a actionRuntimeContainerImageUpdate) CheckProgress(ctx context.Context) (b } // Pod won't get up and running - return true, false, errors.Newf("Container %s failed during image replacement: (%d) %s: %s", name, s.ExitCode, s.Reason, s.Message) + return true, false, errors.Errorf("Container %s failed during image replacement: (%d) %s: %s", name, s.ExitCode, s.Reason, s.Message) } else if s := cstatus.State.Waiting; s != nil { if pod.Spec.RestartPolicy == core.RestartPolicyAlways { lastTermination := cstatus.LastTerminationState.Terminated if lastTermination != nil { allowedRestartPeriod := time.Now().Add(time.Second * -20) if lastTermination.FinishedAt.Time.Before(allowedRestartPeriod) { - return true, false, errors.Newf("Container %s continuously failing during image replacement: (%d) %s: %s", name, lastTermination.ExitCode, lastTermination.Reason, lastTermination.Message) + return true, false, errors.Errorf("Container %s continuously failing during image replacement: (%d) %s: %s", name, lastTermination.ExitCode, lastTermination.Reason, lastTermination.Message) } else { a.log.Str("pod-name", pod.GetName()).Debug("pod is restarting - we are not marking it as terminated yet..") } diff --git a/pkg/deployment/reconcile/action_runtime_sync_tolerations.go b/pkg/deployment/reconcile/action_runtime_sync_tolerations.go index 7a80b9747..532ef2cca 100644 --- a/pkg/deployment/reconcile/action_runtime_sync_tolerations.go +++ b/pkg/deployment/reconcile/action_runtime_sync_tolerations.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,12 +24,12 @@ import ( "context" "reflect" - "github.com/pkg/errors" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/deployment/patch" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/tolerations" ) diff --git a/pkg/deployment/reconcile/helper_shutdown.go b/pkg/deployment/reconcile/helper_shutdown.go index 8b240d212..87125d23b 100644 --- a/pkg/deployment/reconcile/helper_shutdown.go +++ b/pkg/deployment/reconcile/helper_shutdown.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -139,7 +139,7 @@ func (s shutdownHelperAPI) Start(ctx context.Context) (bool, error) { cache, ok := s.actionCtx.ACS().ClusterCache(s.memberStatus.ClusterID) if !ok { - return true, errors.Newf("Cluster is not ready") + return true, errors.Errorf("Cluster is not ready") } // Remove finalizers, so Kubernetes will quickly terminate the pod @@ -228,7 +228,7 @@ func (s shutdownHelperDelete) Start(ctx context.Context) (bool, error) { cache, ok := s.actionCtx.ACS().ClusterCache(s.memberStatus.ClusterID) if !ok { - return true, errors.Newf("Cluster is not ready") + return true, errors.Errorf("Cluster is not ready") } // Terminate pod diff --git a/pkg/deployment/reconcile/helper_tls_sni.go b/pkg/deployment/reconcile/helper_tls_sni.go index afe9904b3..fcb5ff281 100644 --- a/pkg/deployment/reconcile/helper_tls_sni.go +++ b/pkg/deployment/reconcile/helper_tls_sni.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,19 +46,19 @@ func mapTLSSNIConfig(sni api.TLSSNISpec, cachedStatus inspectorInterface.Inspect for name, servers := range mapping { secret, exists := cachedStatus.Secret().V1().GetSimple(name) if !exists { - return nil, errors.Newf("Secret %s does not exist", name) + return nil, errors.Errorf("Secret %s does not exist", name) } tlsKey, ok := secret.Data[constants.SecretTLSKeyfile] if !ok { - return nil, errors.Newf("Not found tls keyfile key in SNI secret") + return nil, errors.Errorf("Not found tls keyfile key in SNI secret") } tlsKeyChecksum := fmt.Sprintf("%0x", sha256.Sum256(tlsKey)) for _, server := range servers { if _, ok := fetchedSecrets[server]; ok { - return nil, errors.Newf("Not found tls key in SNI secret") + return nil, errors.Errorf("Not found tls key in SNI secret") } fetchedSecrets[server] = tlsKeyChecksum } @@ -81,13 +81,13 @@ func compareTLSSNIConfig(ctx context.Context, log logging.Logger, c driver.Conne } if len(m) != len(tlsDetails.Result.SNI) { - return false, errors.Newf("Count of SNI mounted secrets does not match") + return false, errors.Errorf("Count of SNI mounted secrets does not match") } for key, value := range tlsDetails.Result.SNI { currentValue, ok := m[key] if !ok { - return false, errors.Newf("Unable to fetch TLS SNI state") + return false, errors.Errorf("Unable to fetch TLS SNI state") } if value.GetSHA().Checksum() != currentValue { diff --git a/pkg/deployment/reconcile/plan_builder_jwt.go b/pkg/deployment/reconcile/plan_builder_jwt.go index 332b0991b..b4da493a8 100644 --- a/pkg/deployment/reconcile/plan_builder_jwt.go +++ b/pkg/deployment/reconcile/plan_builder_jwt.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -277,7 +277,7 @@ func isMemberJWTTokenInvalid(ctx context.Context, c client.Client, data map[stri } if jwtActive, ok := data[pod.ActiveJWTKey]; !ok { - return false, errors.Newf("Missing Active JWT Token in folder") + return false, errors.Errorf("Missing Active JWT Token in folder") } else if util.SHA256(jwtActive) != e.Result.Active.GetSHA().Checksum() { return true, nil } diff --git a/pkg/deployment/reconcile/plan_builder_scale_utils.go b/pkg/deployment/reconcile/plan_builder_scale_utils.go index 6c00f4ca6..a8fb2e650 100644 --- a/pkg/deployment/reconcile/plan_builder_scale_utils.go +++ b/pkg/deployment/reconcile/plan_builder_scale_utils.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -100,7 +100,7 @@ func (s scaleFilter) Select(in ScaleSelectFunc) ScaleFilter { func (s scaleFilter) Get() (api.MemberStatus, error) { el, ok := util.RandomElement(s.in) if !ok { - return api.MemberStatus{}, errors.Newf("Unable to select member") + return api.MemberStatus{}, errors.Errorf("Unable to select member") } return el, nil diff --git a/pkg/deployment/reconcile/plan_builder_test.go b/pkg/deployment/reconcile/plan_builder_test.go index b27526214..c212e444e 100644 --- a/pkg/deployment/reconcile/plan_builder_test.go +++ b/pkg/deployment/reconcile/plan_builder_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -363,13 +363,13 @@ func (c *testContext) EnableScalingCluster(_ context.Context) error { // GetTLSKeyfile returns the keyfile encoded TLS certificate+key for // the given member. func (c *testContext) GetTLSKeyfile(group api.ServerGroup, member api.MemberStatus) (string, error) { - return "", errors.WithStack(errors.Newf("Not implemented")) + return "", errors.WithStack(errors.Errorf("Not implemented")) } // GetTLSCA returns the TLS CA certificate in the secret with given name. // Returns: publicKey, privateKey, ownerByDeployment, error func (c *testContext) GetTLSCA(secretName string) (string, string, bool, error) { - return "", "", false, errors.WithStack(errors.Newf("Not implemented")) + return "", "", false, errors.WithStack(errors.Errorf("Not implemented")) } // CreateEvent creates a given event. diff --git a/pkg/deployment/resources/inspector/acs.go b/pkg/deployment/resources/inspector/acs.go index 5c0b10d7a..e0e5cbd33 100644 --- a/pkg/deployment/resources/inspector/acs.go +++ b/pkg/deployment/resources/inspector/acs.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -181,11 +181,11 @@ func (p *arangoClusterSynchronizationsInspector) Throttle(c throttle.Components) func (p *arangoClusterSynchronizationsInspector) validate() error { if p == nil { - return errors.Newf("ArangoClusterSynchronizationInspector is nil") + return errors.Errorf("ArangoClusterSynchronizationInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/acs_v1.go b/pkg/deployment/resources/inspector/acs_v1.go index 86c1f26ab..e5f175ba7 100644 --- a/pkg/deployment/resources/inspector/acs_v1.go +++ b/pkg/deployment/resources/inspector/acs_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,19 +65,19 @@ func (p *arangoClusterSynchronizationsInspectorV1) Filter(filters ...ins.Filter) func (p *arangoClusterSynchronizationsInspectorV1) validate() error { if p == nil { - return errors.Newf("ArangoClusterSynchronizationsV1Inspector is nil") + return errors.Errorf("ArangoClusterSynchronizationsV1Inspector is nil") } if p.arangoClusterSynchronizationInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.arangoClusterSynchronizations == nil && p.err == nil { - return errors.Newf("ListSimple or err should be not nil") + return errors.Errorf("ListSimple or err should be not nil") } if p.arangoClusterSynchronizations != nil && p.err != nil { - return errors.Newf("ListSimple or err cannot be not nil together") + return errors.Errorf("ListSimple or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/am.go b/pkg/deployment/resources/inspector/am.go index 3b5151cf0..57845e8c7 100644 --- a/pkg/deployment/resources/inspector/am.go +++ b/pkg/deployment/resources/inspector/am.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -185,11 +185,11 @@ func (p *arangoMembersInspector) Throttle(c throttle.Components) throttle.Thrott func (p *arangoMembersInspector) validate() error { if p == nil { - return errors.Newf("ArangoMemberInspector is nil") + return errors.Errorf("ArangoMemberInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/am_v1.go b/pkg/deployment/resources/inspector/am_v1.go index 554f3fc9f..dc34359e5 100644 --- a/pkg/deployment/resources/inspector/am_v1.go +++ b/pkg/deployment/resources/inspector/am_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,19 +45,19 @@ type arangoMembersInspectorV1 struct { func (p *arangoMembersInspectorV1) validate() error { if p == nil { - return errors.Newf("ArangoMembersV1Inspector is nil") + return errors.Errorf("ArangoMembersV1Inspector is nil") } if p.arangoMemberInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.arangoMembers == nil { - return errors.Newf("ArangoMembers or err should be not nil") + return errors.Errorf("ArangoMembers or err should be not nil") } if p.err != nil { - return errors.Newf("ArangoMembers or err cannot be not nil together") + return errors.Errorf("ArangoMembers or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/at.go b/pkg/deployment/resources/inspector/at.go index 46cd8c55c..d07da7d77 100644 --- a/pkg/deployment/resources/inspector/at.go +++ b/pkg/deployment/resources/inspector/at.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -181,11 +181,11 @@ func (p *arangoTasksInspector) Throttle(c throttle.Components) throttle.Throttle func (p *arangoTasksInspector) validate() error { if p == nil { - return errors.Newf("ArangoTaskInspector is nil") + return errors.Errorf("ArangoTaskInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/at_v1.go b/pkg/deployment/resources/inspector/at_v1.go index b865ab016..9a05d1dcd 100644 --- a/pkg/deployment/resources/inspector/at_v1.go +++ b/pkg/deployment/resources/inspector/at_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,19 +65,19 @@ func (p *arangoTasksInspectorV1) Filter(filters ...ins.Filter) []*api.ArangoTask func (p *arangoTasksInspectorV1) validate() error { if p == nil { - return errors.Newf("ArangoTasksV1Inspector is nil") + return errors.Errorf("ArangoTasksV1Inspector is nil") } if p.arangoTaskInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.arangoTasks == nil && p.err == nil { - return errors.Newf("ArangoTasks or err should be not nil") + return errors.Errorf("ArangoTasks or err should be not nil") } if p.arangoTasks != nil && p.err != nil { - return errors.Newf("ArangoTasks or err cannot be not nil together") + return errors.Errorf("ArangoTasks or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/endpoints.go b/pkg/deployment/resources/inspector/endpoints.go index c0972f971..ce02d6814 100644 --- a/pkg/deployment/resources/inspector/endpoints.go +++ b/pkg/deployment/resources/inspector/endpoints.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -181,11 +181,11 @@ func (p *endpointsInspector) Throttle(c throttle.Components) throttle.Throttle { func (p *endpointsInspector) validate() error { if p == nil { - return errors.Newf("EndpointsInspector is nil") + return errors.Errorf("EndpointsInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/endpoints_v1.go b/pkg/deployment/resources/inspector/endpoints_v1.go index 9c7e1a801..9c502d715 100644 --- a/pkg/deployment/resources/inspector/endpoints_v1.go +++ b/pkg/deployment/resources/inspector/endpoints_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,19 +65,19 @@ func (p *endpointsInspectorV1) Filter(filters ...ins.Filter) []*core.Endpoints { func (p *endpointsInspectorV1) validate() error { if p == nil { - return errors.Newf("EndpointsV1Inspector is nil") + return errors.Errorf("EndpointsV1Inspector is nil") } if p.endpointsInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.endpoints == nil && p.err == nil { - return errors.Newf("Endpoints or err should be not nil") + return errors.Errorf("Endpoints or err should be not nil") } if p.endpoints != nil && p.err != nil { - return errors.Newf("Endpoints or err cannot be not nil together") + return errors.Errorf("Endpoints or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/inspector.go b/pkg/deployment/resources/inspector/inspector.go index ed7b8bfa1..55bcb6d0e 100644 --- a/pkg/deployment/resources/inspector/inspector.go +++ b/pkg/deployment/resources/inspector/inspector.go @@ -232,7 +232,7 @@ func (i *inspectorState) AnonymousObjects() []anonymous.Impl { func (i *inspectorState) GetCurrentArangoDeployment() (*api.ArangoDeployment, error) { if i.deploymentResult == nil { - return nil, errors.Newf("Deployment not initialised") + return nil, errors.Errorf("Deployment not initialised") } return i.deploymentResult.depl, i.deploymentResult.err diff --git a/pkg/deployment/resources/inspector/nodes.go b/pkg/deployment/resources/inspector/nodes.go index 72e64fdfd..6da09e025 100644 --- a/pkg/deployment/resources/inspector/nodes.go +++ b/pkg/deployment/resources/inspector/nodes.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -181,11 +181,11 @@ func (p *nodesInspector) Throttle(c throttle.Components) throttle.Throttle { func (p *nodesInspector) validate() error { if p == nil { - return errors.Newf("NodeInspector is nil") + return errors.Errorf("NodeInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/nodes_v1.go b/pkg/deployment/resources/inspector/nodes_v1.go index b353db0de..5fac5a7b0 100644 --- a/pkg/deployment/resources/inspector/nodes_v1.go +++ b/pkg/deployment/resources/inspector/nodes_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,19 +49,19 @@ type nodesInspectorV1 struct { func (p *nodesInspectorV1) validate() error { if p == nil { - return errors.Newf("NodesV1Inspector is nil") + return errors.Errorf("NodesV1Inspector is nil") } if p.nodeInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.nodes == nil && p.err == nil { - return errors.Newf("Nodes or err should be not nil") + return errors.Errorf("Nodes or err should be not nil") } if p.nodes != nil && p.err != nil { - return errors.Newf("Nodes or err cannot be not nil together") + return errors.Errorf("Nodes or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/pdbs.go b/pkg/deployment/resources/inspector/pdbs.go index 123863337..ac1b7c8ec 100644 --- a/pkg/deployment/resources/inspector/pdbs.go +++ b/pkg/deployment/resources/inspector/pdbs.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -190,11 +190,11 @@ func (p *podDisruptionBudgetsInspector) Throttle(c throttle.Components) throttle func (p *podDisruptionBudgetsInspector) validate() error { if p == nil { - return errors.Newf("PodDisruptionBudgetInspector is nil") + return errors.Errorf("PodDisruptionBudgetInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if err := p.v1.validate(); err != nil { diff --git a/pkg/deployment/resources/inspector/pdbs_v1.go b/pkg/deployment/resources/inspector/pdbs_v1.go index 4bf4ab34c..5a17bfd63 100644 --- a/pkg/deployment/resources/inspector/pdbs_v1.go +++ b/pkg/deployment/resources/inspector/pdbs_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,19 +49,19 @@ type podDisruptionBudgetsInspectorV1 struct { func (p *podDisruptionBudgetsInspectorV1) validate() error { if p == nil { - return errors.Newf("PodDisruptionBudgetsV1Inspector is nil") + return errors.Errorf("PodDisruptionBudgetsV1Inspector is nil") } if p.podDisruptionBudgetInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.podDisruptionBudgets == nil && p.err == nil { - return errors.Newf("PodDisruptionBudgets or err should be not nil") + return errors.Errorf("PodDisruptionBudgets or err should be not nil") } if p.podDisruptionBudgets != nil && p.err != nil { - return errors.Newf("PodDisruptionBudgets or err cannot be not nil together") + return errors.Errorf("PodDisruptionBudgets or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/pods.go b/pkg/deployment/resources/inspector/pods.go index 3d4030b93..af3dc4092 100644 --- a/pkg/deployment/resources/inspector/pods.go +++ b/pkg/deployment/resources/inspector/pods.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -185,11 +185,11 @@ func (p *podsInspector) Throttle(c throttle.Components) throttle.Throttle { func (p *podsInspector) validate() error { if p == nil { - return errors.Newf("PodInspector is nil") + return errors.Errorf("PodInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/pods_v1.go b/pkg/deployment/resources/inspector/pods_v1.go index 1b99387cf..23c562bfa 100644 --- a/pkg/deployment/resources/inspector/pods_v1.go +++ b/pkg/deployment/resources/inspector/pods_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,19 +46,19 @@ type podsInspectorV1 struct { func (p *podsInspectorV1) validate() error { if p == nil { - return errors.Newf("PodsV1Inspector is nil") + return errors.Errorf("PodsV1Inspector is nil") } if p.podInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.pods == nil { - return errors.Newf("Pods or err should be not nil") + return errors.Errorf("Pods or err should be not nil") } if p.err != nil { - return errors.Newf("Pods or err cannot be not nil together") + return errors.Errorf("Pods or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/pvcs.go b/pkg/deployment/resources/inspector/pvcs.go index c0a64237c..9ecdc11f8 100644 --- a/pkg/deployment/resources/inspector/pvcs.go +++ b/pkg/deployment/resources/inspector/pvcs.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -185,11 +185,11 @@ func (p *persistentVolumeClaimsInspector) Throttle(c throttle.Components) thrott func (p *persistentVolumeClaimsInspector) validate() error { if p == nil { - return errors.Newf("PersistentVolumeClaimInspector is nil") + return errors.Errorf("PersistentVolumeClaimInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/pvcs_v1.go b/pkg/deployment/resources/inspector/pvcs_v1.go index fb9459a97..e375a31ca 100644 --- a/pkg/deployment/resources/inspector/pvcs_v1.go +++ b/pkg/deployment/resources/inspector/pvcs_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,19 +45,19 @@ type persistentVolumeClaimsInspectorV1 struct { func (p *persistentVolumeClaimsInspectorV1) validate() error { if p == nil { - return errors.Newf("PersistentVolumeClaimsV1Inspector is nil") + return errors.Errorf("PersistentVolumeClaimsV1Inspector is nil") } if p.persistentVolumeClaimInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.persistentVolumeClaims == nil { - return errors.Newf("PersistentVolumeClaims or err should be not nil") + return errors.Errorf("PersistentVolumeClaims or err should be not nil") } if p.err != nil { - return errors.Newf("PersistentVolumeClaims or err cannot be not nil together") + return errors.Errorf("PersistentVolumeClaims or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/pvs.go b/pkg/deployment/resources/inspector/pvs.go index 7965e962b..2ef931ea8 100644 --- a/pkg/deployment/resources/inspector/pvs.go +++ b/pkg/deployment/resources/inspector/pvs.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -181,11 +181,11 @@ func (p *persistentVolumesInspector) Throttle(c throttle.Components) throttle.Th func (p *persistentVolumesInspector) validate() error { if p == nil { - return errors.Newf("PersistentVolumeInspector is nil") + return errors.Errorf("PersistentVolumeInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/pvs_v1.go b/pkg/deployment/resources/inspector/pvs_v1.go index 3b775afe6..818762e95 100644 --- a/pkg/deployment/resources/inspector/pvs_v1.go +++ b/pkg/deployment/resources/inspector/pvs_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,19 +49,19 @@ type persistentVolumesInspectorV1 struct { func (p *persistentVolumesInspectorV1) validate() error { if p == nil { - return errors.Newf("PersistentVolumesV1Inspector is nil") + return errors.Errorf("PersistentVolumesV1Inspector is nil") } if p.persistentVolumeInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.persistentVolumes == nil && p.err == nil { - return errors.Newf("PersistentVolumes or err should be not nil") + return errors.Errorf("PersistentVolumes or err should be not nil") } if p.persistentVolumes != nil && p.err != nil { - return errors.Newf("PersistentVolumes or err cannot be not nil together") + return errors.Errorf("PersistentVolumes or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/sa.go b/pkg/deployment/resources/inspector/sa.go index 8b6d19a6a..a9896ee92 100644 --- a/pkg/deployment/resources/inspector/sa.go +++ b/pkg/deployment/resources/inspector/sa.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -185,11 +185,11 @@ func (p *serviceAccountsInspector) Throttle(c throttle.Components) throttle.Thro func (p *serviceAccountsInspector) validate() error { if p == nil { - return errors.Newf("ServiceAccountInspector is nil") + return errors.Errorf("ServiceAccountInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/sa_v1.go b/pkg/deployment/resources/inspector/sa_v1.go index a9cde5a18..1746b8275 100644 --- a/pkg/deployment/resources/inspector/sa_v1.go +++ b/pkg/deployment/resources/inspector/sa_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,19 +45,19 @@ type serviceAccountsInspectorV1 struct { func (p *serviceAccountsInspectorV1) validate() error { if p == nil { - return errors.Newf("ServiceAccountsV1Inspector is nil") + return errors.Errorf("ServiceAccountsV1Inspector is nil") } if p.serviceAccountInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.serviceAccounts == nil { - return errors.Newf("ServiceAccounts or err should be not nil") + return errors.Errorf("ServiceAccounts or err should be not nil") } if p.err != nil { - return errors.Newf("ServiceAccounts or err cannot be not nil together") + return errors.Errorf("ServiceAccounts or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/secrets.go b/pkg/deployment/resources/inspector/secrets.go index dce402279..326b25b8c 100644 --- a/pkg/deployment/resources/inspector/secrets.go +++ b/pkg/deployment/resources/inspector/secrets.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -185,11 +185,11 @@ func (p *secretsInspector) Throttle(c throttle.Components) throttle.Throttle { func (p *secretsInspector) validate() error { if p == nil { - return errors.Newf("SecretInspector is nil") + return errors.Errorf("SecretInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/secrets_v1.go b/pkg/deployment/resources/inspector/secrets_v1.go index b18ac7259..6925d8f5f 100644 --- a/pkg/deployment/resources/inspector/secrets_v1.go +++ b/pkg/deployment/resources/inspector/secrets_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,19 +45,19 @@ type secretsInspectorV1 struct { func (p *secretsInspectorV1) validate() error { if p == nil { - return errors.Newf("SecretsV1Inspector is nil") + return errors.Errorf("SecretsV1Inspector is nil") } if p.secretInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.secrets == nil { - return errors.Newf("Secrets or err should be not nil") + return errors.Errorf("Secrets or err should be not nil") } if p.err != nil { - return errors.Newf("Secrets or err cannot be not nil together") + return errors.Errorf("Secrets or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/services.go b/pkg/deployment/resources/inspector/services.go index a44c10879..58e210e4d 100644 --- a/pkg/deployment/resources/inspector/services.go +++ b/pkg/deployment/resources/inspector/services.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -185,11 +185,11 @@ func (p *servicesInspector) Throttle(c throttle.Components) throttle.Throttle { func (p *servicesInspector) validate() error { if p == nil { - return errors.Newf("ServiceInspector is nil") + return errors.Errorf("ServiceInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/services_v1.go b/pkg/deployment/resources/inspector/services_v1.go index f3cc9e9cd..0cfd4384f 100644 --- a/pkg/deployment/resources/inspector/services_v1.go +++ b/pkg/deployment/resources/inspector/services_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,19 +45,19 @@ type servicesInspectorV1 struct { func (p *servicesInspectorV1) validate() error { if p == nil { - return errors.Newf("ServicesV1Inspector is nil") + return errors.Errorf("ServicesV1Inspector is nil") } if p.serviceInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.services == nil { - return errors.Newf("Services or err should be not nil") + return errors.Errorf("Services or err should be not nil") } if p.err != nil { - return errors.Newf("Services or err cannot be not nil together") + return errors.Errorf("Services or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/inspector/sm.go b/pkg/deployment/resources/inspector/sm.go index ec5cfb18e..1f1e59700 100644 --- a/pkg/deployment/resources/inspector/sm.go +++ b/pkg/deployment/resources/inspector/sm.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -177,11 +177,11 @@ func (p *serviceMonitorsInspector) Throttle(c throttle.Components) throttle.Thro func (p *serviceMonitorsInspector) validate() error { if p == nil { - return errors.Newf("ServiceMonitorInspector is nil") + return errors.Errorf("ServiceMonitorInspector is nil") } if p.state == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } return p.v1.validate() diff --git a/pkg/deployment/resources/inspector/sm_v1.go b/pkg/deployment/resources/inspector/sm_v1.go index 2c071f186..53c6258a7 100644 --- a/pkg/deployment/resources/inspector/sm_v1.go +++ b/pkg/deployment/resources/inspector/sm_v1.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,19 +49,19 @@ type serviceMonitorsInspectorV1 struct { func (p *serviceMonitorsInspectorV1) validate() error { if p == nil { - return errors.Newf("ServiceMonitorsV1Inspector is nil") + return errors.Errorf("ServiceMonitorsV1Inspector is nil") } if p.serviceMonitorInspector == nil { - return errors.Newf("Parent is nil") + return errors.Errorf("Parent is nil") } if p.serviceMonitors == nil && p.err == nil { - return errors.Newf("ServiceMonitors or err should be not nil") + return errors.Errorf("ServiceMonitors or err should be not nil") } if p.serviceMonitors != nil && p.err != nil { - return errors.Newf("ServiceMonitors or err cannot be not nil together") + return errors.Errorf("ServiceMonitors or err cannot be not nil together") } return nil diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 2825701f1..4656a364d 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -306,7 +306,7 @@ func (r *Resources) RenderPodForMember(ctx context.Context, acs sutil.ACS, spec apiObject := r.context.GetAPIObject() m, group, found := status.Members.ElementByID(memberID) if !found { - return nil, errors.WithStack(errors.Newf("Member '%s' not found", memberID)) + return nil, errors.WithStack(errors.Errorf("Member '%s' not found", memberID)) } groupSpec := spec.GetServerGroupSpec(group) @@ -314,16 +314,16 @@ func (r *Resources) RenderPodForMember(ctx context.Context, acs sutil.ACS, spec member, ok := acs.CurrentClusterCache().ArangoMember().V1().GetSimple(memberName) if !ok { - return nil, errors.Newf("ArangoMember %s not found", memberName) + return nil, errors.Errorf("ArangoMember %s not found", memberName) } cluster, ok := acs.Cluster(m.ClusterID) if !ok { - return nil, errors.Newf("Cluster is not found") + return nil, errors.Errorf("Cluster is not found") } if !cluster.Ready() { - return nil, errors.Newf("Cluster is not ready") + return nil, errors.Errorf("Cluster is not ready") } cache := cluster.Cache() @@ -357,7 +357,7 @@ func (r *Resources) RenderPodForMember(ctx context.Context, acs sutil.ACS, spec // Check image if !imageInfo.Enterprise { log.Str("image", spec.GetImage()).Debug("Image is not an enterprise image") - return nil, errors.WithStack(errors.Newf("Image '%s' does not contain an Enterprise version of ArangoDB", spec.GetImage())) + return nil, errors.WithStack(errors.Errorf("Image '%s' does not contain an Enterprise version of ArangoDB", spec.GetImage())) } // Check if the sync image is overwritten by the SyncSpec imageInfo := imageInfo @@ -378,7 +378,7 @@ func (r *Resources) RenderPodForMember(ctx context.Context, acs sutil.ACS, spec cachedStatus: cache, } } else { - return nil, errors.Newf("unable to render Pod") + return nil, errors.Errorf("unable to render Pod") } pod, err := RenderArangoPod(ctx, cache, apiObject, role, m.ID, podName, podCreator) @@ -439,7 +439,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect if template == nil { // Template not yet propagated - return errors.Newf("Template not yet propagated") + return errors.Errorf("Template not yet propagated") } if status.CurrentImage == nil { @@ -460,7 +460,7 @@ func (r *Resources) createPodForMember(ctx context.Context, cachedStatus inspect apiObject := r.context.GetAPIObject() if !found { - return errors.WithStack(errors.Newf("Member '%s' not found", memberID)) + return errors.WithStack(errors.Errorf("Member '%s' not found", memberID)) } // Update pod name diff --git a/pkg/deployment/resources/pod_termination.go b/pkg/deployment/resources/pod_termination.go index 9039aea5f..99ef7168e 100644 --- a/pkg/deployment/resources/pod_termination.go +++ b/pkg/deployment/resources/pod_termination.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -71,7 +71,7 @@ func (r *Resources) prepareAgencyPodTermination(p *core.Pod, memberStatus api.Me pvc, ok := r.context.ACS().CurrentClusterCache().PersistentVolumeClaim().V1().GetSimple(memberStatus.PersistentVolumeClaim.GetName()) if !ok { log.Warn("Failed to get PVC for member") - return errors.Newf("Failed to get PVC for member") + return errors.Errorf("Failed to get PVC for member") } if k8sutil.IsPersistentVolumeClaimMarkedForDeletion(pvc) { agentDataWillBeGone = true @@ -89,11 +89,11 @@ func (r *Resources) prepareAgencyPodTermination(p *core.Pod, memberStatus api.Me agencyHealth, ok := r.context.GetAgencyHealth() if !ok { log.Debug("Agency health fetch failed") - return errors.Newf("Agency health fetch failed") + return errors.Errorf("Agency health fetch failed") } if err := agencyHealth.Healthy(); err != nil { log.Err(err).Debug("Agency is not healthy. Cannot delete this one") - return errors.WithStack(errors.Newf("Agency is not healthy")) + return errors.WithStack(errors.Errorf("Agency is not healthy")) } // Complete agent recovery is needed, since data is already gone or not accessible if memberStatus.Conditions.Update(api.ConditionTypeAgentRecoveryNeeded, true, "Data Gone", "") { @@ -252,7 +252,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, p *core.P // Check the job progress cache, ok := r.context.GetAgencyCache() if !ok { - return errors.Newf("AgencyCache is not ready") + return errors.Errorf("AgencyCache is not ready") } details, jobStatus := cache.Target.GetJob(state.JobID(memberStatus.CleanoutJobID)) @@ -275,7 +275,7 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, p *core.P // Check the job progress cache, ok := r.context.GetAgencyCache() if !ok { - return errors.Newf("AgencyCache is not ready") + return errors.Errorf("AgencyCache is not ready") } details, jobStatus := cache.Target.GetJob(state.JobID(memberStatus.CleanoutJobID)) @@ -301,6 +301,6 @@ func (r *Resources) prepareDBServerPodTermination(ctx context.Context, p *core.P } } - return errors.WithStack(errors.Newf("Server is not yet cleaned out")) + return errors.WithStack(errors.Errorf("Server is not yet cleaned out")) } diff --git a/pkg/deployment/resources/pvc_finalizers.go b/pkg/deployment/resources/pvc_finalizers.go index 4d5745f9e..537b6e877 100644 --- a/pkg/deployment/resources/pvc_finalizers.go +++ b/pkg/deployment/resources/pvc_finalizers.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -121,5 +121,5 @@ func (r *Resources) inspectFinalizerPVCMemberExists(ctx context.Context, group a } } - return errors.WithStack(errors.Newf("Member still exists")) + return errors.WithStack(errors.Errorf("Member still exists")) } diff --git a/pkg/deployment/resources/secrets.go b/pkg/deployment/resources/secrets.go index 190b79a36..23cab190b 100644 --- a/pkg/deployment/resources/secrets.go +++ b/pkg/deployment/resources/secrets.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -136,12 +136,12 @@ func (r *Resources) EnsureSecrets(ctx context.Context, cachedStatus inspectorInt member, ok := cachedStatus.ArangoMember().V1().GetSimple(memberName) if !ok { - return errors.Newf("Member %s not found", memberName) + return errors.Errorf("Member %s not found", memberName) } service, ok := cachedStatus.Service().V1().GetSimple(memberName) if !ok { - return errors.Newf("Service of member %s not found", memberName) + return errors.Errorf("Service of member %s not found", memberName) } tlsKeyfileSecretName := k8sutil.AppendTLSKeyfileSecretPostfix(member.GetName()) @@ -195,12 +195,12 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in if len(f.Data) == 0 { s, exists := cachedStatus.Secret().V1().GetSimple(secretName) if !exists { - return errors.Newf("Token secret does not exist") + return errors.Errorf("Token secret does not exist") } token, ok := s.Data[constants.SecretKeyToken] if !ok { - return errors.Newf("Token secret is invalid") + return errors.Errorf("Token secret is invalid") } f.Data[util.SHA256(token)] = token @@ -221,7 +221,7 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in if _, ok := f.Data[pod.ActiveJWTKey]; !ok { _, b, ok := getFirstKeyFromMap(f.Data) if !ok { - return errors.Newf("Token Folder secret is invalid") + return errors.Errorf("Token Folder secret is invalid") } p := patch.NewPatch() @@ -244,7 +244,7 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in if _, ok := f.Data[constants.SecretKeyToken]; !ok { b, ok := f.Data[pod.ActiveJWTKey] if !ok { - return errors.Newf("Token Folder secret is invalid") + return errors.Errorf("Token Folder secret is invalid") } p := patch.NewPatch() @@ -269,12 +269,12 @@ func (r *Resources) ensureTokenSecretFolder(ctx context.Context, cachedStatus in s, exists := cachedStatus.Secret().V1().GetSimple(secretName) if !exists { - return errors.Newf("Token secret does not exist") + return errors.Errorf("Token secret does not exist") } token, ok := s.Data[constants.SecretKeyToken] if !ok { - return errors.Newf("Token secret is invalid") + return errors.Errorf("Token secret is invalid") } if err := r.createSecretWithMod(ctx, secrets, folderSecretName, func(s *core.Secret) { @@ -365,14 +365,14 @@ func (r *Resources) ensureEncryptionKeyfolderSecret(ctx context.Context, cachedS if folderExists { return nil } - return errors.Newf("Unable to find original secret %s", keyfileSecretName) + return errors.Errorf("Unable to find original secret %s", keyfileSecretName) } if len(keyfile.Data) == 0 { if folderExists { return nil } - return errors.Newf("Missing key in secret") + return errors.Errorf("Missing key in secret") } d, ok := keyfile.Data[constants.SecretEncryptionKey] @@ -380,7 +380,7 @@ func (r *Resources) ensureEncryptionKeyfolderSecret(ctx context.Context, cachedS if folderExists { return nil } - return errors.Newf("Missing key in secret") + return errors.Errorf("Missing key in secret") } owner := r.context.GetAPIObject().AsOwner() @@ -467,7 +467,7 @@ func (r *Resources) ensureExporterTokenSecretCreateRequired(cachedStatus inspect jwtSecret, exists := cachedStatus.Secret().V1().GetSimple(secretSecretName) if !exists { - return true, true, errors.Newf("Secret %s does not exists", secretSecretName) + return true, true, errors.Errorf("Secret %s does not exists", secretSecretName) } secret, err := k8sutil.GetTokenFromSecret(jwtSecret) diff --git a/pkg/deployment/resources/servicemonitor.go b/pkg/deployment/resources/servicemonitor.go index a194c3fb0..d02b44d8b 100644 --- a/pkg/deployment/resources/servicemonitor.go +++ b/pkg/deployment/resources/servicemonitor.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2019-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2019-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -145,7 +145,7 @@ func (r *Resources) EnsureServiceMonitor(ctx context.Context, enabled bool) erro client, ok := kclient.GetDefaultFactory().Client() if !ok { log.Error("Cannot get a monitoring client.") - return errors.Newf("Client not initialised") + return errors.Errorf("Client not initialised") } mClient := client.Monitoring() diff --git a/pkg/deployment/resources/services.go b/pkg/deployment/resources/services.go index 34395ae02..c3e4920aa 100644 --- a/pkg/deployment/resources/services.go +++ b/pkg/deployment/resources/services.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -95,7 +95,7 @@ func (r *Resources) EnsureServices(ctx context.Context, cachedStatus inspectorIn member, ok := cachedStatus.ArangoMember().V1().GetSimple(memberName) if !ok { - return errors.Newf("Member %s not found", memberName) + return errors.Errorf("Member %s not found", memberName) } ports := CreateServerServicePortsWithSidecars(amInspector, e.Member.ArangoMemberName(deploymentName, e.Group)) diff --git a/pkg/exporter/monitor.go b/pkg/exporter/monitor.go index b0b6b5e4d..b9932938e 100644 --- a/pkg/exporter/monitor.go +++ b/pkg/exporter/monitor.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ package exporter import ( "context" "encoding/json" - "errors" "fmt" "io" "net/url" @@ -38,6 +37,7 @@ import ( shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/logging" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/timer" ) diff --git a/pkg/handlers/backup/arango_client_impl.go b/pkg/handlers/backup/arango_client_impl.go index 06ca093a7..c4bfe2d59 100644 --- a/pkg/handlers/backup/arango_client_impl.go +++ b/pkg/handlers/backup/arango_client_impl.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -190,7 +190,7 @@ func (ac *arangoClientBackupImpl) Upload(backupID driver.BackupID) (driver.Backu uploadSpec := ac.backup.Spec.Upload if uploadSpec == nil { - return "", errors.Newf("upload was called but no upload spec was given") + return "", errors.Errorf("upload was called but no upload spec was given") } cred, err := ac.getCredentialsFromSecret(ctx, uploadSpec.CredentialsSecretName) @@ -207,7 +207,7 @@ func (ac *arangoClientBackupImpl) Download(backupID driver.BackupID) (driver.Bac downloadSpec := ac.backup.Spec.Download if downloadSpec == nil { - return "", errors.Newf("Download was called but not download spec was given") + return "", errors.Errorf("Download was called but not download spec was given") } cred, err := ac.getCredentialsFromSecret(ctx, downloadSpec.CredentialsSecretName) @@ -254,7 +254,7 @@ func (ac *arangoClientBackupImpl) Progress(jobID driver.BackupTransferJobID) (Ar case "": completedCount++ default: - return ArangoBackupProgress{}, errors.Newf("Unknown transfer status: %s", status.Status) + return ArangoBackupProgress{}, errors.Errorf("Unknown transfer status: %s", status.Status) } } diff --git a/pkg/handlers/backup/arango_client_mock_test.go b/pkg/handlers/backup/arango_client_mock_test.go index a1b4ca664..8ada1a85e 100644 --- a/pkg/handlers/backup/arango_client_mock_test.go +++ b/pkg/handlers/backup/arango_client_mock_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -185,7 +185,7 @@ func (m *mockArangoClientBackup) Get(id driver.BackupID) (driver.BackupMeta, err return meta, nil } - return driver.BackupMeta{}, errors.Newf("not found") + return driver.BackupMeta{}, errors.Errorf("not found") } func (m *mockArangoClientBackup) Create() (ArangoBackupCreateResponse, error) { diff --git a/pkg/handlers/backup/backup_suite_test.go b/pkg/handlers/backup/backup_suite_test.go index 61c8c733e..db5a5d04d 100644 --- a/pkg/handlers/backup/backup_suite_test.go +++ b/pkg/handlers/backup/backup_suite_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -188,7 +188,7 @@ func wrapperConnectionIssues(t *testing.T, state state.State) { // Arrange handler := newFakeHandler() - f := newMockArangoClientBackupErrorFactory(errors.Newf(errorString)) + f := newMockArangoClientBackupErrorFactory(errors.Errorf(errorString)) handler.arangoClientFactory = f obj, deployment := newObjectSet(t, state) diff --git a/pkg/handlers/backup/errors.go b/pkg/handlers/backup/errors.go index 5acf7a924..441bbdeb8 100644 --- a/pkg/handlers/backup/errors.go +++ b/pkg/handlers/backup/errors.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ func newTemporaryError(err error) error { } func newTemporaryErrorf(format string, a ...interface{}) error { - return newTemporaryError(errors.Newf(format, a...)) + return newTemporaryError(errors.Errorf(format, a...)) } type temporaryError struct { @@ -58,7 +58,7 @@ func newFatalError(err error) error { } func newFatalErrorf(format string, a ...interface{}) error { - return newFatalError(errors.Newf(format, a...)) + return newFatalError(errors.Errorf(format, a...)) } type fatalError struct { diff --git a/pkg/handlers/backup/handler.go b/pkg/handlers/backup/handler.go index 2e4a1da54..c8521c35f 100644 --- a/pkg/handlers/backup/handler.go +++ b/pkg/handlers/backup/handler.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ package backup import ( "context" - "errors" "fmt" "sync" "time" @@ -44,7 +43,7 @@ import ( "github.com/arangodb/kube-arangodb/pkg/operatorV2/event" "github.com/arangodb/kube-arangodb/pkg/operatorV2/operation" "github.com/arangodb/kube-arangodb/pkg/util" - adbErrors "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) var logger = logging.Global().RegisterAndGetLogger("backup-operator", logging.Info) @@ -348,7 +347,7 @@ func (h *handler) processArangoBackup(backup *backupApi.ArangoBackup) (*backupAp return f(h, backup) } - return nil, adbErrors.Newf("state %s is not supported", backup.Status.State) + return nil, errors.Errorf("state %s is not supported", backup.Status.State) } func (h *handler) CanBeHandled(item operation.Item) bool { diff --git a/pkg/ml/storage/s3/s3.go b/pkg/ml/storage/s3/s3.go index dba098283..e610dd3d4 100644 --- a/pkg/ml/storage/s3/s3.go +++ b/pkg/ml/storage/s3/s3.go @@ -1,5 +1,5 @@ // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ package s3 +import "github.com/arangodb/kube-arangodb/pkg/util/errors" + type Config struct { Endpoint string AllowInsecure bool @@ -29,3 +31,16 @@ type Config struct { AccessKeyFile string // path to file containing S3 AccessKey SecretKeyFile string // path to file containing S3 SecretKey } + +func (c Config) Validate() error { + if c.AccessKeyFile == "" { + return errors.Errorf("AccessKeyFile is not defined") + } + if c.SecretKeyFile == "" { + return errors.Errorf("SecretKeyFile is not defined") + } + if c.Endpoint == "" { + return errors.Errorf("Endpoint is not defined") + } + return nil +} diff --git a/pkg/ml/storage/service.community.go b/pkg/ml/storage/service.community.go index 29c574730..37da8a431 100644 --- a/pkg/ml/storage/service.community.go +++ b/pkg/ml/storage/service.community.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,11 +24,11 @@ package storage import ( "context" - "errors" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/svc" ) -func NewService(_ context.Context, _ StorageType, _ ServiceConfig) (svc.Service, error) { +func NewService(_ context.Context, _ StorageType, _ ServiceConfig) (svc.Handler, error) { return nil, errors.New("this service is available only in enterprise edition of operator") } diff --git a/pkg/ml/storage/service.go b/pkg/ml/storage/service.go index 5548a2822..9b892d474 100644 --- a/pkg/ml/storage/service.go +++ b/pkg/ml/storage/service.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ package storage import ( "github.com/arangodb/kube-arangodb/pkg/ml/storage/s3" + "github.com/arangodb/kube-arangodb/pkg/util/svc" ) type StorageType string @@ -31,6 +32,6 @@ const ( ) type ServiceConfig struct { - ListenAddress string + Configuration svc.Configuration S3 s3.Config } diff --git a/pkg/operator/operator_deployment.go b/pkg/operator/operator_deployment.go index c18486daa..2c4f7e581 100644 --- a/pkg/operator/operator_deployment.go +++ b/pkg/operator/operator_deployment.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -146,13 +146,13 @@ func (o *Operator) handleDeploymentEvent(event *Event) error { delete(o.deployments, apiObject.Name) return nil } - return errors.WithStack(errors.Newf("ignore failed deployment (%s). Please delete its CR", apiObject.Name)) + return errors.WithStack(errors.Errorf("ignore failed deployment (%s). Please delete its CR", apiObject.Name)) } switch event.Type { case kwatch.Added: if _, ok := o.deployments[apiObject.Name]; ok { - return errors.WithStack(errors.Newf("unsafe state. deployment (%s) was created before but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. deployment (%s) was created before but we received event (%s)", apiObject.Name, event.Type)) } // Fill in defaults @@ -165,7 +165,7 @@ func (o *Operator) handleDeploymentEvent(event *Event) error { cfg, deps := o.makeDeploymentConfigAndDeps() nc, err := deployment.New(cfg, deps, apiObject) if err != nil { - return errors.WithStack(errors.Newf("failed to create deployment: %s", err)) + return errors.WithStack(errors.Errorf("failed to create deployment: %s", err)) } o.deployments[apiObject.Name] = nc @@ -175,7 +175,7 @@ func (o *Operator) handleDeploymentEvent(event *Event) error { case kwatch.Modified: depl, ok := o.deployments[apiObject.Name] if !ok { - return errors.WithStack(errors.Newf("unsafe state. deployment (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. deployment (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) } depl.Update(apiObject) deploymentsModified.Inc() @@ -183,7 +183,7 @@ func (o *Operator) handleDeploymentEvent(event *Event) error { case kwatch.Deleted: depl, ok := o.deployments[apiObject.Name] if !ok { - return errors.WithStack(errors.Newf("unsafe state. deployment (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. deployment (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) } depl.Stop() delete(o.deployments, apiObject.Name) diff --git a/pkg/operator/operator_deployment_replication.go b/pkg/operator/operator_deployment_replication.go index f4df2cff6..64b941839 100644 --- a/pkg/operator/operator_deployment_replication.go +++ b/pkg/operator/operator_deployment_replication.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -148,13 +148,13 @@ func (o *Operator) handleDeploymentReplicationEvent(event *Event) error { delete(o.deploymentReplications, apiObject.Name) return nil } - return errors.WithStack(errors.Newf("ignore failed deployment replication (%s). Please delete its CR", apiObject.Name)) + return errors.WithStack(errors.Errorf("ignore failed deployment replication (%s). Please delete its CR", apiObject.Name)) } switch event.Type { case kwatch.Added: if _, ok := o.deploymentReplications[apiObject.Name]; ok { - return errors.WithStack(errors.Newf("unsafe state. deployment replication (%s) was created before but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. deployment replication (%s) was created before but we received event (%s)", apiObject.Name, event.Type)) } // Fill in defaults @@ -167,7 +167,7 @@ func (o *Operator) handleDeploymentReplicationEvent(event *Event) error { cfg, deps := o.makeDeploymentReplicationConfigAndDeps() nc, err := replication.New(cfg, deps, apiObject) if err != nil { - return errors.WithStack(errors.Newf("failed to create deployment: %s", err)) + return errors.WithStack(errors.Errorf("failed to create deployment: %s", err)) } o.deploymentReplications[apiObject.Name] = nc @@ -177,7 +177,7 @@ func (o *Operator) handleDeploymentReplicationEvent(event *Event) error { case kwatch.Modified: repl, ok := o.deploymentReplications[apiObject.Name] if !ok { - return errors.WithStack(errors.Newf("unsafe state. deployment replication (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. deployment replication (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) } repl.Update(apiObject) deploymentReplicationsModified.Inc() @@ -185,7 +185,7 @@ func (o *Operator) handleDeploymentReplicationEvent(event *Event) error { case kwatch.Deleted: repl, ok := o.deploymentReplications[apiObject.Name] if !ok { - return errors.WithStack(errors.Newf("unsafe state. deployment replication (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. deployment replication (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) } repl.Delete() delete(o.deploymentReplications, apiObject.Name) diff --git a/pkg/operator/operator_local_storage.go b/pkg/operator/operator_local_storage.go index a58f6764c..800b64911 100644 --- a/pkg/operator/operator_local_storage.go +++ b/pkg/operator/operator_local_storage.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -147,7 +147,7 @@ func (o *Operator) handleLocalStorageEvent(event *Event) error { delete(o.localStorages, apiObject.Name) return nil } - return errors.WithStack(errors.Newf("ignore failed local storage (%s). Please delete its CR", apiObject.Name)) + return errors.WithStack(errors.Errorf("ignore failed local storage (%s). Please delete its CR", apiObject.Name)) } // Fill in defaults @@ -160,13 +160,13 @@ func (o *Operator) handleLocalStorageEvent(event *Event) error { switch event.Type { case kwatch.Added: if _, ok := o.localStorages[apiObject.Name]; ok { - return errors.WithStack(errors.Newf("unsafe state. local storage (%s) was created before but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. local storage (%s) was created before but we received event (%s)", apiObject.Name, event.Type)) } cfg, deps := o.makeLocalStorageConfigAndDeps() stg, err := storage.New(cfg, deps, apiObject) if err != nil { - return errors.WithStack(errors.Newf("failed to create local storage: %s", err)) + return errors.WithStack(errors.Errorf("failed to create local storage: %s", err)) } o.localStorages[apiObject.Name] = stg @@ -176,7 +176,7 @@ func (o *Operator) handleLocalStorageEvent(event *Event) error { case kwatch.Modified: stg, ok := o.localStorages[apiObject.Name] if !ok { - return errors.WithStack(errors.Newf("unsafe state. local storage (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. local storage (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) } stg.Update(apiObject) localStoragesModified.Inc() @@ -184,7 +184,7 @@ func (o *Operator) handleLocalStorageEvent(event *Event) error { case kwatch.Deleted: stg, ok := o.localStorages[apiObject.Name] if !ok { - return errors.WithStack(errors.Newf("unsafe state. local storage (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) + return errors.WithStack(errors.Errorf("unsafe state. local storage (%s) was never created but we received event (%s)", apiObject.Name, event.Type)) } stg.Delete() delete(o.localStorages, apiObject.Name) diff --git a/pkg/operatorV2/operation/item.go b/pkg/operatorV2/operation/item.go index 78da7c123..546a8b4b5 100644 --- a/pkg/operatorV2/operation/item.go +++ b/pkg/operatorV2/operation/item.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ func NewItemFromString(itemString string) (Item, error) { parts := strings.Split(itemString, "/") if len(parts) != 6 { - return Item{}, errors.Newf("expected 6 parts in %s, got %d", itemString, len(parts)) + return Item{}, errors.Errorf("expected 6 parts in %s, got %d", itemString, len(parts)) } return NewItem(Operation(parts[0]), parts[1], parts[2], parts[3], parts[4], parts[5]) @@ -94,11 +94,11 @@ type Item struct { func validateField(name, value string, allowEmpty bool) error { if !allowEmpty && value == "" { - return errors.Newf(emptyError, name) + return errors.Errorf(emptyError, name) } if index := strings.Index(value, separator); index != -1 { - return errors.Newf(invalidCharacterError, separator, name) + return errors.Errorf(invalidCharacterError, separator, name) } return nil diff --git a/pkg/operatorV2/operator.go b/pkg/operatorV2/operator.go index 4010a5851..a192a69f9 100644 --- a/pkg/operatorV2/operator.go +++ b/pkg/operatorV2/operator.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -109,7 +109,7 @@ func (o *operator) ProcessItem(item operation.Item) error { defer o.lock.Unlock() if !o.started { - return errors.Newf("operator is not started started") + return errors.Errorf("operator is not started started") } } @@ -121,12 +121,12 @@ func (o *operator) RegisterHandler(handler Handler) error { defer o.lock.Unlock() if o.started { - return errors.Newf("operator already started") + return errors.Errorf("operator already started") } for _, registeredHandlers := range o.handlers { if registeredHandlers == handler { - return errors.Newf("handler already registered") + return errors.Errorf("handler already registered") } } @@ -140,12 +140,12 @@ func (o *operator) RegisterStarter(starter Starter) error { defer o.lock.Unlock() if o.started { - return errors.Newf("operator already started") + return errors.Errorf("operator already started") } for _, registeredStarter := range o.starters { if registeredStarter == starter { - return errors.Newf("starter already registered") + return errors.Errorf("starter already registered") } } @@ -163,12 +163,12 @@ func (o *operator) RegisterInformer(informer cache.SharedIndexInformer, group, v defer o.lock.Unlock() if o.started { - return errors.Newf("operator already started") + return errors.Errorf("operator already started") } for _, registeredInformer := range o.informers { if registeredInformer == informer { - return errors.Newf("informer already registered") + return errors.Errorf("informer already registered") } } @@ -184,7 +184,7 @@ func (o *operator) Start(threadiness int, stopCh <-chan struct{}) error { defer o.lock.Unlock() if o.started { - return errors.Newf("operator already started") + return errors.Errorf("operator already started") } o.started = true @@ -227,7 +227,7 @@ func (o *operator) waitForCacheSync(stopCh <-chan struct{}) error { } if ok := cache.WaitForCacheSync(stopCh, cacheSync...); !ok { - return errors.Newf("cache can not sync") + return errors.Errorf("cache can not sync") } return nil diff --git a/pkg/operatorV2/operator_worker.go b/pkg/operatorV2/operator_worker.go index 99b1febf5..83913e7da 100644 --- a/pkg/operatorV2/operator_worker.go +++ b/pkg/operatorV2/operator_worker.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -112,7 +112,7 @@ func (o *operator) processObject(obj interface{}) error { if !IsReconcile(err) { message := fmt.Sprintf("error syncing '%s': %s, re-queuing", key, err.Error()) loggerWorker.Debug(message) - return errors.Newf(message) + return errors.Errorf(message) } return nil diff --git a/pkg/operatorV2/update.go b/pkg/operatorV2/update.go index 3e55ac15e..cdc16f54e 100644 --- a/pkg/operatorV2/update.go +++ b/pkg/operatorV2/update.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ func WithUpdateStatusInterfaceRetry[S interface{}, T Object[S]](ctx context.Cont } } - return util.Default[T](), errors.Newf("Unable to save Object %s/%s, retries exceeded", obj.GetNamespace(), obj.GetName()) + return util.Default[T](), errors.Errorf("Unable to save Object %s/%s, retries exceeded", obj.GetNamespace(), obj.GetName()) } func WithUpdateStatusInterface[S interface{}, T Object[S]](ctx context.Context, client UpdateStatusInterface[S, T], obj T, status S, opts meta.UpdateOptions) (T, error) { diff --git a/pkg/replication/deployment_replication.go b/pkg/replication/deployment_replication.go index 0f2f9a2c1..ea217d242 100644 --- a/pkg/replication/deployment_replication.go +++ b/pkg/replication/deployment_replication.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -238,7 +238,7 @@ func (dr *DeploymentReplication) handleArangoDeploymentReplicationUpdatedEvent(e // Save updated spec if err := dr.updateCRSpec(newAPIObject.Spec); err != nil { - return errors.WithStack(errors.Newf("failed to update ArangoDeploymentReplication spec: %v", err)) + return errors.WithStack(errors.Errorf("failed to update ArangoDeploymentReplication spec: %v", err)) } // Trigger inspect @@ -292,7 +292,7 @@ func (dr *DeploymentReplication) updateCRStatus() error { } if err != nil { log.Err(err).Debug("failed to patch ArangoDeploymentReplication status") - return errors.WithStack(errors.Newf("failed to patch ArangoDeploymentReplication status: %v", err)) + return errors.WithStack(errors.Errorf("failed to patch ArangoDeploymentReplication status: %v", err)) } } } @@ -329,7 +329,7 @@ func (dr *DeploymentReplication) updateCRSpec(newSpec api.DeploymentReplicationS } if err != nil { log.Err(err).Debug("failed to patch ArangoDeploymentReplication spec") - return errors.WithStack(errors.Newf("failed to patch ArangoDeploymentReplication spec: %v", err)) + return errors.WithStack(errors.Errorf("failed to patch ArangoDeploymentReplication spec: %v", err)) } } } @@ -388,7 +388,7 @@ func (dr *DeploymentReplication) reportFailedStatus() { return errors.WithStack(err) } dr.apiObject = depl - return errors.WithStack(errors.Newf("retry needed")) + return errors.WithStack(errors.Errorf("retry needed")) } retry.Retry(op, time.Hour*24*365) diff --git a/pkg/replication/finalizers.go b/pkg/replication/finalizers.go index 4dc25ae25..028075a0b 100644 --- a/pkg/replication/finalizers.go +++ b/pkg/replication/finalizers.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -140,7 +140,7 @@ func (dr *DeploymentReplication) inspectFinalizerDeplReplStopSync(ctx context.Co return errors.WithStack(err) }*/ //sourceClient.Master().C - return false, errors.WithStack(errors.Newf("TODO")) + return false, errors.WithStack(errors.Errorf("TODO")) } // Destination still exists, stop/abort sync. diff --git a/pkg/server/auth.go b/pkg/server/auth.go index 7b6d342c5..2fbe8e454 100644 --- a/pkg/server/auth.go +++ b/pkg/server/auth.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -95,7 +95,7 @@ func newServerAuthentication(secrets typedCore.SecretInterface, adminSecretName // Returns username, password, error func (s *serverAuthentication) fetchAdminSecret() (string, string, error) { if s.adminSecretName == "" { - return "", "", errors.WithStack(errors.Newf("No admin secret name specified")) + return "", "", errors.WithStack(errors.Errorf("No admin secret name specified")) } secret, err := s.secrets.Get(context.Background(), s.adminSecretName, meta.GetOptions{}) if err != nil { @@ -103,12 +103,12 @@ func (s *serverAuthentication) fetchAdminSecret() (string, string, error) { } var username, password string if raw, found := secret.Data[core.BasicAuthUsernameKey]; !found { - return "", "", errors.WithStack(errors.Newf("Secret '%s' contains no '%s' field", s.adminSecretName, core.BasicAuthUsernameKey)) + return "", "", errors.WithStack(errors.Errorf("Secret '%s' contains no '%s' field", s.adminSecretName, core.BasicAuthUsernameKey)) } else { username = string(raw) } if raw, found := secret.Data[core.BasicAuthPasswordKey]; !found { - return "", "", errors.WithStack(errors.Newf("Secret '%s' contains no '%s' field", s.adminSecretName, core.BasicAuthPasswordKey)) + return "", "", errors.WithStack(errors.Errorf("Secret '%s' contains no '%s' field", s.adminSecretName, core.BasicAuthPasswordKey)) } else { password = string(raw) } diff --git a/pkg/server/server.go b/pkg/server/server.go index 40fd1ca43..faa396897 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -113,11 +113,11 @@ func NewServer(cli typedCore.CoreV1Interface, cfg Config, deps Dependencies) (*S } certBytes, found := s.Data[core.TLSCertKey] if !found { - return nil, errors.WithStack(errors.Newf("No %s found in secret %s", core.TLSCertKey, cfg.TLSSecretName)) + return nil, errors.WithStack(errors.Errorf("No %s found in secret %s", core.TLSCertKey, cfg.TLSSecretName)) } keyBytes, found := s.Data[core.TLSPrivateKeyKey] if !found { - return nil, errors.WithStack(errors.Newf("No %s found in secret %s", core.TLSPrivateKeyKey, cfg.TLSSecretName)) + return nil, errors.WithStack(errors.Errorf("No %s found in secret %s", core.TLSPrivateKeyKey, cfg.TLSSecretName)) } cert = string(certBytes) key = string(keyBytes) diff --git a/pkg/storage/clients.go b/pkg/storage/clients.go index 5a06b8633..64031bc54 100644 --- a/pkg/storage/clients.go +++ b/pkg/storage/clients.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -114,5 +114,5 @@ func (ls *LocalStorage) GetClientByNodeName(ctx context.Context, nodeName string return c, nil } - return nil, errors.WithStack(errors.Newf("No client found for node name '%s'", nodeName)) + return nil, errors.WithStack(errors.Errorf("No client found for node name '%s'", nodeName)) } diff --git a/pkg/storage/daemon_set.go b/pkg/storage/daemon_set.go index 14360a0b0..b180eaf33 100644 --- a/pkg/storage/daemon_set.go +++ b/pkg/storage/daemon_set.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -159,7 +159,7 @@ func (ls *LocalStorage) ensureDaemonSet(apiObject *api.ArangoLocalStorage) error continue } else if err != nil { ls.log.Err(err).Debug("failed to patch DaemonSet spec") - return errors.WithStack(errors.Newf("failed to patch DaemonSet spec: %v", err)) + return errors.WithStack(errors.Errorf("failed to patch DaemonSet spec: %v", err)) } else { // Update was a success ls.log.Debug("Updated DaemonSet") diff --git a/pkg/storage/local_storage.go b/pkg/storage/local_storage.go index 3b498d9a2..eed3f9812 100644 --- a/pkg/storage/local_storage.go +++ b/pkg/storage/local_storage.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -334,7 +334,7 @@ func (ls *LocalStorage) handleArangoLocalStorageUpdatedEvent(event *localStorage // Save updated spec if err := ls.updateCRSpec(newAPIObject.Spec); err != nil { - return errors.WithStack(errors.Newf("failed to update ArangoLocalStorage spec: %v", err)) + return errors.WithStack(errors.Errorf("failed to update ArangoLocalStorage spec: %v", err)) } // Trigger inspect @@ -380,7 +380,7 @@ func (ls *LocalStorage) updateCRStatus() error { } if err != nil { ls.log.Err(err).Debug("failed to patch ArangoLocalStorage status") - return errors.WithStack(errors.Newf("failed to patch ArangoLocalStorage status: %v", err)) + return errors.WithStack(errors.Errorf("failed to patch ArangoLocalStorage status: %v", err)) } } } @@ -414,7 +414,7 @@ func (ls *LocalStorage) updateCRSpec(newSpec api.LocalStorageSpec) error { } if err != nil { ls.log.Err(err).Debug("failed to patch ArangoLocalStorage spec") - return errors.WithStack(errors.Newf("failed to patch ArangoLocalStorage spec: %v", err)) + return errors.WithStack(errors.Errorf("failed to patch ArangoLocalStorage spec: %v", err)) } } } @@ -457,7 +457,7 @@ func (ls *LocalStorage) reportFailedStatus() { return errors.WithStack(err) } ls.apiObject = depl - return errors.WithStack(errors.Newf("retry needed")) + return errors.WithStack(errors.Errorf("retry needed")) } retry.Retry(op, time.Hour*24*365) diff --git a/pkg/storage/provisioner/client/client.go b/pkg/storage/provisioner/client/client.go index e98fcb619..a5e3ead39 100644 --- a/pkg/storage/provisioner/client/client.go +++ b/pkg/storage/provisioner/client/client.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -184,7 +184,7 @@ func (c *client) do(ctx context.Context, req *http.Request, result interface{}) if err := provisioner.ParseResponseError(resp, body); err != nil { return errors.WithStack(err) } - return errors.WithStack(errors.Newf("Invalid status %d", statusCode)) + return errors.WithStack(errors.Errorf("Invalid status %d", statusCode)) } // Got a success status diff --git a/pkg/storage/provisioner/mocks/provisioner.go b/pkg/storage/provisioner/mocks/provisioner.go index dc3597955..f7185eb09 100644 --- a/pkg/storage/provisioner/mocks/provisioner.go +++ b/pkg/storage/provisioner/mocks/provisioner.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -77,7 +77,7 @@ func (m *provisionerMock) GetInfo(ctx context.Context, localPath string) (provis // Prepare a volume at the given local path func (m *provisionerMock) Prepare(ctx context.Context, localPath string) error { if _, found := m.localPaths[localPath]; found { - return errors.Newf("Path already exists: %s", localPath) + return errors.Errorf("Path already exists: %s", localPath) } m.localPaths[localPath] = struct{}{} return nil @@ -86,7 +86,7 @@ func (m *provisionerMock) Prepare(ctx context.Context, localPath string) error { // Remove a volume with the given local path func (m *provisionerMock) Remove(ctx context.Context, localPath string) error { if _, found := m.localPaths[localPath]; !found { - return errors.Newf("Path not found: %s", localPath) + return errors.Errorf("Path not found: %s", localPath) } delete(m.localPaths, localPath) return nil diff --git a/pkg/storage/pv_cleanup.go b/pkg/storage/pv_cleanup.go index b4bb8c75e..d33a3651d 100644 --- a/pkg/storage/pv_cleanup.go +++ b/pkg/storage/pv_cleanup.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -139,14 +139,14 @@ func (c *pvCleaner) clean(pv core.PersistentVolume) error { // Find local path localSource := pv.Spec.PersistentVolumeSource.Local if localSource == nil { - return errors.WithStack(errors.Newf("PersistentVolume has no local source")) + return errors.WithStack(errors.Errorf("PersistentVolume has no local source")) } localPath := localSource.Path // Find client that serves the node nodeName := pv.GetAnnotations()[nodeNameAnnotation] if nodeName == "" { - return errors.WithStack(errors.Newf("PersistentVolume has no node-name annotation")) + return errors.WithStack(errors.Errorf("PersistentVolume has no node-name annotation")) } client, err := c.clientGetter(context.Background(), nodeName) if err != nil { diff --git a/pkg/storage/pv_creator.go b/pkg/storage/pv_creator.go index fe2377ab4..de6c4a205 100644 --- a/pkg/storage/pv_creator.go +++ b/pkg/storage/pv_creator.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ func (ls *LocalStorage) createPVs(ctx context.Context, apiObject *api.ArangoLoca } if len(clients) == 0 { // No provisioners available - return false, errors.WithStack(errors.Newf("No ready provisioner endpoints found")) + return false, errors.WithStack(errors.Errorf("No ready provisioner endpoints found")) } for i, claim := range unboundClaims { @@ -267,7 +267,7 @@ func (ls *LocalStorage) createPV(ctx context.Context, apiObject *api.ArangoLocal return nil } } - return errors.WithStack(errors.Newf("No more nodes available")) + return errors.WithStack(errors.Errorf("No more nodes available")) } // createValidEndpointList convers the given endpoints list into @@ -360,7 +360,7 @@ func (ls *LocalStorage) bindClaimToVolume(claim core.PersistentVolumeClaim, volu log.Info("PersistentVolumeClaim already bound to PersistentVolume") return nil } - return errors.WithStack(errors.Newf("PersistentVolumeClaim '%s' no longer needs a volume", claim.GetName())) + return errors.WithStack(errors.Errorf("PersistentVolumeClaim '%s' no longer needs a volume", claim.GetName())) } // Try to bind @@ -376,7 +376,7 @@ func (ls *LocalStorage) bindClaimToVolume(claim core.PersistentVolumeClaim, volu return nil } log.Error("All attempts to bind PVC to volume failed") - return errors.WithStack(errors.Newf("All attempts to bind PVC to volume failed")) + return errors.WithStack(errors.Errorf("All attempts to bind PVC to volume failed")) } // shortHash creates a 6 letter hash of the given name. diff --git a/pkg/storage/pv_inspector.go b/pkg/storage/pv_inspector.go index 6127d6d5f..5d42d1a17 100644 --- a/pkg/storage/pv_inspector.go +++ b/pkg/storage/pv_inspector.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -169,14 +169,14 @@ func (ls *LocalStorage) removePVFinalizerPersistentVolumeCleanup(pv *core.Persis // Find local path localSource := pv.Spec.PersistentVolumeSource.Local if localSource == nil { - return errors.WithStack(errors.Newf("PersistentVolume has no local source")) + return errors.WithStack(errors.Errorf("PersistentVolume has no local source")) } localPath := localSource.Path // Find client that serves the node nodeName := pv.GetAnnotations()[nodeNameAnnotation] if nodeName == "" { - return errors.WithStack(errors.Newf("PersistentVolume has no node-name annotation")) + return errors.WithStack(errors.Errorf("PersistentVolume has no node-name annotation")) } client, err := ls.GetClientByNodeName(context.Background(), nodeName) if err != nil { diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index f3d1a553a..b62666da3 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,9 +24,8 @@ import ( "sort" "sync" - "github.com/pkg/errors" - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces" ) diff --git a/pkg/util/arangod/client.go b/pkg/util/arangod/client.go index 6819d757a..27b221a3b 100644 --- a/pkg/util/arangod/client.go +++ b/pkg/util/arangod/client.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -224,7 +224,7 @@ func createArangodClientAuthentication(ctx context.Context, cli typedCore.CoreV1 // Authentication is not enabled. if ctx.Value(requireAuthenticationKey{}) != nil { // Context requires authentication - return nil, errors.WithStack(errors.Newf("Authentication is required by context, but not provided in API object")) + return nil, errors.WithStack(errors.Errorf("Authentication is required by context, but not provided in API object")) } } return nil, nil diff --git a/pkg/util/arangod/dbserver.go b/pkg/util/arangod/dbserver.go index 0681576c8..cc003dc34 100644 --- a/pkg/util/arangod/dbserver.go +++ b/pkg/util/arangod/dbserver.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ func IsDBServerEmpty(ctx context.Context, id string, client driver.Client) error for _, serverID := range serverIDs { if string(serverID) == id { // DBServer still used in this shard - return errors.WithStack(errors.Newf("DBServer still used in shard %s of %s.%s", shardID, col.Parameters.Name, db.Name())) + return errors.WithStack(errors.Errorf("DBServer still used in shard %s of %s.%s", shardID, col.Parameters.Name, db.Name())) } } } diff --git a/pkg/util/crd/crd.go b/pkg/util/crd/crd.go index 13d72f51f..9033a2e8d 100644 --- a/pkg/util/crd/crd.go +++ b/pkg/util/crd/crd.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -55,11 +55,11 @@ func WaitCRDReady(clientset apiextensionsclient.Interface, crdName string) error } case apiextensionsv1.NamesAccepted: if cond.Status == apiextensionsv1.ConditionFalse { - return errors.WithStack(errors.Newf("Name conflict: %v", cond.Reason)) + return errors.WithStack(errors.Errorf("Name conflict: %v", cond.Reason)) } } } - return errors.WithStack(errors.Newf("Retry needed")) + return errors.WithStack(errors.Errorf("Retry needed")) } return WaitReady(op) } diff --git a/pkg/util/errors/errors.go b/pkg/util/errors/errors.go index 7afc44fc2..fd249da1c 100644 --- a/pkg/util/errors/errors.go +++ b/pkg/util/errors/errors.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,36 +22,29 @@ package errors import ( "context" - "fmt" "io" "net" "net/url" "os" "syscall" - errs "github.com/pkg/errors" + "github.com/pkg/errors" driver "github.com/arangodb/go-driver" "github.com/arangodb/kube-arangodb/pkg/logging" ) -var ( - Cause = errs.Cause - New = errs.New - WithStack = errs.WithStack - Wrap = errs.Wrap - Wrapf = errs.Wrapf - WithMessage = errs.WithMessage - WithMessagef = errs.WithMessagef -) +func Cause(err error) error { + return errors.Cause(err) +} // CauseWithNil returns Cause of an error. // If error returned by Cause is same (no Causer interface implemented), function will return nil instead func CauseWithNil(err error) error { if nerr := Cause(err); err == nil { return nil - } else if nerr == err { + } else if errors.Is(nerr, err) { // Cause returns same error if error object does not implement Causer interface // To prevent infinite loops in usage CauseWithNil will return nil in this case return nil @@ -60,10 +53,38 @@ func CauseWithNil(err error) error { } } -func Newf(format string, args ...interface{}) error { - return New(fmt.Sprintf(format, args...)) +func New(message string) error { + return errors.New(message) } +func Errorf(format string, args ...interface{}) error { + return errors.Errorf(format, args...) +} + +func WithStack(err error) error { + return errors.WithStack(err) +} + +func Wrap(err error, message string) error { + return errors.Wrap(err, message) +} + +func Wrapf(err error, format string, args ...interface{}) error { + return errors.Wrapf(err, format, args...) +} + +func WithMessage(err error, message string) error { + return errors.WithMessage(err, message) +} + +func WithMessagef(err error, format string, args ...interface{}) error { + return errors.WithMessagef(err, format, args...) +} + +func Is(err, target error) bool { return errors.Is(err, target) } + +func As(err error, target interface{}) bool { return errors.As(err, target) } + type timeout interface { Timeout() bool } @@ -73,7 +94,7 @@ func IsTimeout(err error) bool { if err == nil { return false } - if t, ok := errs.Cause(err).(timeout); ok { + if t, ok := errors.Cause(err).(timeout); ok { return t.Timeout() } return false @@ -88,7 +109,7 @@ func IsTemporary(err error) bool { if err == nil { return false } - if t, ok := errs.Cause(err).(temporary); ok { + if t, ok := errors.Cause(err).(temporary); ok { return t.Temporary() } return false @@ -96,7 +117,7 @@ func IsTemporary(err error) bool { // IsEOF returns true if the given error is caused by an EOF error. func IsEOF(err error) bool { - err = errs.Cause(err) + err = errors.Cause(err) if err == io.EOF { return true } @@ -108,7 +129,7 @@ func IsEOF(err error) bool { // IsConnectionRefused returns true if the given error is caused by an "connection refused" error. func IsConnectionRefused(err error) bool { - err = errs.Cause(err) + err = errors.Cause(err) if err, ok := err.(syscall.Errno); ok { return err == syscall.ECONNREFUSED } @@ -120,7 +141,7 @@ func IsConnectionRefused(err error) bool { // IsConnectionReset returns true if the given error is caused by an "connection reset by peer" error. func IsConnectionReset(err error) bool { - err = errs.Cause(err) + err = errors.Cause(err) if err, ok := err.(syscall.Errno); ok { return err == syscall.ECONNRESET } @@ -132,7 +153,7 @@ func IsConnectionReset(err error) bool { // IsContextCanceled returns true if the given error is caused by a context cancelation. func IsContextCanceled(err error) bool { - err = errs.Cause(err) + err = errors.Cause(err) if err == context.Canceled { return true } @@ -144,7 +165,7 @@ func IsContextCanceled(err error) bool { // IsContextDeadlineExpired returns true if the given error is caused by a context deadline expiration. func IsContextDeadlineExpired(err error) bool { - err = errs.Cause(err) + err = errors.Cause(err) if err == context.DeadlineExceeded { return true } @@ -157,7 +178,7 @@ func IsContextDeadlineExpired(err error) bool { // IsContextCanceledOrExpired returns true if the given error is caused by a context cancelation // or deadline expiration. func IsContextCanceledOrExpired(err error) bool { - err = errs.Cause(err) + err = errors.Cause(err) if err == context.Canceled || err == context.DeadlineExceeded { return true } diff --git a/pkg/util/errors/section.go b/pkg/util/errors/section.go index d8d403509..362f84c6c 100644 --- a/pkg/util/errors/section.go +++ b/pkg/util/errors/section.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ package errors -import "github.com/pkg/errors" - func Section(cause error, format string, args ...interface{}) error { - return errors.Wrapf(cause, format, args...) + return Wrapf(cause, format, args...) } diff --git a/pkg/util/http/server.go b/pkg/util/http/server.go index 85167c273..1842f4659 100644 --- a/pkg/util/http/server.go +++ b/pkg/util/http/server.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,11 +22,12 @@ package http import ( "crypto/tls" - "errors" "net/http" "sync" "github.com/arangodb-helper/go-certificates" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) func NewServer(server *http.Server) PlainServer { diff --git a/pkg/util/k8sutil/helpers/service_account.go b/pkg/util/k8sutil/helpers/service_account.go index 8dcbb6a5f..c67622725 100644 --- a/pkg/util/k8sutil/helpers/service_account.go +++ b/pkg/util/k8sutil/helpers/service_account.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ import ( func EnsureServiceAccount(ctx context.Context, client kubernetes.Interface, owner meta.OwnerReference, obj *sharedApi.ServiceAccount, name, namespace string, role, clusterRole []rbac.PolicyRule) (bool, error) { if obj == nil { - return false, errors.Newf("Object reference cannot be nil") + return false, errors.Errorf("Object reference cannot be nil") } // Check if secret exists diff --git a/pkg/util/k8sutil/images.go b/pkg/util/k8sutil/images.go index c9eb12159..1de38fd4b 100644 --- a/pkg/util/k8sutil/images.go +++ b/pkg/util/k8sutil/images.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -79,7 +79,7 @@ func GetImageDetails(images ...*sharedApi.Image) *sharedApi.Image { // InjectImageDetails injects image details into the Pod definition func InjectImageDetails(image *sharedApi.Image, pod *core.PodTemplateSpec, containers ...*core.Container) error { if image == nil { - return errors.Newf("Image not found") + return errors.Errorf("Image not found") } else if err := image.Validate(); err != nil { return errors.Wrapf(err, "Unable to validate image") } diff --git a/pkg/util/k8sutil/kerrors/errors_test.go b/pkg/util/k8sutil/kerrors/errors_test.go index ae5a4c81e..138e38747 100644 --- a/pkg/util/k8sutil/kerrors/errors_test.go +++ b/pkg/util/k8sutil/kerrors/errors_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ var ( existsError = apierrors.NewAlreadyExists(schema.GroupResource{Group: "groupName", Resource: "resourceName"}, "something") invalidError = apierrors.NewInvalid(schema.GroupKind{Group: "groupName", Kind: "kindName"}, "something", field.ErrorList{}) notFoundError = apierrors.NewNotFound(schema.GroupResource{Group: "groupName", Resource: "resourceName"}, "something") - forbiddenError = apierrors.NewForbidden(schema.GroupResource{Group: "groupName", Resource: "resourceName"}, "something", errors.Newf("error")) + forbiddenError = apierrors.NewForbidden(schema.GroupResource{Group: "groupName", Resource: "resourceName"}, "something", errors.Errorf("error")) ) func TestIsAlreadyExists(t *testing.T) { diff --git a/pkg/util/k8sutil/license.go b/pkg/util/k8sutil/license.go index af71c8c56..e967e2be7 100644 --- a/pkg/util/k8sutil/license.go +++ b/pkg/util/k8sutil/license.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -48,7 +48,7 @@ type LicenseSecret struct { func GetLicenseFromSecret(secret secret.Inspector, name string) (LicenseSecret, error) { s, ok := secret.Secret().V1().GetSimple(name) if !ok { - return LicenseSecret{}, errors.Newf("Secret %s not found", name) + return LicenseSecret{}, errors.Errorf("Secret %s not found", name) } var l LicenseSecret @@ -72,7 +72,7 @@ func GetLicenseFromSecret(secret secret.Inspector, name string) (LicenseSecret, l.V2 = License(v2) } } else { - return LicenseSecret{}, errors.Newf("Key (%s, %s or %s) is missing in the license secret (%s)", + return LicenseSecret{}, errors.Errorf("Key (%s, %s or %s) is missing in the license secret (%s)", constants.SecretKeyToken, constants.SecretKeyV2License, constants.SecretKeyV2Token, name) } diff --git a/pkg/util/k8sutil/secrets.go b/pkg/util/k8sutil/secrets.go index d6f5d64b4..6bb4a5c91 100644 --- a/pkg/util/k8sutil/secrets.go +++ b/pkg/util/k8sutil/secrets.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -51,10 +51,10 @@ func ValidateEncryptionKeyFromSecret(s *core.Secret) error { // Check `key` field keyData, found := s.Data[constants.SecretEncryptionKey] if !found { - return errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretEncryptionKey, s.GetName())) + return errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretEncryptionKey, s.GetName())) } if len(keyData) != 32 { - return errors.WithStack(errors.Newf("'%s' in secret '%s' is expected to be 32 bytes long, found %d", constants.SecretEncryptionKey, s.GetName(), len(keyData))) + return errors.WithStack(errors.Errorf("'%s' in secret '%s' is expected to be 32 bytes long, found %d", constants.SecretEncryptionKey, s.GetName(), len(keyData))) } return nil } @@ -62,7 +62,7 @@ func ValidateEncryptionKeyFromSecret(s *core.Secret) error { // CreateEncryptionKeySecret creates a secret used to store a RocksDB encryption key. func CreateEncryptionKeySecret(secrets secretv1.ModInterface, secretName string, key []byte) error { if len(key) != 32 { - return errors.WithStack(errors.Newf("Key in secret '%s' is expected to be 32 bytes long, got %d", secretName, len(key))) + return errors.WithStack(errors.Errorf("Key in secret '%s' is expected to be 32 bytes long, got %d", secretName, len(key))) } // Create secret secret := &core.Secret{ @@ -90,7 +90,7 @@ func ValidateCACertificateSecret(ctx context.Context, secrets secretv1.ReadInter // Check `ca.crt` field _, found := s.Data[constants.SecretCACertificate] if !found { - return errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretCACertificate, secretName)) + return errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretCACertificate, secretName)) } return nil } @@ -111,7 +111,7 @@ func GetCACertficateSecret(ctx context.Context, secrets secretv1.ReadInterface, // Load `ca.crt` field cert, found := s.Data[constants.SecretCACertificate] if !found { - return "", errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretCACertificate, secretName)) + return "", errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretCACertificate, secretName)) } return string(cert), nil } @@ -143,11 +143,11 @@ func GetCAFromSecret(s *core.Secret, ownerRef *meta.OwnerReference) (string, str // Load `ca.crt` field cert, found := s.Data[constants.SecretCACertificate] if !found { - return "", "", isOwned, errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretCACertificate, s.GetName())) + return "", "", isOwned, errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretCACertificate, s.GetName())) } priv, found := s.Data[constants.SecretCAKey] if !found { - return "", "", isOwned, errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretCAKey, s.GetName())) + return "", "", isOwned, errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretCAKey, s.GetName())) } return string(cert), string(priv), isOwned, nil } @@ -155,12 +155,12 @@ func GetCAFromSecret(s *core.Secret, ownerRef *meta.OwnerReference) (string, str func GetKeyCertFromSecret(secret *core.Secret, certName, keyName string) (crypto.Certificates, interface{}, error) { ca, exists := secret.Data[certName] if !exists { - return nil, nil, errors.Newf("Key %s missing in secret", certName) + return nil, nil, errors.Errorf("Key %s missing in secret", certName) } key, exists := secret.Data[keyName] if !exists { - return nil, nil, errors.Newf("Key %s missing in secret", keyName) + return nil, nil, errors.Errorf("Key %s missing in secret", keyName) } cert, keys, err := certificates.LoadFromPEM(string(ca), string(key)) @@ -208,7 +208,7 @@ func GetTLSKeyfileFromSecret(s *core.Secret) (string, error) { // Load `tls.keyfile` field keyfile, found := s.Data[constants.SecretTLSKeyfile] if !found { - return "", errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretTLSKeyfile, s.GetName())) + return "", errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretTLSKeyfile, s.GetName())) } return string(keyfile), nil } @@ -249,7 +249,7 @@ func ValidateTokenFromSecret(s *core.Secret) error { // Check `token` field _, found := s.Data[constants.SecretKeyToken] if !found { - return errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretKeyToken, s.GetName())) + return errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretKeyToken, s.GetName())) } return nil } @@ -268,7 +268,7 @@ func GetTokenFromSecret(s *core.Secret) (string, error) { // Take the first data from the token key data, found := s.Data[constants.SecretKeyToken] if !found { - return "", errors.WithStack(errors.Newf("No '%s' data found in secret '%s'", constants.SecretKeyToken, s.GetName())) + return "", errors.WithStack(errors.Errorf("No '%s' data found in secret '%s'", constants.SecretKeyToken, s.GetName())) } return string(data), nil } @@ -361,11 +361,11 @@ func GetBasicAuthSecret(secrets secretv1.Interface, secretName string) (string, func GetSecretAuthCredentials(secret *core.Secret) (string, string, error) { username, found := secret.Data[constants.SecretUsername] if !found { - return "", "", errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretUsername, secret.Name)) + return "", "", errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretUsername, secret.Name)) } password, found := secret.Data[constants.SecretPassword] if !found { - return "", "", errors.WithStack(errors.Newf("No '%s' found in secret '%s'", constants.SecretPassword, secret.Name)) + return "", "", errors.WithStack(errors.Errorf("No '%s' found in secret '%s'", constants.SecretPassword, secret.Name)) } return string(username), string(password), nil } diff --git a/pkg/util/k8sutil/services.go b/pkg/util/k8sutil/services.go index d38e3f8f6..2d9b84afa 100644 --- a/pkg/util/k8sutil/services.go +++ b/pkg/util/k8sutil/services.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -270,7 +270,7 @@ func CreateServiceURL(svc core.Service, scheme string, portPredicate func(core.S } } if !portFound { - return "", errors.WithStack(errors.Newf("Cannot find port in service '%s.%s'", svc.GetName(), svc.GetNamespace())) + return "", errors.WithStack(errors.Errorf("Cannot find port in service '%s.%s'", svc.GetName(), svc.GetNamespace())) } var host string @@ -297,7 +297,7 @@ func CreateServiceURL(svc core.Service, scheme string, portPredicate func(core.S return "", errors.WithStack(err) } if len(nodeList) == 0 { - return "", errors.WithStack(errors.Newf("No nodes found")) + return "", errors.WithStack(errors.Errorf("No nodes found")) } node := nodeList[util.Rand().Intn(len(nodeList))] if len(node.Status.Addresses) > 0 { @@ -308,10 +308,10 @@ func CreateServiceURL(svc core.Service, scheme string, portPredicate func(core.S host = svc.Spec.ClusterIP } default: - return "", errors.WithStack(errors.Newf("Unknown service type '%s' in service '%s.%s'", svc.Spec.Type, svc.GetName(), svc.GetNamespace())) + return "", errors.WithStack(errors.Errorf("Unknown service type '%s' in service '%s.%s'", svc.Spec.Type, svc.GetName(), svc.GetNamespace())) } if host == "" { - return "", errors.WithStack(errors.Newf("Cannot find host for service '%s.%s'", svc.GetName(), svc.GetNamespace())) + return "", errors.WithStack(errors.Errorf("Cannot find host for service '%s.%s'", svc.GetName(), svc.GetNamespace())) } if !strings.HasSuffix(scheme, "://") { scheme = scheme + "://" diff --git a/pkg/util/kclient/client_factory.go b/pkg/util/kclient/client_factory.go index 4a3a1e224..68b44ca45 100644 --- a/pkg/util/kclient/client_factory.go +++ b/pkg/util/kclient/client_factory.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,13 +24,13 @@ import ( "sync" "github.com/dchest/uniuri" - "github.com/pkg/errors" monitoring "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned" apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "github.com/arangodb/kube-arangodb/pkg/generated/clientset/versioned" + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) const ( diff --git a/pkg/util/kclient/helpers/secret.go b/pkg/util/kclient/helpers/secret.go index c82d45751..44b2407c4 100644 --- a/pkg/util/kclient/helpers/secret.go +++ b/pkg/util/kclient/helpers/secret.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,11 +21,11 @@ package helpers import ( - "github.com/pkg/errors" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "github.com/arangodb/kube-arangodb/pkg/util" + "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/secret" "github.com/arangodb/kube-arangodb/pkg/util/kclient" ) diff --git a/pkg/util/metrics/http_utils_test.go b/pkg/util/metrics/http_utils_test.go index c2dbb6689..1c3d51e51 100644 --- a/pkg/util/metrics/http_utils_test.go +++ b/pkg/util/metrics/http_utils_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ package metrics import ( - "errors" "fmt" "net" "net/http" @@ -29,6 +28,8 @@ import ( "time" "github.com/stretchr/testify/require" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" ) func StartHTTP(t *testing.T, mux *http.ServeMux) (string, func()) { diff --git a/pkg/util/shutdown/grpc.go b/pkg/util/shutdown/grpc.go index 9123b4fec..04394f37c 100644 --- a/pkg/util/shutdown/grpc.go +++ b/pkg/util/shutdown/grpc.go @@ -24,21 +24,23 @@ import ( "context" "time" + "google.golang.org/grpc" + "github.com/arangodb/kube-arangodb/pkg/api/server" pbShutdown "github.com/arangodb/kube-arangodb/pkg/api/shutdown/v1" + "github.com/arangodb/kube-arangodb/pkg/util/svc" ) -func NewShutdownableShutdownServer() ShutdownableShutdownServer { - return &impl{closer: stop} +func NewGlobalShutdownServer() svc.Handler { + return NewShutdownServer(stop) } -type ShutdownableShutdownServer interface { - pbShutdown.ShutdownServer - - Shutdown(cancelFunc context.CancelFunc) +func NewShutdownServer(closer context.CancelFunc) svc.Handler { + return &impl{closer: closer} } -var _ ShutdownableShutdownServer = &impl{} +var _ pbShutdown.ShutdownServer = &impl{} +var _ svc.Handler = &impl{} type impl struct { pbShutdown.UnimplementedShutdownServer @@ -46,6 +48,18 @@ type impl struct { closer context.CancelFunc } +func (i *impl) Name() string { + return "shutdown" +} + +func (i *impl) Health() svc.HealthState { + return svc.Healthy +} + +func (i *impl) Register(registrar *grpc.Server) { + pbShutdown.RegisterShutdownServer(registrar, i) +} + func (i *impl) ShutdownServer(ctx context.Context, empty *server.Empty) (*server.Empty, error) { go func() { defer i.closer() @@ -55,7 +69,3 @@ func (i *impl) ShutdownServer(ctx context.Context, empty *server.Empty) (*server return &server.Empty{}, nil } - -func (i *impl) Shutdown(cancelFunc context.CancelFunc) { - cancelFunc() -} diff --git a/pkg/util/shutdown/grpc_test.go b/pkg/util/shutdown/grpc_test.go new file mode 100644 index 000000000..349c63393 --- /dev/null +++ b/pkg/util/shutdown/grpc_test.go @@ -0,0 +1,67 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package shutdown + +import ( + "context" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/arangodb/kube-arangodb/pkg/api/server" + pbShutdown "github.com/arangodb/kube-arangodb/pkg/api/shutdown/v1" + "github.com/arangodb/kube-arangodb/pkg/util/svc" + "github.com/arangodb/kube-arangodb/pkg/util/tests/tgrpc" +) + +func Test_ShutdownGRPC(t *testing.T) { + ctx, c := context.WithCancel(context.Background()) + defer c() + + local := svc.NewService(svc.Configuration{ + Address: "127.0.0.1:0", + }, NewShutdownServer(c)) + + start := local.Start(ctx) + + require.False(t, isContextDone(ctx)) + + client := tgrpc.NewGRPCClient(t, ctx, pbShutdown.NewShutdownClient, start.Address()) + + _, err := client.ShutdownServer(ctx, &server.Empty{}) + require.NoError(t, err) + + time.Sleep(time.Second) + + require.True(t, isContextDone(ctx)) + + require.NoError(t, start.Wait()) +} + +func isContextDone(ctx context.Context) bool { + select { + case <-ctx.Done(): + return true + default: + return false + } +} diff --git a/pkg/util/svc/configuration.go b/pkg/util/svc/configuration.go new file mode 100644 index 000000000..e5f7008b7 --- /dev/null +++ b/pkg/util/svc/configuration.go @@ -0,0 +1,29 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package svc + +import "google.golang.org/grpc" + +type Configuration struct { + Address string + + Options []grpc.ServerOption +} diff --git a/pkg/util/svc/error.go b/pkg/util/svc/error.go new file mode 100644 index 000000000..a7c9ed475 --- /dev/null +++ b/pkg/util/svc/error.go @@ -0,0 +1,47 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package svc + +import "context" + +type serviceError struct { + error +} + +func (p serviceError) StartWithHealth(ctx context.Context, health Health) ServiceStarter { + return p +} + +func (p serviceError) Address() string { + return "" +} + +func (p serviceError) Wait() error { + return p +} + +func (p serviceError) Update(key string, state HealthState) { + +} + +func (p serviceError) Start(ctx context.Context) ServiceStarter { + return p +} diff --git a/pkg/util/svc/grpc.go b/pkg/util/svc/grpc.go deleted file mode 100644 index ae5141784..000000000 --- a/pkg/util/svc/grpc.go +++ /dev/null @@ -1,80 +0,0 @@ -// -// DISCLAIMER -// -// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// Copyright holder is ArangoDB GmbH, Cologne, Germany -// - -package svc - -import ( - "context" - "net" - - "google.golang.org/grpc" -) - -type GRPCConfig struct { - ListenAddress string -} - -type RegisterServerFunc func(server *grpc.Server) - -func NewGRPC(config GRPCConfig, registerFuncs ...RegisterServerFunc) Service { - server := grpc.NewServer( /* currently no auth parameters required */ ) - - for _, fn := range registerFuncs { - fn(server) - } - - return &service{ - cfg: config, - grpcServer: server, - } -} - -type service struct { - grpcServer *grpc.Server - cfg GRPCConfig -} - -func (s *service) Run(ctx context.Context) error { - ln, err := net.Listen("tcp", s.cfg.ListenAddress) - if err != nil { - return err - } - defer ln.Close() - - errChan := make(chan error) - go func() { - if serveErr := s.grpcServer.Serve(ln); serveErr != nil && serveErr != grpc.ErrServerStopped { - errChan <- serveErr - } - }() - - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - select { - case <-ctx.Done(): - s.grpcServer.GracefulStop() - case err = <-errChan: - s.grpcServer.Stop() - close(errChan) - } - - return err -} diff --git a/pkg/util/svc/handler.go b/pkg/util/svc/handler.go new file mode 100644 index 000000000..796a0ebe2 --- /dev/null +++ b/pkg/util/svc/handler.go @@ -0,0 +1,31 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package svc + +import "google.golang.org/grpc" + +type Handler interface { + Name() string + + Health() HealthState + + Register(registrar *grpc.Server) +} diff --git a/pkg/util/svc/health.go b/pkg/util/svc/health.go new file mode 100644 index 000000000..e135b9b54 --- /dev/null +++ b/pkg/util/svc/health.go @@ -0,0 +1,118 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package svc + +import ( + "google.golang.org/grpc" + imHealth "google.golang.org/grpc/health" + pbHealth "google.golang.org/grpc/health/grpc_health_v1" +) + +type HealthState int + +const ( + Unhealthy HealthState = iota + Degraded + Healthy +) + +type HealthType int + +const ( + Readiness HealthType = iota + Liveness + Startup +) + +type Health interface { + Update(key string, state HealthState) +} + +type HealthService interface { + Service + + Health +} + +type emptyHealth struct { +} + +func (e emptyHealth) Update(key string, state HealthState) { + +} + +type health struct { + *service + + t HealthType + *imHealth.Server +} + +func (h *health) Update(key string, state HealthState) { + healthState := pbHealth.HealthCheckResponse_UNKNOWN + + switch h.t { + case Liveness: + switch state { + case Healthy, Degraded: + healthState = pbHealth.HealthCheckResponse_SERVING + case Unhealthy: + healthState = pbHealth.HealthCheckResponse_NOT_SERVING + } + case Startup, Readiness: + switch state { + case Healthy: + healthState = pbHealth.HealthCheckResponse_SERVING + case Degraded, Unhealthy: + healthState = pbHealth.HealthCheckResponse_NOT_SERVING + } + } + + h.SetServingStatus(key, healthState) + h.SetServingStatus("", pbHealth.HealthCheckResponse_SERVING) +} + +func (h *health) Name() string { + return "health" +} + +func (h *health) Health() HealthState { + return Healthy +} + +func (h *health) Register(registrar *grpc.Server) { + pbHealth.RegisterHealthServer(registrar, h) +} + +func NewHealthService(cfg Configuration, t HealthType, handlers ...Handler) HealthService { + health := &health{ + Server: imHealth.NewServer(), + t: t, + } + + var h []Handler + h = append(h, health) + h = append(h, handlers...) + + health.service = newService(cfg, h...) + + return health +} diff --git a/pkg/util/svc/run.go b/pkg/util/svc/run.go new file mode 100644 index 000000000..1ad3991b7 --- /dev/null +++ b/pkg/util/svc/run.go @@ -0,0 +1,33 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package svc + +import "context" + +func Run(ctx context.Context, health HealthService, services ...Service) error { + healthState := health.Start(ctx) + + for _, svc := range services { + svc.StartWithHealth(ctx, health) + } + + return healthState.Wait() +} diff --git a/pkg/util/svc/service.go b/pkg/util/svc/service.go index cfbff08b3..0db469d23 100644 --- a/pkg/util/svc/service.go +++ b/pkg/util/svc/service.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany +// Copyright 2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,40 +22,46 @@ package svc import ( "context" - "sync" - shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" - "github.com/arangodb/kube-arangodb/pkg/util/probe" + "google.golang.org/grpc" ) type Service interface { - Run(ctx context.Context) error + Start(ctx context.Context) ServiceStarter + + StartWithHealth(ctx context.Context, health Health) ServiceStarter } -func RunServices(ctx context.Context, healthService probe.HealthService, services ...Service) error { - if len(services) == 0 { - <-ctx.Done() - return nil - } +type service struct { + server *grpc.Server - errors := make([]error, len(services)) + cfg Configuration - var wg sync.WaitGroup - - for id := range services { - wg.Add(1) - - go func(id int) { - defer wg.Done() - - errors[id] = services[id].Run(ctx) - - healthService.Shutdown() - }(id) - } - - healthService.SetServing() - wg.Wait() - - return shared.WithErrors(errors...) + handlers []Handler +} + +func (p *service) StartWithHealth(ctx context.Context, health Health) ServiceStarter { + return newServiceStarter(ctx, p, health) +} + +func (p *service) Start(ctx context.Context) ServiceStarter { + return newServiceStarter(ctx, p, emptyHealth{}) +} + +func NewService(cfg Configuration, handlers ...Handler) Service { + return newService(cfg, handlers...) +} + +func newService(cfg Configuration, handlers ...Handler) *service { + var q service + + q.cfg = cfg + q.server = grpc.NewServer(cfg.Options...) + q.handlers = handlers + + for _, handler := range q.handlers { + handler.Register(q.server) + } + + return &q } diff --git a/pkg/util/svc/service_test.go b/pkg/util/svc/service_test.go new file mode 100644 index 000000000..dea43dbe0 --- /dev/null +++ b/pkg/util/svc/service_test.go @@ -0,0 +1,72 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package svc + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + pbHealth "google.golang.org/grpc/health/grpc_health_v1" +) + +func Test_Service(t *testing.T) { + h := NewHealthService(Configuration{ + Address: "127.0.0.1:0", + }, Readiness) + + other := NewService(Configuration{ + Address: "127.0.0.1:0", + }) + + ctx, c := context.WithCancel(context.Background()) + defer c() + + st := h.Start(ctx) + + othStart := other.StartWithHealth(ctx, h) + + healthConn, err := grpc.DialContext(ctx, st.Address(), grpc.WithTransportCredentials(insecure.NewCredentials())) + require.NoError(t, err) + + defer healthConn.Close() + + otherConn, err := grpc.DialContext(ctx, othStart.Address(), grpc.WithTransportCredentials(insecure.NewCredentials())) + require.NoError(t, err) + + defer otherConn.Close() + + cl := pbHealth.NewHealthClient(healthConn) + + _, err = cl.Check(context.Background(), &pbHealth.HealthCheckRequest{}) + require.NoError(t, err) + + ol := pbHealth.NewHealthClient(otherConn) + + _, err = ol.Check(context.Background(), &pbHealth.HealthCheckRequest{}) + require.Error(t, err) + + c() + + require.NoError(t, st.Wait()) +} diff --git a/pkg/util/svc/starter.go b/pkg/util/svc/starter.go new file mode 100644 index 000000000..41906dc07 --- /dev/null +++ b/pkg/util/svc/starter.go @@ -0,0 +1,127 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package svc + +import ( + "context" + "fmt" + "net" + "time" + + "google.golang.org/grpc" + + "github.com/arangodb/kube-arangodb/pkg/util/errors" +) + +type ServiceStarter interface { + Wait() error + + Address() string +} + +type serviceStarter struct { + service *service + + address string + + error error + done chan struct{} +} + +func (s *serviceStarter) Address() string { + return s.address +} + +func (s *serviceStarter) Wait() error { + <-s.done + + return s.error +} + +func (s *serviceStarter) run(ctx context.Context, health Health, ln net.Listener) { + defer close(s.done) + + s.error = s.runE(ctx, health, ln) +} + +func (s *serviceStarter) runE(ctx context.Context, health Health, ln net.Listener) error { + pr := ln.Addr().(*net.TCPAddr) + s.address = fmt.Sprintf("%s:%d", pr.IP.String(), pr.Port) + + var serveError error + + done := make(chan struct{}) + go func() { + defer close(done) + + if err := s.service.server.Serve(ln); err != nil && !errors.Is(err, grpc.ErrServerStopped) { + serveError = err + } + }() + + go func() { + <-ctx.Done() + + s.service.server.GracefulStop() + }() + + ticker := time.NewTicker(125 * time.Millisecond) + defer ticker.Stop() + + for { + select { + case <-done: + return serveError + default: + for _, h := range s.service.handlers { + health.Update(h.Name(), h.Health()) + } + break + } + + select { + case <-done: + return serveError + case <-ticker.C: + continue + } + } +} + +func newServiceStarter(ctx context.Context, service *service, health Health) ServiceStarter { + st := &serviceStarter{ + service: service, + error: nil, + done: make(chan struct{}), + } + + ln, err := net.Listen("tcp", service.cfg.Address) + if err != nil { + return serviceError{err} + } + + pr := ln.Addr().(*net.TCPAddr) + st.address = fmt.Sprintf("%s:%d", pr.IP.String(), pr.Port) + + go st.run(ctx, health, ln) + + return st +} diff --git a/pkg/util/tests/kubernetes.go b/pkg/util/tests/kubernetes.go index 95cfee903..7e0dc23e4 100644 --- a/pkg/util/tests/kubernetes.go +++ b/pkg/util/tests/kubernetes.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ func HandleWithMax(handler operator.Handler, item operation.Item, max int) error return nil } - return errors.Newf("Max retries reached") + return errors.Errorf("Max retries reached") } type KubernetesObject interface { diff --git a/pkg/util/tests/tgrpc/grpc.go b/pkg/util/tests/tgrpc/grpc.go new file mode 100644 index 000000000..7ba422855 --- /dev/null +++ b/pkg/util/tests/tgrpc/grpc.go @@ -0,0 +1,53 @@ +// +// DISCLAIMER +// +// Copyright 2024 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package tgrpc + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +func NewGRPCClient[T any](t *testing.T, ctx context.Context, in func(cc grpc.ClientConnInterface) T, addr string, opts ...grpc.DialOption) T { + return in(NewGRPCConn(t, ctx, addr, opts...)) +} + +func NewGRPCConn(t *testing.T, ctx context.Context, addr string, opts ...grpc.DialOption) *grpc.ClientConn { + var z []grpc.DialOption + + z = append(z, grpc.WithTransportCredentials(insecure.NewCredentials())) + + z = append(z, opts...) + + conn, err := grpc.DialContext(ctx, addr, z...) + require.NoError(t, err) + + go func() { + <-ctx.Done() + + require.NoError(t, conn.Close()) + }() + + return conn +} diff --git a/tools/license/license.go b/tools/license/license.go index e9f26cfb7..10f62f961 100644 --- a/tools/license/license.go +++ b/tools/license/license.go @@ -112,7 +112,7 @@ func mainE() error { } if !valid { - return errors.Newf("Parse of file failed") + return errors.Errorf("Parse of file failed") } return nil @@ -211,5 +211,5 @@ func extractFileLicenseData(file string) (int, int, error) { return from, to, nil } - return 0, 0, errors.Newf("Unable to find license string") + return 0, 0, errors.Errorf("Unable to find license string") }