Skip to content

Commit e868003

Browse files
authored
remove github.com/pkg/errors (#1031)
* remove github.com/pkg/errors Signed-off-by: fahed dorgaa <[email protected]> * fixes Signed-off-by: fahed dorgaa <[email protected]>
1 parent bc0ba12 commit e868003

File tree

18 files changed

+96
-106
lines changed

18 files changed

+96
-106
lines changed

cmd/versionhook/main.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package main
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"io"
78
"os"
89
"strings"
910
"time"
1011

11-
"github.com/pkg/errors"
12-
1312
"github.com/mongodb/mongodb-kubernetes-operator/pkg/agent"
1413
"go.uber.org/zap"
1514
corev1 "k8s.io/api/core/v1"
@@ -108,7 +107,7 @@ func waitForAgentHealthStatus() (agent.Health, error) {
108107

109108
status, ok := health.Healthiness[getHostname()]
110109
if !ok {
111-
return agent.Health{}, errors.Errorf("couldn't find status for hostname %s", getHostname())
110+
return agent.Health{}, fmt.Errorf("couldn't find status for hostname %s", getHostname())
112111
}
113112

114113
// We determine if the file has been updated by checking if the process is not in goal state.
@@ -117,7 +116,7 @@ func waitForAgentHealthStatus() (agent.Health, error) {
117116
return health, nil
118117
}
119118
}
120-
return agent.Health{}, errors.Errorf("agent health status not ready after waiting %s", pollingDuration.String())
119+
return agent.Health{}, fmt.Errorf("agent health status not ready after waiting %s", pollingDuration.String())
121120

122121
}
123122

@@ -132,7 +131,7 @@ func getAgentHealthStatus() (agent.Health, error) {
132131

133132
h, err := readAgentHealthStatus(f)
134133
if err != nil {
135-
return agent.Health{}, errors.Errorf("could not read health status file: %s", err)
134+
return agent.Health{}, fmt.Errorf("could not read health status file: %s", err)
136135
}
137136
return h, err
138137
}
@@ -159,7 +158,7 @@ func getHostname() string {
159158
func shouldDeletePod(health agent.Health) (bool, error) {
160159
status, ok := health.ProcessPlans[getHostname()]
161160
if !ok {
162-
return false, errors.Errorf("hostname %s was not in the process plans", getHostname())
161+
return false, fmt.Errorf("hostname %s was not in the process plans", getHostname())
163162
}
164163
return isWaitingToBeDeleted(status), nil
165164
}
@@ -186,15 +185,15 @@ func isWaitingToBeDeleted(healthStatus agent.MmsDirectorStatus) bool {
186185
func deletePod() error {
187186
thisPod, err := getThisPod()
188187
if err != nil {
189-
return errors.Errorf("could not get pod: %s", err)
188+
return fmt.Errorf("could not get pod: %s", err)
190189
}
191190
k8sClient, err := inClusterClient()
192191
if err != nil {
193-
return errors.Errorf("could not get client: %s", err)
192+
return fmt.Errorf("could not get client: %s", err)
194193
}
195194

196195
if err := k8sClient.Delete(context.TODO(), &thisPod); err != nil {
197-
return errors.Errorf("could not delete pod: %s", err)
196+
return fmt.Errorf("could not delete pod: %s", err)
198197
}
199198
return nil
200199
}
@@ -203,12 +202,12 @@ func deletePod() error {
203202
func getThisPod() (corev1.Pod, error) {
204203
podName := getHostname()
205204
if podName == "" {
206-
return corev1.Pod{}, errors.Errorf("environment variable HOSTNAME was not present")
205+
return corev1.Pod{}, fmt.Errorf("environment variable HOSTNAME was not present")
207206
}
208207

209208
ns, err := getNamespace()
210209
if err != nil {
211-
return corev1.Pod{}, errors.Errorf("could not read namespace: %s", err)
210+
return corev1.Pod{}, fmt.Errorf("could not read namespace: %s", err)
212211
}
213212

214213
return corev1.Pod{
@@ -222,12 +221,12 @@ func getThisPod() (corev1.Pod, error) {
222221
func inClusterClient() (client.Client, error) {
223222
config, err := rest.InClusterConfig()
224223
if err != nil {
225-
return nil, errors.Errorf("could not get cluster config: %s", err)
224+
return nil, fmt.Errorf("could not get cluster config: %s", err)
226225
}
227226

228227
k8sClient, err := client.New(config, client.Options{})
229228
if err != nil {
230-
return nil, errors.Errorf("could not create client: %s", err)
229+
return nil, fmt.Errorf("could not create client: %s", err)
231230
}
232231
return k8sClient, nil
233232
}

controllers/mongodb_tls.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/mongodb/mongodb-kubernetes-operator/controllers/construct"
99
"github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig"
10-
"github.com/pkg/errors"
1110

1211
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/secret"
1312

@@ -172,7 +171,7 @@ func getCaCrt(cmGetter configmap.Getter, secretGetter secret.Getter, mdb mdbv1.M
172171
}
173172

174173
if cert, ok := caData[tlsCACertName]; !ok || cert == "" {
175-
return "", errors.Errorf(`CA certificate resource "%s" should have a CA certificate in field "%s"`, caResourceName, tlsCACertName)
174+
return "", fmt.Errorf(`CA certificate resource "%s" should have a CA certificate in field "%s"`, caResourceName, tlsCACertName)
176175
} else {
177176
return cert, nil
178177
}

controllers/prometheus.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
mdbv1 "github.com/mongodb/mongodb-kubernetes-operator/api/v1"
99
"github.com/mongodb/mongodb-kubernetes-operator/pkg/automationconfig"
1010
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/secret"
11-
"github.com/pkg/errors"
1211

1312
"k8s.io/apimachinery/pkg/types"
1413
)
@@ -28,7 +27,7 @@ func getPrometheusModification(getUpdateCreator secret.GetUpdateCreator, mdb mdb
2827
secretNamespacedName := types.NamespacedName{Name: mdb.Spec.Prometheus.PasswordSecretRef.Name, Namespace: mdb.Namespace}
2928
password, err := secret.ReadKey(getUpdateCreator, mdb.Spec.Prometheus.GetPasswordKey(), secretNamespacedName)
3029
if err != nil {
31-
return automationconfig.NOOP(), errors.Errorf("could not configure Prometheus modification: %s", err)
30+
return automationconfig.NOOP(), fmt.Errorf("could not configure Prometheus modification: %s", err)
3231
}
3332

3433
var certKey string

controllers/replica_set_controller.go

+16-18
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import (
2828

2929
"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/status"
3030

31-
"github.com/pkg/errors"
32-
3331
"github.com/mongodb/mongodb-kubernetes-operator/controllers/construct"
3432
"github.com/mongodb/mongodb-kubernetes-operator/controllers/validation"
3533
"github.com/mongodb/mongodb-kubernetes-operator/controllers/watch"
@@ -296,11 +294,11 @@ func (r *ReplicaSetReconciler) ensureTLSResources(mdb mdbv1.MongoDBCommunity) er
296294
if mdb.Spec.Security.TLS.Enabled {
297295
r.log.Infof("TLS is enabled, creating/updating CA secret")
298296
if err := ensureCASecret(r.client, r.client, r.client, mdb); err != nil {
299-
return errors.Errorf("could not ensure CA secret: %s", err)
297+
return fmt.Errorf("could not ensure CA secret: %s", err)
300298
}
301299
r.log.Infof("TLS is enabled, creating/updating TLS secret")
302300
if err := ensureTLSSecret(r.client, mdb); err != nil {
303-
return errors.Errorf("could not ensure TLS secret: %s", err)
301+
return fmt.Errorf("could not ensure TLS secret: %s", err)
304302
}
305303
}
306304
return nil
@@ -317,7 +315,7 @@ func (r *ReplicaSetReconciler) ensurePrometheusTLSResources(mdb mdbv1.MongoDBCom
317315
// require the contents.
318316
r.log.Infof("Prometheus TLS is enabled, creating/updating TLS secret")
319317
if err := ensurePrometheusTLSSecret(r.client, mdb); err != nil {
320-
return errors.Errorf("could not ensure TLS secret: %s", err)
318+
return fmt.Errorf("could not ensure TLS secret: %s", err)
321319
}
322320

323321
return nil
@@ -332,17 +330,17 @@ func (r *ReplicaSetReconciler) ensurePrometheusTLSResources(mdb mdbv1.MongoDBCom
332330
func (r *ReplicaSetReconciler) deployStatefulSet(mdb mdbv1.MongoDBCommunity) (bool, error) {
333331
r.log.Info("Creating/Updating StatefulSet")
334332
if err := r.createOrUpdateStatefulSet(mdb, false); err != nil {
335-
return false, errors.Errorf("error creating/updating StatefulSet: %s", err)
333+
return false, fmt.Errorf("error creating/updating StatefulSet: %s", err)
336334
}
337335

338336
r.log.Info("Creating/Updating StatefulSet for Arbiters")
339337
if err := r.createOrUpdateStatefulSet(mdb, true); err != nil {
340-
return false, errors.Errorf("error creating/updating StatefulSet: %s", err)
338+
return false, fmt.Errorf("error creating/updating StatefulSet: %s", err)
341339
}
342340

343341
currentSts, err := r.client.GetStatefulSet(mdb.NamespacedName())
344342
if err != nil {
345-
return false, errors.Errorf("error getting StatefulSet: %s", err)
343+
return false, fmt.Errorf("error getting StatefulSet: %s", err)
346344
}
347345

348346
r.log.Debugf("Ensuring StatefulSet is ready, with type: %s", mdb.GetUpdateStrategyType())
@@ -474,7 +472,7 @@ func (r *ReplicaSetReconciler) ensureService(mdb mdbv1.MongoDBCommunity) error {
474472
func (r *ReplicaSetReconciler) createProcessPortManager(mdb mdbv1.MongoDBCommunity) (*agent.ReplicaSetPortManager, error) {
475473
currentAC, err := automationconfig.ReadFromSecret(r.client, types.NamespacedName{Name: mdb.AutomationConfigSecretName(), Namespace: mdb.Namespace})
476474
if err != nil {
477-
return nil, errors.Errorf("could not read existing automation config: %s", err)
475+
return nil, fmt.Errorf("could not read existing automation config: %s", err)
478476
}
479477

480478
currentPodStates, err := agent.GetAllDesiredMembersAndArbitersPodState(mdb.NamespacedName(), r.client, mdb.StatefulSetReplicasThisReconciliation(), mdb.StatefulSetArbitersThisReconciliation(), currentAC.Version, r.log)
@@ -496,7 +494,7 @@ func (r *ReplicaSetReconciler) createOrUpdateStatefulSet(mdb mdbv1.MongoDBCommun
496494
err := r.client.Get(context.TODO(), name, &set)
497495
err = k8sClient.IgnoreNotFound(err)
498496
if err != nil {
499-
return errors.Errorf("error getting StatefulSet: %s", err)
497+
return fmt.Errorf("error getting StatefulSet: %s", err)
500498
}
501499

502500
buildStatefulSetModificationFunction(mdb)(&set)
@@ -505,7 +503,7 @@ func (r *ReplicaSetReconciler) createOrUpdateStatefulSet(mdb mdbv1.MongoDBCommun
505503
}
506504

507505
if _, err = statefulset.CreateOrUpdate(r.client, set); err != nil {
508-
return errors.Errorf("error creating/updating StatefulSet: %s", err)
506+
return fmt.Errorf("error creating/updating StatefulSet: %s", err)
509507
}
510508
return nil
511509
}
@@ -515,7 +513,7 @@ func (r *ReplicaSetReconciler) createOrUpdateStatefulSet(mdb mdbv1.MongoDBCommun
515513
func (r ReplicaSetReconciler) ensureAutomationConfig(mdb mdbv1.MongoDBCommunity) (automationconfig.AutomationConfig, error) {
516514
ac, err := r.buildAutomationConfig(mdb)
517515
if err != nil {
518-
return automationconfig.AutomationConfig{}, errors.Errorf("could not build automation config: %s", err)
516+
return automationconfig.AutomationConfig{}, fmt.Errorf("could not build automation config: %s", err)
519517
}
520518

521519
return automationconfig.EnsureSecret(
@@ -618,22 +616,22 @@ func getCustomRolesModification(mdb mdbv1.MongoDBCommunity) (automationconfig.Mo
618616
func (r ReplicaSetReconciler) buildAutomationConfig(mdb mdbv1.MongoDBCommunity) (automationconfig.AutomationConfig, error) {
619617
tlsModification, err := getTLSConfigModification(r.client, r.client, mdb)
620618
if err != nil {
621-
return automationconfig.AutomationConfig{}, errors.Errorf("could not configure TLS modification: %s", err)
619+
return automationconfig.AutomationConfig{}, fmt.Errorf("could not configure TLS modification: %s", err)
622620
}
623621

624622
customRolesModification, err := getCustomRolesModification(mdb)
625623
if err != nil {
626-
return automationconfig.AutomationConfig{}, errors.Errorf("could not configure custom roles: %s", err)
624+
return automationconfig.AutomationConfig{}, fmt.Errorf("could not configure custom roles: %s", err)
627625
}
628626

629627
currentAC, err := automationconfig.ReadFromSecret(r.client, types.NamespacedName{Name: mdb.AutomationConfigSecretName(), Namespace: mdb.Namespace})
630628
if err != nil {
631-
return automationconfig.AutomationConfig{}, errors.Errorf("could not read existing automation config: %s", err)
629+
return automationconfig.AutomationConfig{}, fmt.Errorf("could not read existing automation config: %s", err)
632630
}
633631

634632
auth := automationconfig.Auth{}
635633
if err := scram.Enable(&auth, r.client, mdb); err != nil {
636-
return automationconfig.AutomationConfig{}, errors.Errorf("could not configure scram authentication: %s", err)
634+
return automationconfig.AutomationConfig{}, fmt.Errorf("could not configure scram authentication: %s", err)
637635
}
638636

639637
prometheusModification := automationconfig.NOOP()
@@ -643,7 +641,7 @@ func (r ReplicaSetReconciler) buildAutomationConfig(mdb mdbv1.MongoDBCommunity)
643641

644642
prometheusModification, err = getPrometheusModification(r.client, mdb)
645643
if err != nil {
646-
return automationconfig.AutomationConfig{}, errors.Errorf("could not enable TLS on Prometheus endpoint: %s", err)
644+
return automationconfig.AutomationConfig{}, fmt.Errorf("could not enable TLS on Prometheus endpoint: %s", err)
647645
}
648646
}
649647

@@ -663,7 +661,7 @@ func (r ReplicaSetReconciler) buildAutomationConfig(mdb mdbv1.MongoDBCommunity)
663661
)
664662

665663
if err != nil {
666-
return automationconfig.AutomationConfig{}, errors.Errorf("could not create an automation config: %s", err)
664+
return automationconfig.AutomationConfig{}, fmt.Errorf("could not create an automation config: %s", err)
667665
}
668666

669667
if mdb.Spec.AutomationConfigOverride != nil {

controllers/replicaset_controller_test.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
"k8s.io/apimachinery/pkg/runtime"
2020
"sigs.k8s.io/yaml"
2121

22-
"github.com/pkg/errors"
23-
2422
"github.com/stretchr/objx"
2523

2624
k8sClient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -176,7 +174,7 @@ func getVolumeByName(sts appsv1.StatefulSet, volumeName string) (corev1.Volume,
176174
return v, nil
177175
}
178176
}
179-
return corev1.Volume{}, errors.Errorf("volume with name %s, not found", volumeName)
177+
return corev1.Volume{}, fmt.Errorf("volume with name %s, not found", volumeName)
180178
}
181179

182180
func TestChangingVersion_ResultsInRollingUpdateStrategyType(t *testing.T) {
@@ -1151,11 +1149,11 @@ func loadTestFixture(yamlFileName string) (mdbv1.MongoDBCommunity, error) {
11511149
mdb := mdbv1.MongoDBCommunity{}
11521150
data, err := os.ReadFile(testPath)
11531151
if err != nil {
1154-
return mdb, errors.Errorf("error reading file: %s", err)
1152+
return mdb, fmt.Errorf("error reading file: %s", err)
11551153
}
11561154

11571155
if err := marshalRuntimeObjectFromYAMLBytes(data, &mdb); err != nil {
1158-
return mdb, errors.Errorf("error converting yaml bytes to service account: %s", err)
1156+
return mdb, fmt.Errorf("error converting yaml bytes to service account: %s", err)
11591157
}
11601158

11611159
return mdb, nil

controllers/validation/validation.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package validation
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67

78
mdbv1 "github.com/mongodb/mongodb-kubernetes-operator/api/v1"
89
"github.com/mongodb/mongodb-kubernetes-operator/pkg/authentication/scram"
9-
"github.com/pkg/errors"
1010
)
1111

1212
// ValidateInitalSpec checks if the resource's initial Spec is valid.
@@ -77,12 +77,12 @@ func validateUsers(mdb mdbv1.MongoDBCommunity) error {
7777

7878
}
7979
if len(nameCollisions) > 0 {
80-
return errors.Errorf("connection string secret names collision, update at least one of the users so that the resulted secret names (<resource name>-<user>-<db>) are unique: %s",
80+
return fmt.Errorf("connection string secret names collision, update at least one of the users so that the resulted secret names (<resource name>-<user>-<db>) are unique: %s",
8181
strings.Join(nameCollisions, ", "))
8282
}
8383

8484
if len(scramSecretNameCollisions) > 0 {
85-
return errors.Errorf("scram credential secret names collision, update at least one of the users: %s",
85+
return fmt.Errorf("scram credential secret names collision, update at least one of the users: %s",
8686
strings.Join(scramSecretNameCollisions, ", "))
8787
}
8888

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/go-logr/logr v1.2.3
88
github.com/hashicorp/go-multierror v1.1.1
99
github.com/imdario/mergo v0.3.13
10-
github.com/pkg/errors v0.9.1
1110
github.com/spf13/cast v1.5.0
1211
github.com/stretchr/objx v0.4.0
1312
github.com/stretchr/testify v1.7.1
@@ -45,6 +44,7 @@ require (
4544
github.com/moby/spdystream v0.2.0 // indirect
4645
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4746
github.com/modern-go/reflect2 v1.0.2 // indirect
47+
github.com/pkg/errors v0.9.1 // indirect
4848
github.com/pmezard/go-difflib v1.0.0 // indirect
4949
github.com/prometheus/client_golang v1.11.0 // indirect
5050
github.com/prometheus/client_model v0.2.0 // indirect

0 commit comments

Comments
 (0)