diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 4e3c7f69a0..c1f5362d43 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -27,8 +27,8 @@ import ( "strings" "sync" + "github.com/kanisterio/errkit" osversioned "github.com/openshift/client-go/apps/clientset/versioned" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "gopkg.in/tomb.v2" corev1 "k8s.io/api/core/v1" @@ -86,23 +86,23 @@ func New(c *rest.Config, reg prometheus.Registerer) *Controller { func (c *Controller) StartWatch(ctx context.Context, namespace string) error { crClient, err := versioned.NewForConfig(c.config) if err != nil { - return errors.Wrap(err, "failed to get a CustomResource client") + return errkit.Wrap(err, "failed to get a CustomResource client") } if err := checkCRAccess(ctx, crClient, namespace); err != nil { return err } clientset, err := kubernetes.NewForConfig(c.config) if err != nil { - return errors.Wrap(err, "failed to get a k8s client") + return errkit.Wrap(err, "failed to get a k8s client") } dynClient, err := dynamic.NewForConfig(c.config) if err != nil { - return errors.Wrap(err, "failed to get a k8s dynamic client") + return errkit.Wrap(err, "failed to get a k8s dynamic client") } osClient, err := osversioned.NewForConfig(c.config) if err != nil { - return errors.Wrap(err, "failed to get a openshift client") + return errkit.Wrap(err, "failed to get a openshift client") } c.crClient = crClient @@ -134,13 +134,13 @@ func (c *Controller) StartWatch(ctx context.Context, namespace string) error { func checkCRAccess(ctx context.Context, cli versioned.Interface, ns string) error { if _, err := cli.CrV1alpha1().ActionSets(ns).List(ctx, metav1.ListOptions{}); err != nil { - return errors.Wrap(err, "Could not list ActionSets") + return errkit.Wrap(err, "Could not list ActionSets") } if _, err := cli.CrV1alpha1().Blueprints(ns).List(ctx, metav1.ListOptions{}); err != nil { - return errors.Wrap(err, "Could not list Blueprints") + return errkit.Wrap(err, "Could not list Blueprints") } if _, err := cli.CrV1alpha1().Profiles(ns).List(ctx, metav1.ListOptions{}); err != nil { - return errors.Wrap(err, "Could not list Profiles") + return errkit.Wrap(err, "Could not list Profiles") } return nil } @@ -220,7 +220,7 @@ func (c *Controller) onAddActionSet(ctx context.Context, t *tomb.Tomb, as *crv1a } as, err := c.crClient.CrV1alpha1().ActionSets(as.GetNamespace()).Get(ctx, as.GetName(), metav1.GetOptions{}) if err != nil { - return errors.WithStack(err) + return errkit.WithStack(err) } if err = validate.ActionSet(as); err != nil { return err @@ -313,13 +313,13 @@ func (c *Controller) initActionSetStatus(ctx context.Context, as *crv1alpha1.Act for _, a := range as.Spec.Actions { if a.Blueprint == "" { // TODO: If no blueprint is specified, we should consider a default. - err = errors.New("Blueprint is not specified for action") + err = errkit.New("Blueprint is not specified for action") c.logAndErrorEvent(ctx, "Could not get blueprint:", "Blueprint not specified", err, as) break } var bp *crv1alpha1.Blueprint if bp, err = c.crClient.CrV1alpha1().Blueprints(as.GetNamespace()).Get(ctx, a.Blueprint, metav1.GetOptions{}); err != nil { - err = errors.Wrap(err, "Failed to query blueprint") + err = errkit.Wrap(err, "Failed to query blueprint") c.logAndErrorEvent(ctx, "Could not get blueprint:", "Error", err, as) break } @@ -349,7 +349,7 @@ func (c *Controller) initActionSetStatus(ctx context.Context, as *crv1alpha1.Act func (c *Controller) initialActionStatus(a crv1alpha1.ActionSpec, bp *crv1alpha1.Blueprint) (*crv1alpha1.ActionStatus, error) { bpa, ok := bp.Actions[a.Name] if !ok { - return nil, errors.Errorf("Action %s for object kind %s not found in blueprint %s", a.Name, a.Object.Kind, a.Blueprint) + return nil, errkit.New(fmt.Sprintf("Action %s for object kind %s not found in blueprint %s", a.Name, a.Object.Kind, a.Blueprint)) } phases := make([]crv1alpha1.Phase, 0, len(bpa.Phases)) for _, p := range bpa.Phases { @@ -379,14 +379,14 @@ func (c *Controller) initialActionStatus(a crv1alpha1.ActionSpec, bp *crv1alpha1 func (c *Controller) handleActionSet(ctx context.Context, t *tomb.Tomb, as *crv1alpha1.ActionSet) (err error) { if as.Status == nil { - return errors.New("ActionSet was not initialized") + return errkit.New("ActionSet was not initialized") } if as.Status.State != crv1alpha1.StatePending { return nil } as.Status.State = crv1alpha1.StateRunning if as, err = c.crClient.CrV1alpha1().ActionSets(as.GetNamespace()).Update(ctx, as, metav1.UpdateOptions{}); err != nil { - return errors.WithStack(err) + return errkit.WithStack(err) } ctx = field.Context(ctx, consts.ActionsetNameKey, as.GetName()) // adding labels with prefix "kanister.io/" in the context as field for better logging @@ -399,7 +399,7 @@ func (c *Controller) handleActionSet(ctx context.Context, t *tomb.Tomb, as *crv1 for i, a := range as.Status.Actions { var bp *crv1alpha1.Blueprint if bp, err = c.crClient.CrV1alpha1().Blueprints(as.GetNamespace()).Get(ctx, a.Blueprint, metav1.GetOptions{}); err != nil { - err = errors.Wrap(err, "Failed to query blueprint") + err = errkit.Wrap(err, "Failed to query blueprint") c.logAndErrorEvent(ctx, "Could not get blueprint:", "Error", err, as) break } @@ -419,7 +419,7 @@ func (c *Controller) handleActionSet(ctx context.Context, t *tomb.Tomb, as *crv1 Message: err.Error(), } _, err = c.crClient.CrV1alpha1().ActionSets(as.GetNamespace()).Update(ctx, as, metav1.UpdateOptions{}) - return errors.WithStack(err) + return errkit.WithStack(err) } log.WithContext(ctx).Print("Created actionset and started executing actions", field.M{"NewActionSetName": as.GetName()}) return nil diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index 6f5b8604a0..f5b4210025 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -21,7 +21,7 @@ import ( "testing" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "github.com/prometheus/client_golang/prometheus" promgomodel "github.com/prometheus/client_model/go" "gopkg.in/check.v1" @@ -171,12 +171,12 @@ func (s *ControllerSuite) waitOnActionSetState(as *crv1alpha1.ActionSet, state c if as.Status.State == crv1alpha1.StatePending || as.Status.State == crv1alpha1.StateRunning { return false, nil } - return false, errors.New(fmt.Sprintf("Unexpected state: %s", as.Status.State)) + return false, errkit.New(fmt.Sprintf("Unexpected state: %s", as.Status.State)) }) if err == nil { return nil } - return errors.Wrapf(err, "State '%s' never reached", state) + return errkit.Wrap(err, fmt.Sprintf("State '%s' never reached", state)) } func (s *ControllerSuite) waitOnDeferPhaseState(as *crv1alpha1.ActionSet, state crv1alpha1.State) error { @@ -201,7 +201,7 @@ func (s *ControllerSuite) waitOnDeferPhaseState(as *crv1alpha1.ActionSet, state if err == nil { return nil } - return errors.Wrapf(err, "State '%s' never reached", state) + return errkit.Wrap(err, fmt.Sprintf("State '%s' never reached", state)) } func (s *ControllerSuite) waitOnActionSetCompleteWithRunningPhases(as *crv1alpha1.ActionSet, rp *sets.Set[string]) error { @@ -229,12 +229,12 @@ func (s *ControllerSuite) waitOnActionSetCompleteWithRunningPhases(as *crv1alpha } return false, nil } - return false, errors.New(fmt.Sprintf("Unexpected state: %s", as.Status.State)) + return false, errkit.New(fmt.Sprintf("Unexpected state: %s", as.Status.State)) }) if err == nil { return nil } - return errors.Wrapf(err, "ActionSet did not reach '%s' state", crv1alpha1.StateComplete) + return errkit.Wrap(err, fmt.Sprintf("ActionSet did not reach '%s' state", crv1alpha1.StateComplete)) } func newBPWithOutputArtifact() *crv1alpha1.Blueprint { @@ -731,7 +731,7 @@ func (s *ControllerSuite) TestRuntimeObjEventLogs(c *check.C) { config, err := kube.LoadConfig() c.Assert(err, check.IsNil) ctlr := New(config, nil) - ctlr.logAndErrorEvent(ctx, msg, reason, errors.New("Testing Event Logs"), as, nilAs, bp) + ctlr.logAndErrorEvent(ctx, msg, reason, errkit.New("Testing Event Logs"), as, nilAs, bp) // Test ActionSet error event logging events, err := s.cli.CoreV1().Events(as.Namespace).Search(scheme.Scheme, as) @@ -754,7 +754,7 @@ func (s *ControllerSuite) TestRuntimeObjEventLogs(c *check.C) { // Testing empty Blueprint testbp := &crv1alpha1.Blueprint{} - ctlr.logAndErrorEvent(ctx, msg, reason, errors.New("Testing Event Logs"), testbp) + ctlr.logAndErrorEvent(ctx, msg, reason, errkit.New("Testing Event Logs"), testbp) events, err = s.cli.CoreV1().Events(bp.Namespace).Search(scheme.Scheme, testbp) c.Assert(err, check.NotNil) c.Assert(len(events.Items), check.Equals, 0) diff --git a/pkg/controllers/repositoryserver/handler.go b/pkg/controllers/repositoryserver/handler.go index 29677628de..d7325f0c27 100644 --- a/pkg/controllers/repositoryserver/handler.go +++ b/pkg/controllers/repositoryserver/handler.go @@ -22,7 +22,7 @@ import ( "github.com/go-logr/logr" "github.com/jpillora/backoff" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" apimeta "k8s.io/apimachinery/pkg/api/meta" @@ -50,20 +50,20 @@ type RepoServerHandler struct { func (h *RepoServerHandler) CreateOrUpdateOwnedResources(ctx context.Context) error { if err := h.getSecretsFromCR(ctx); err != nil { - return errors.Wrap(err, "Failed to get Kopia API server secrets") + return errkit.Wrap(err, "Failed to get Kopia API server secrets") } svc, err := h.reconcileService(ctx) if err != nil { - return errors.Wrap(err, "Failed to reconcile service") + return errkit.Wrap(err, "Failed to reconcile service") } envVars, pod, err := h.reconcilePod(ctx, svc) if err != nil { - return errors.Wrap(err, "Failed to reconcile Kopia API server pod") + return errkit.Wrap(err, "Failed to reconcile Kopia API server pod") } if err := h.waitForPodReady(ctx, pod); err != nil { - return errors.Wrap(err, "Kopia API server pod not in ready state") + return errkit.Wrap(err, "Kopia API server pod not in ready state") } // envVars are set only when credentials are of type AWS/Azure. @@ -95,7 +95,7 @@ func (h *RepoServerHandler) reconcileService(ctx context.Context) (*corev1.Servi return nil, err } if err := h.updateServerInfoInCRStatus(ctx, h.RepositoryServer.Status.ServerInfo.PodName, svc.Name); err != nil { - return nil, errors.Wrap(err, "Failed to update service name in RepositoryServer /status") + return nil, errkit.Wrap(err, "Failed to update service name in RepositoryServer /status") } return svc, err } @@ -131,7 +131,7 @@ func (h *RepoServerHandler) createService(ctx context.Context, repoServerNamespa } err := h.Reconciler.Create(ctx, &svc) if err != nil { - return nil, errors.Wrap(err, "Failed to create RepositoryServer service") + return nil, errkit.Wrap(err, "Failed to create RepositoryServer service") } err = poll.WaitWithBackoff(ctx, backoff.Backoff{ @@ -184,7 +184,7 @@ func (h *RepoServerHandler) createPodAndUpdateStatus(ctx context.Context, repoSe return nil, nil, err } if err := h.updateServerInfoInCRStatus(ctx, pod.Name, h.RepositoryServer.Status.ServerInfo.ServiceName); err != nil { - return nil, nil, errors.Wrap(err, "Failed to update pod name in RepositoryServer /status") + return nil, nil, errkit.Wrap(err, "Failed to update pod name in RepositoryServer /status") } return envVars, pod, nil } @@ -236,7 +236,7 @@ func (h *RepoServerHandler) createPod(ctx context.Context, repoServerNamespace s return nil, nil, err } if err := h.Reconciler.Create(ctx, pod); err != nil { - return nil, nil, errors.Wrap(err, "Failed to create RepositoryServer pod") + return nil, nil, errkit.Wrap(err, "Failed to create RepositoryServer pod") } return pod, envVars, err } @@ -284,7 +284,7 @@ func (h *RepoServerHandler) preparePodOverride(ctx context.Context, po *kube.Pod h.RepositoryServerSecrets.serverTLS.Name, po, ); err != nil { - return nil, errors.Wrap(err, "Failed to attach TLS Certificate configuration") + return nil, errkit.Wrap(err, "Failed to attach TLS Certificate configuration") } return podOverride, nil } @@ -315,7 +315,7 @@ func (h *RepoServerHandler) updateServerInfoInCRStatus(ctx context.Context, podN func (h *RepoServerHandler) waitForPodReady(ctx context.Context, pod *corev1.Pod) error { if err := kube.WaitForPodReady(ctx, h.KubeCli, pod.Namespace, pod.Name); err != nil { - return errors.Wrap(err, fmt.Sprintf("Failed while waiting for pod %s to be ready", pod.Name)) + return errkit.Wrap(err, fmt.Sprintf("Failed while waiting for pod %s to be ready", pod.Name)) } return nil } diff --git a/pkg/controllers/repositoryserver/repositoryserver_controller.go b/pkg/controllers/repositoryserver/repositoryserver_controller.go index 8616921b95..7e52febac0 100644 --- a/pkg/controllers/repositoryserver/repositoryserver_controller.go +++ b/pkg/controllers/repositoryserver/repositoryserver_controller.go @@ -18,7 +18,7 @@ import ( "context" "github.com/go-logr/logr" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -69,11 +69,11 @@ func (r *RepositoryServerReconciler) Reconcile(ctx context.Context, req ctrl.Req logger = logger.V(1) cnf, err := ctrl.GetConfig() if err != nil { - return ctrl.Result{}, errors.Wrap(err, "Failed to get k8s config") + return ctrl.Result{}, errkit.Wrap(err, "Failed to get k8s config") } kubeCli, err := kubernetes.NewForConfig(cnf) if err != nil { - return ctrl.Result{}, errors.Wrap(err, "Failed to get a k8s client") + return ctrl.Result{}, errkit.Wrap(err, "Failed to get a k8s client") } repositoryServer := &crv1alpha1.RepositoryServer{} diff --git a/pkg/controllers/repositoryserver/repositoryserver_controller_test.go b/pkg/controllers/repositoryserver/repositoryserver_controller_test.go index 90b6e9f5fa..b84557e468 100644 --- a/pkg/controllers/repositoryserver/repositoryserver_controller_test.go +++ b/pkg/controllers/repositoryserver/repositoryserver_controller_test.go @@ -23,7 +23,7 @@ import ( "testing" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "gopkg.in/check.v1" corev1 "k8s.io/api/core/v1" k8sresource "k8s.io/apimachinery/pkg/api/resource" @@ -477,11 +477,11 @@ func (s *RepoServerControllerSuite) waitForRepoServerInfoUpdateInCR(repoServerNa }) if !serverInfoUpdated && err == nil { - err = errors.New("pod name or service name is not set on repository server CR") + err = errkit.New("pod name or service name is not set on repository server CR") } if err != nil { - return errors.Wrapf(err, "failed waiting for RepoServer Info updates in the CR") + return errkit.Wrap(err, "failed waiting for RepoServer Info updates in the CR") } return err } @@ -502,12 +502,12 @@ func (s *RepoServerControllerSuite) waitOnRepositoryServerState(reposerverName s return false, nil } if repoServerCR.Status.Progress == crv1alpha1.Failed { - return false, errors.New(fmt.Sprintf(" There is failure in staring the repository server, server is in %s state, please check logs", repoServerCR.Status.Progress)) + return false, errkit.New(fmt.Sprintf("There is failure in staring the repository server, server is in %s state, please check logs", repoServerCR.Status.Progress)) } if repoServerCR.Status.Progress == crv1alpha1.Ready { return true, nil } - return false, errors.New(fmt.Sprintf("Unexpected Repository server state: %s", repoServerCR.Status.Progress)) + return false, errkit.New(fmt.Sprintf("Unexpected Repository server state: %s", repoServerCR.Status.Progress)) }) return repoServerState, err } diff --git a/pkg/controllers/repositoryserver/secrets_manager.go b/pkg/controllers/repositoryserver/secrets_manager.go index 9272eeafb3..fb66923ea2 100644 --- a/pkg/controllers/repositoryserver/secrets_manager.go +++ b/pkg/controllers/repositoryserver/secrets_manager.go @@ -18,7 +18,7 @@ import ( "context" "fmt" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" ) @@ -76,14 +76,14 @@ func (h *RepoServerHandler) getSecretsFromCR(ctx context.Context) error { func (h *RepoServerHandler) fetchSecret(ctx context.Context, ref *corev1.SecretReference) (*corev1.Secret, error) { if ref == nil { - return nil, errors.New("repository server CR does not have a secret reference set") + return nil, errkit.New("repository server CR does not have a secret reference set") } h.Logger.Info(fmt.Sprintf("Fetching secret %s from namespace %s", ref.Name, ref.Namespace)) secret := corev1.Secret{} err := h.Reconciler.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: ref.Namespace}, &secret) if err != nil { - return nil, errors.Wrap(err, fmt.Sprintf("Error fetching secret %s from namespace %s", ref.Name, ref.Namespace)) + return nil, errkit.Wrap(err, fmt.Sprintf("Error fetching secret %s from namespace %s", ref.Name, ref.Namespace)) } return &secret, nil } diff --git a/pkg/controllers/repositoryserver/server.go b/pkg/controllers/repositoryserver/server.go index 16ce3d4a08..9d03c0ea33 100644 --- a/pkg/controllers/repositoryserver/server.go +++ b/pkg/controllers/repositoryserver/server.go @@ -21,7 +21,7 @@ import ( "os" "time" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" "k8s.io/kube-openapi/pkg/util/sets" "github.com/kanisterio/kanister/pkg/format" @@ -69,12 +69,12 @@ func (h *RepoServerHandler) startRepoProxyServer(ctx context.Context) (err error format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout) format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr) if err != nil { - return errors.Wrap(err, "Failed to start Kopia API server") + return errkit.Wrap(err, "Failed to start Kopia API server") } err = h.waitForServerReady(ctx, repoServerAddress, serverAdminUserName, serverAdminPassword) if err != nil { - return errors.Wrap(err, "Failed to check Kopia API server status") + return errkit.Wrap(err, "Failed to check Kopia API server status") } return nil } @@ -87,10 +87,10 @@ func (h *RepoServerHandler) getServerDetails(ctx context.Context) (string, strin var serverAdminUsername, serverAdminPassword []byte var ok bool if serverAdminUsername, ok = h.RepositoryServerSecrets.serverAdmin.Data[reposerver.AdminUsernameKey]; !ok { - return "", "", "", errors.New("Server admin username is not specified") + return "", "", "", errkit.New("Server admin username is not specified") } if serverAdminPassword, ok = h.RepositoryServerSecrets.serverAdmin.Data[reposerver.AdminPasswordKey]; !ok { - return "", "", "", errors.New("Server admin password is not specified") + return "", "", "", errkit.New("Server admin password is not specified") } return repoServerAddress, string(serverAdminUsername), string(serverAdminPassword), nil } @@ -98,7 +98,7 @@ func (h *RepoServerHandler) getServerDetails(ctx context.Context) (string, strin func (h *RepoServerHandler) checkServerStatus(ctx context.Context, serverAddress, username, password string) error { cmd, err := h.getServerStatusCommand(ctx, serverAddress, username, password) if err != nil { - return errors.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") + return errkit.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") } stdout, stderr, exErr := kube.Exec(ctx, h.KubeCli, h.RepositoryServer.Namespace, h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, cmd, nil) format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout) @@ -109,7 +109,7 @@ func (h *RepoServerHandler) checkServerStatus(ctx context.Context, serverAddress func (h *RepoServerHandler) waitForServerReady(ctx context.Context, serverAddress, username, password string) error { cmd, err := h.getServerStatusCommand(ctx, serverAddress, username, password) if err != nil { - return errors.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") + return errkit.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") } serverStartTimeOut := h.getRepositoryServerStartTimeout() ctx, cancel := context.WithTimeout(ctx, serverStartTimeOut) @@ -132,14 +132,14 @@ func (h *RepoServerHandler) createOrUpdateClientUsers(ctx context.Context) error format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout) format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr) if err != nil { - return errors.Wrap(err, "Failed to list users from the Kopia repository") + return errkit.Wrap(err, "Failed to list users from the Kopia repository") } userProfiles := []maintenance.KopiaUserProfile{} err = json.Unmarshal([]byte(stdout), &userProfiles) if err != nil { - return errors.Wrap(err, "Failed to unmarshal user list") + return errkit.Wrap(err, "Failed to unmarshal user list") } // Get list of usernames from ServerListUserCommand output to update the existing data with updated password @@ -169,7 +169,7 @@ func (h *RepoServerHandler) createOrUpdateClientUsers(ctx context.Context) error format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout) format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr) if err != nil { - return errors.Wrap(err, "Failed to update existing user passphrase from the Kopia API server") + return errkit.Wrap(err, "Failed to update existing user passphrase from the Kopia API server") } continue } @@ -187,7 +187,7 @@ func (h *RepoServerHandler) createOrUpdateClientUsers(ctx context.Context) error format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout) format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr) if err != nil { - return errors.Wrap(err, "Failed to add new user to the Kopia API server") + return errkit.Wrap(err, "Failed to add new user to the Kopia API server") } } return nil @@ -201,7 +201,7 @@ func (h *RepoServerHandler) refreshServer(ctx context.Context) error { repoPassword := string(h.RepositoryServerSecrets.repositoryPassword.Data[reposerver.RepoPasswordKey]) fingerprint, err := kopia.ExtractFingerprintFromCertSecret(ctx, h.KubeCli, h.RepositoryServerSecrets.serverTLS.Name, h.RepositoryServer.Namespace) if err != nil { - return errors.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") + return errkit.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") } cmd := command.ServerRefresh( @@ -220,7 +220,7 @@ func (h *RepoServerHandler) refreshServer(ctx context.Context) error { format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stdout) format.Log(h.RepositoryServer.Status.ServerInfo.PodName, repoServerPodContainerName, stderr) if err != nil { - return errors.Wrap(err, "Failed to refresh Kopia API server") + return errkit.Wrap(err, "Failed to refresh Kopia API server") } return nil } @@ -241,7 +241,7 @@ func (h *RepoServerHandler) getRepositoryServerStartTimeout() time.Duration { func (h *RepoServerHandler) getServerStatusCommand(ctx context.Context, serverAddress, username, password string) ([]string, error) { fingerprint, err := kopia.ExtractFingerprintFromCertSecret(ctx, h.KubeCli, h.RepositoryServerSecrets.serverTLS.Name, h.RepositoryServer.Namespace) if err != nil { - return nil, errors.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") + return nil, errkit.Wrap(err, "Failed to extract fingerprint from Kopia API server certificate secret data") } cmd := command.ServerStatus( command.ServerStatusCommandArgs{ diff --git a/pkg/controllers/repositoryserver/utils.go b/pkg/controllers/repositoryserver/utils.go index 928dc984bb..0fdcd5af69 100644 --- a/pkg/controllers/repositoryserver/utils.go +++ b/pkg/controllers/repositoryserver/utils.go @@ -22,7 +22,7 @@ import ( "time" "github.com/jpillora/backoff" - "github.com/pkg/errors" + "github.com/kanisterio/errkit" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -164,12 +164,12 @@ func volumeSpecForName(podSpec corev1.PodSpec, podOverride map[string]interface{ func addTLSCertConfigurationInPodOverride(podOverride *map[string]interface{}, tlsCertSecretName string, po *kube.PodOptions) error { podSpecBytes, err := json.Marshal(*podOverride) if err != nil { - return errors.Wrap(err, "Failed to marshal Pod Override") + return errkit.Wrap(err, "Failed to marshal Pod Override") } var podOverrideSpec corev1.PodSpec if err := json.Unmarshal(podSpecBytes, &podOverrideSpec); err != nil { - return errors.Wrap(err, "Failed to unmarshal Pod Override Spec") + return errkit.Wrap(err, "Failed to unmarshal Pod Override Spec") } podOverrideSpec.Volumes = append(podOverrideSpec.Volumes, corev1.Volume{ @@ -199,11 +199,11 @@ func addTLSCertConfigurationInPodOverride(podOverride *map[string]interface{}, t podSpecBytes, err = json.Marshal(podOverrideSpec) if err != nil { - return errors.Wrap(err, "Failed to marshal Pod Override Spec") + return errkit.Wrap(err, "Failed to marshal Pod Override Spec") } if err := json.Unmarshal(podSpecBytes, podOverride); err != nil { - return errors.Wrap(err, "Failed to unmarshal Pod Override") + return errkit.Wrap(err, "Failed to unmarshal Pod Override") } return nil @@ -235,7 +235,7 @@ func getPodOptions(namespace string, svc *corev1.Service, vols map[string]kube.V func getPodAddress(ctx context.Context, cli kubernetes.Interface, namespace, podName string) (string, error) { p, err := cli.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{}) if err != nil { - return "", errors.Wrap(err, "Failed to get pod") + return "", errkit.Wrap(err, "Failed to get pod") } return fmt.Sprintf(repoServerAddressFormat, p.Status.PodIP, repoServerServicePort), nil } @@ -277,17 +277,17 @@ func getVolumes( vols := make(map[string]kube.VolumeMountOptions, 0) var claimName []byte if len(secret.Data) == 0 { - return nil, errors.Errorf(secerrors.EmptySecretErrorMessage, secret.Namespace, secret.Name) + return nil, errkit.New(fmt.Sprintf(secerrors.EmptySecretErrorMessage, secret.Namespace, secret.Name)) } if locationType, ok := (secret.Data[reposerver.TypeKey]); ok && reposerver.LocType(string(locationType)) == reposerver.LocTypeFilestore { if claimName, ok = secret.Data[reposerver.ClaimNameKey]; !ok { - return nil, errors.New("Claim name not set for file store location secret, failed to retrieve PVC") + return nil, errkit.New("Claim name not set for file store location secret, failed to retrieve PVC") } claimNameString := string(claimName) pvc, err := cli.CoreV1().PersistentVolumeClaims(namespace).Get(ctx, claimNameString, metav1.GetOptions{}) if err != nil { - return nil, errors.Wrapf(err, "Failed to validate if PVC %s:%s exists", namespace, claimName) + return nil, errkit.Wrap(err, "Failed to validate if PVC exists", "namespace", namespace, "claimName", claimName) } vols[claimNameString] = kube.VolumeMountOptions{