Skip to content

Commit 4e3682b

Browse files
committed
Adjustments to appease golangci linter
1 parent ea058b1 commit 4e3682b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+242
-259
lines changed

internal/bridge/client.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (c *Client) doWithBackoff(
280280
request.Header = headers.Clone()
281281

282282
//nolint:bodyclose // This response is returned to the caller.
283-
response, err = c.Client.Do(request)
283+
response, err = c.Do(request)
284284
}
285285

286286
// An error indicates there was no response from the server, and the
@@ -327,7 +327,7 @@ func (c *Client) doWithRetry(
327327
// Retry the request when the server responds with "Too many requests".
328328
// - https://docs.crunchybridge.com/api-concepts/getting-started/#status-codes
329329
// - https://docs.crunchybridge.com/api-concepts/getting-started/#rate-limiting
330-
for err == nil && response.StatusCode == 429 {
330+
for err == nil && response.StatusCode == http.StatusTooManyRequests {
331331
seconds, _ := strconv.Atoi(response.Header.Get("Retry-After"))
332332

333333
// Only retry when the response indicates how long to wait.
@@ -378,11 +378,11 @@ func (c *Client) CreateAuthObject(ctx context.Context, authn AuthObject) (AuthOb
378378
}
379379

380380
// 401, Unauthorized
381-
case response.StatusCode == 401:
381+
case response.StatusCode == http.StatusUnauthorized:
382382
err = fmt.Errorf("%w: %s", errAuthentication, body)
383383

384384
default:
385-
//nolint:goerr113 // This is intentionally dynamic.
385+
//nolint:err113 // This is intentionally dynamic.
386386
err = fmt.Errorf("%v: %s", response.Status, body)
387387
}
388388
}
@@ -409,7 +409,7 @@ func (c *Client) CreateInstallation(ctx context.Context) (Installation, error) {
409409
}
410410

411411
default:
412-
//nolint:goerr113 // This is intentionally dynamic.
412+
//nolint:err113 // This is intentionally dynamic.
413413
err = fmt.Errorf("%v: %s", response.Status, body)
414414
}
415415
}
@@ -445,7 +445,7 @@ func (c *Client) ListClusters(ctx context.Context, apiKey, teamId string) ([]*Cl
445445
}
446446

447447
default:
448-
//nolint:goerr113 // This is intentionally dynamic.
448+
//nolint:err113 // This is intentionally dynamic.
449449
err = fmt.Errorf("%v: %s", response.Status, body)
450450
}
451451
}
@@ -486,7 +486,7 @@ func (c *Client) CreateCluster(
486486
}
487487

488488
default:
489-
//nolint:goerr113 // This is intentionally dynamic.
489+
//nolint:err113 // This is intentionally dynamic.
490490
err = fmt.Errorf("%v: %s", response.Status, body)
491491
}
492492
}
@@ -524,14 +524,14 @@ func (c *Client) DeleteCluster(ctx context.Context, apiKey, id string) (*Cluster
524524
// --https://docs.crunchybridge.com/api-concepts/idempotency#delete-semantics
525525
// But also, if we can't find it...
526526
// Maybe if no ID we return already deleted?
527-
case response.StatusCode == 410:
527+
case response.StatusCode == http.StatusGone:
528528
fallthrough
529-
case response.StatusCode == 404:
529+
case response.StatusCode == http.StatusNotFound:
530530
deletedAlready = true
531531
err = nil
532532

533533
default:
534-
//nolint:goerr113 // This is intentionally dynamic.
534+
//nolint:err113 // This is intentionally dynamic.
535535
err = fmt.Errorf("%v: %s", response.Status, body)
536536
}
537537
}
@@ -565,7 +565,7 @@ func (c *Client) GetCluster(ctx context.Context, apiKey, id string) (*ClusterApi
565565
}
566566

567567
default:
568-
//nolint:goerr113 // This is intentionally dynamic.
568+
//nolint:err113 // This is intentionally dynamic.
569569
err = fmt.Errorf("%v: %s", response.Status, body)
570570
}
571571
}
@@ -599,7 +599,7 @@ func (c *Client) GetClusterStatus(ctx context.Context, apiKey, id string) (*Clus
599599
}
600600

601601
default:
602-
//nolint:goerr113 // This is intentionally dynamic.
602+
//nolint:err113 // This is intentionally dynamic.
603603
err = fmt.Errorf("%v: %s", response.Status, body)
604604
}
605605
}
@@ -633,7 +633,7 @@ func (c *Client) GetClusterUpgrade(ctx context.Context, apiKey, id string) (*Clu
633633
}
634634

635635
default:
636-
//nolint:goerr113 // This is intentionally dynamic.
636+
//nolint:err113 // This is intentionally dynamic.
637637
err = fmt.Errorf("%v: %s", response.Status, body)
638638
}
639639
}
@@ -674,7 +674,7 @@ func (c *Client) UpgradeCluster(
674674
}
675675

676676
default:
677-
//nolint:goerr113 // This is intentionally dynamic.
677+
//nolint:err113 // This is intentionally dynamic.
678678
err = fmt.Errorf("%v: %s", response.Status, body)
679679
}
680680
}
@@ -709,7 +709,7 @@ func (c *Client) UpgradeClusterHA(ctx context.Context, apiKey, id, action string
709709
}
710710

711711
default:
712-
//nolint:goerr113 // This is intentionally dynamic.
712+
//nolint:err113 // This is intentionally dynamic.
713713
err = fmt.Errorf("%v: %s", response.Status, body)
714714
}
715715
}
@@ -747,7 +747,7 @@ func (c *Client) UpdateCluster(
747747
}
748748

749749
default:
750-
//nolint:goerr113 // This is intentionally dynamic.
750+
//nolint:err113 // This is intentionally dynamic.
751751
err = fmt.Errorf("%v: %s", response.Status, body)
752752
}
753753
}
@@ -777,7 +777,7 @@ func (c *Client) GetClusterRole(ctx context.Context, apiKey, clusterId, roleName
777777
}
778778

779779
default:
780-
//nolint:goerr113 // This is intentionally dynamic.
780+
//nolint:err113 // This is intentionally dynamic.
781781
err = fmt.Errorf("%v: %s", response.Status, body)
782782
}
783783
}
@@ -807,7 +807,7 @@ func (c *Client) ListClusterRoles(ctx context.Context, apiKey, id string) ([]*Cl
807807
}
808808

809809
default:
810-
//nolint:goerr113 // This is intentionally dynamic.
810+
//nolint:err113 // This is intentionally dynamic.
811811
err = fmt.Errorf("%v: %s", response.Status, body)
812812
}
813813
}

internal/bridge/client_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func TestClientBackoff(t *testing.T) {
3131
client := NewClient("", "")
3232
var total time.Duration
3333

34-
for i := 1; i <= 50 && client.Backoff.Steps > 0; i++ {
35-
step := client.Backoff.Step()
34+
for i := 1; i <= 50 && client.Steps > 0; i++ {
35+
step := client.Step()
3636
total += step
3737

3838
t.Logf("%02d:%20v%20v", i, step, total)
@@ -68,7 +68,7 @@ func TestClientDoWithBackoff(t *testing.T) {
6868

6969
// Client with one attempt, i.e. no backoff.
7070
client := NewClient(server.URL, "xyz")
71-
client.Backoff.Steps = 1
71+
client.Steps = 1
7272
assert.Equal(t, client.BaseURL.String(), server.URL)
7373

7474
ctx := context.Background()
@@ -113,8 +113,8 @@ func TestClientDoWithBackoff(t *testing.T) {
113113

114114
// Client with brief backoff.
115115
client := NewClient(server.URL, "")
116-
client.Backoff.Duration = time.Millisecond
117-
client.Backoff.Steps = 5
116+
client.Duration = time.Millisecond
117+
client.Steps = 5
118118
assert.Equal(t, client.BaseURL.String(), server.URL)
119119

120120
ctx := context.Background()
@@ -170,8 +170,8 @@ func TestClientDoWithBackoff(t *testing.T) {
170170

171171
// Client with brief backoff.
172172
client := NewClient(server.URL, "")
173-
client.Backoff.Duration = time.Millisecond
174-
client.Backoff.Steps = 5
173+
client.Duration = time.Millisecond
174+
client.Steps = 5
175175
assert.Equal(t, client.BaseURL.String(), server.URL)
176176

177177
ctx := context.Background()
@@ -190,8 +190,8 @@ func TestClientDoWithBackoff(t *testing.T) {
190190

191191
// Client with lots of brief backoff.
192192
client := NewClient(server.URL, "")
193-
client.Backoff.Duration = time.Millisecond
194-
client.Backoff.Steps = 100
193+
client.Duration = time.Millisecond
194+
client.Steps = 100
195195
assert.Equal(t, client.BaseURL.String(), server.URL)
196196

197197
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)

internal/bridge/crunchybridgecluster/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (r *CrunchyBridgeClusterReconciler) patch(
2222
patch client.Patch, options ...client.PatchOption,
2323
) error {
2424
options = append([]client.PatchOption{r.Owner}, options...)
25-
return r.Client.Patch(ctx, object, patch, options...)
25+
return r.Patch(ctx, object, patch, options...)
2626
}
2727

2828
// apply sends an apply patch to object's endpoint in the Kubernetes API and

internal/bridge/crunchybridgecluster/crunchybridgecluster_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (r *CrunchyBridgeClusterReconciler) SetupWithManager(
9191
func (r *CrunchyBridgeClusterReconciler) setControllerReference(
9292
owner *v1beta1.CrunchyBridgeCluster, controlled client.Object,
9393
) error {
94-
return controllerutil.SetControllerReference(owner, controlled, r.Client.Scheme())
94+
return controllerutil.SetControllerReference(owner, controlled, r.Scheme())
9595
}
9696

9797
//+kubebuilder:rbac:groups="postgres-operator.crunchydata.com",resources="crunchybridgeclusters",verbs={get,patch,update}
@@ -684,7 +684,7 @@ func (r *CrunchyBridgeClusterReconciler) GetSecretKeys(
684684
}}
685685

686686
err := errors.WithStack(
687-
r.Client.Get(ctx, client.ObjectKeyFromObject(existing), existing))
687+
r.Get(ctx, client.ObjectKeyFromObject(existing), existing))
688688

689689
if err == nil {
690690
if existing.Data["key"] != nil && existing.Data["team"] != nil {
@@ -707,7 +707,7 @@ func (r *CrunchyBridgeClusterReconciler) deleteControlled(
707707
version := object.GetResourceVersion()
708708
exactly := client.Preconditions{UID: &uid, ResourceVersion: &version}
709709

710-
return r.Client.Delete(ctx, object, exactly)
710+
return r.Delete(ctx, object, exactly)
711711
}
712712

713713
return nil

internal/bridge/crunchybridgecluster/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (r *CrunchyBridgeClusterReconciler) handleDelete(
2828
log := ctrl.LoggerFrom(ctx)
2929

3030
// If the CrunchyBridgeCluster isn't being deleted, add the finalizer
31-
if crunchybridgecluster.ObjectMeta.DeletionTimestamp.IsZero() {
31+
if crunchybridgecluster.DeletionTimestamp.IsZero() {
3232
if !controllerutil.ContainsFinalizer(crunchybridgecluster, finalizer) {
3333
controllerutil.AddFinalizer(crunchybridgecluster, finalizer)
3434
if err := r.Update(ctx, crunchybridgecluster); err != nil {

internal/bridge/crunchybridgecluster/delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestHandleDeleteCluster(t *testing.T) {
6565

6666
// Get cluster from kubernetes and assert that the deletion timestamp was added
6767
assert.NilError(t, tClient.Get(ctx, client.ObjectKeyFromObject(cluster), cluster))
68-
assert.Check(t, !cluster.ObjectMeta.DeletionTimestamp.IsZero())
68+
assert.Check(t, !cluster.DeletionTimestamp.IsZero())
6969

7070
// Note: We must run handleDelete multiple times because we don't want to remove the
7171
// finalizer until we're sure that the cluster has been deleted from Bridge, so we
@@ -107,7 +107,7 @@ func TestHandleDeleteCluster(t *testing.T) {
107107

108108
// Get cluster from kubernetes and assert that the deletion timestamp was added
109109
assert.NilError(t, tClient.Get(ctx, client.ObjectKeyFromObject(cluster), cluster))
110-
assert.Check(t, !cluster.ObjectMeta.DeletionTimestamp.IsZero())
110+
assert.Check(t, !cluster.DeletionTimestamp.IsZero())
111111

112112
// Run handleDelete again to attempt to delete from Bridge, but provide bad api key
113113
cluster.Status.ID = "2345"

internal/bridge/crunchybridgecluster/mock_bridge_api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/crunchydata/postgres-operator/internal/bridge"
1515
"github.com/crunchydata/postgres-operator/internal/initialize"
16-
1716
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1817
)
1918

internal/bridge/crunchybridgecluster/postgres.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/pkg/errors"
1212
corev1 "k8s.io/api/core/v1"
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
1514
ctrl "sigs.k8s.io/controller-runtime"
1615
"sigs.k8s.io/controller-runtime/pkg/client"
1716

@@ -93,7 +92,7 @@ func (r *CrunchyBridgeClusterReconciler) reconcilePostgresRoleSecrets(
9392
// Make sure that this cluster's role secret names are not being used by any other
9493
// secrets in the namespace
9594
allSecretsInNamespace := &corev1.SecretList{}
96-
err := errors.WithStack(r.Client.List(ctx, allSecretsInNamespace, client.InNamespace(cluster.Namespace)))
95+
err := errors.WithStack(r.List(ctx, allSecretsInNamespace, client.InNamespace(cluster.Namespace)))
9796
if err != nil {
9897
return nil, nil, err
9998
}
@@ -116,7 +115,7 @@ func (r *CrunchyBridgeClusterReconciler) reconcilePostgresRoleSecrets(
116115
selector, err := naming.AsSelector(naming.CrunchyBridgeClusterPostgresRoles(cluster.Name))
117116
if err == nil {
118117
err = errors.WithStack(
119-
r.Client.List(ctx, secrets,
118+
r.List(ctx, secrets,
120119
client.InNamespace(cluster.Namespace),
121120
client.MatchingLabelsSelector{Selector: selector},
122121
))

internal/bridge/crunchybridgecluster/postgres_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
"context"
99
"testing"
1010

11-
"sigs.k8s.io/controller-runtime/pkg/client"
12-
1311
"gotest.tools/v3/assert"
1412
corev1 "k8s.io/api/core/v1"
1513
apierrors "k8s.io/apimachinery/pkg/api/errors"
1614
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
"sigs.k8s.io/controller-runtime/pkg/client"
1716

1817
"github.com/crunchydata/postgres-operator/internal/bridge"
1918
"github.com/crunchydata/postgres-operator/internal/testing/require"

internal/bridge/installation_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestInstallationReconcile(t *testing.T) {
9999

100100
reconciler.NewClient = func() *Client {
101101
c := NewClient(server.URL, "")
102-
c.Backoff.Steps = 1
102+
c.Steps = 1
103103
assert.Equal(t, c.BaseURL.String(), server.URL)
104104
return c
105105
}
@@ -155,7 +155,7 @@ func TestInstallationReconcile(t *testing.T) {
155155

156156
reconciler.NewClient = func() *Client {
157157
c := NewClient(server.URL, "")
158-
c.Backoff.Steps = 1
158+
c.Steps = 1
159159
assert.Equal(t, c.BaseURL.String(), server.URL)
160160
return c
161161
}
@@ -289,7 +289,7 @@ func TestInstallationReconcile(t *testing.T) {
289289

290290
reconciler.NewClient = func() *Client {
291291
c := NewClient(server.URL, "")
292-
c.Backoff.Steps = 1
292+
c.Steps = 1
293293
assert.Equal(t, c.BaseURL.String(), server.URL)
294294
return c
295295
}
@@ -343,7 +343,7 @@ func TestInstallationReconcile(t *testing.T) {
343343

344344
reconciler.NewClient = func() *Client {
345345
c := NewClient(server.URL, "")
346-
c.Backoff.Steps = 1
346+
c.Steps = 1
347347
assert.Equal(t, c.BaseURL.String(), server.URL)
348348
return c
349349
}
@@ -426,7 +426,7 @@ func TestInstallationReconcile(t *testing.T) {
426426

427427
reconciler.NewClient = func() *Client {
428428
c := NewClient(server.URL, "")
429-
c.Backoff.Steps = 1
429+
c.Steps = 1
430430
assert.Equal(t, c.BaseURL.String(), server.URL)
431431
return c
432432
}

0 commit comments

Comments
 (0)