Skip to content

Commit 4ce71d7

Browse files
tony-landrethtony-landreth
tony-landreth
authored andcommitted
Responds to linter feedback
1 parent 2c45df7 commit 4ce71d7

37 files changed

+163
-159
lines changed

.golangci.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ formatters:
149149
- third_party$
150150
- builtin$
151151
- examples$
152+
issues:
153+
# Disable max issues limit (default is 50)
154+
max-issues-per-linter: 0
155+
max-same-issues: 0

internal/bridge/client.go

+1-1
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

internal/bridge/client_test.go

+9-9
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

+1-1
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

+3-3
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

+1-1
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

+2-2
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/postgres.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (r *CrunchyBridgeClusterReconciler) reconcilePostgresRoleSecrets(
9292
// Make sure that this cluster's role secret names are not being used by any other
9393
// secrets in the namespace
9494
allSecretsInNamespace := &corev1.SecretList{}
95-
err := errors.WithStack(r.Client.List(ctx, allSecretsInNamespace, client.InNamespace(cluster.Namespace)))
95+
err := errors.WithStack(r.List(ctx, allSecretsInNamespace, client.InNamespace(cluster.Namespace)))
9696
if err != nil {
9797
return nil, nil, err
9898
}
@@ -115,7 +115,7 @@ func (r *CrunchyBridgeClusterReconciler) reconcilePostgresRoleSecrets(
115115
selector, err := naming.AsSelector(naming.CrunchyBridgeClusterPostgresRoles(cluster.Name))
116116
if err == nil {
117117
err = errors.WithStack(
118-
r.Client.List(ctx, secrets,
118+
r.List(ctx, secrets,
119119
client.InNamespace(cluster.Namespace),
120120
client.MatchingLabelsSelector{Selector: selector},
121121
))

internal/bridge/installation_test.go

+5-5
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
}

internal/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func VerifyImageValues(cluster *v1beta1.PostgresCluster) error {
173173
}
174174

175175
if len(images) > 0 {
176-
return fmt.Errorf("Missing image(s): %s", images)
176+
return fmt.Errorf("missing image(s): %s", images)
177177
}
178178

179179
return nil

internal/controller/pgupgrade/jobs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func pgUpgradeContainerImage(upgrade *v1beta1.PGUpgrade) string {
354354
// spec is defined. If it is undefined, an error is returned.
355355
func verifyUpgradeImageValue(upgrade *v1beta1.PGUpgrade) error {
356356
if pgUpgradeContainerImage(upgrade) == "" {
357-
return fmt.Errorf("Missing crunchy-upgrade image")
357+
return fmt.Errorf("missing crunchy-upgrade image")
358358
}
359359
return nil
360360
}

internal/controller/postgrescluster/cluster_test.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ func TestCustomLabels(t *testing.T) {
137137

138138
t.Run("Cluster", func(t *testing.T) {
139139
cluster := testCluster()
140-
cluster.ObjectMeta.Name = "global-cluster"
141-
cluster.ObjectMeta.Namespace = ns.Name
140+
cluster.Name = "global-cluster"
141+
cluster.Namespace = ns.Name
142142
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
143143
Name: "daisy-instance1",
144144
Replicas: initialize.Int32(1),
@@ -185,8 +185,8 @@ func TestCustomLabels(t *testing.T) {
185185

186186
t.Run("Instance", func(t *testing.T) {
187187
cluster := testCluster()
188-
cluster.ObjectMeta.Name = "instance-cluster"
189-
cluster.ObjectMeta.Namespace = ns.Name
188+
cluster.Name = "instance-cluster"
189+
cluster.Namespace = ns.Name
190190
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
191191
Name: "max-instance",
192192
Replicas: initialize.Int32(1),
@@ -236,8 +236,8 @@ func TestCustomLabels(t *testing.T) {
236236

237237
t.Run("PGBackRest", func(t *testing.T) {
238238
cluster := testCluster()
239-
cluster.ObjectMeta.Name = "pgbackrest-cluster"
240-
cluster.ObjectMeta.Namespace = ns.Name
239+
cluster.Name = "pgbackrest-cluster"
240+
cluster.Namespace = ns.Name
241241
cluster.Spec.Backups.PGBackRest.Metadata = &v1beta1.Metadata{
242242
Labels: map[string]string{"my.pgbackrest.label": "lucy"},
243243
}
@@ -280,8 +280,8 @@ func TestCustomLabels(t *testing.T) {
280280

281281
t.Run("PGBouncer", func(t *testing.T) {
282282
cluster := testCluster()
283-
cluster.ObjectMeta.Name = "pgbouncer-cluster"
284-
cluster.ObjectMeta.Namespace = ns.Name
283+
cluster.Name = "pgbouncer-cluster"
284+
cluster.Namespace = ns.Name
285285
cluster.Spec.Proxy.PGBouncer.Metadata = &v1beta1.Metadata{
286286
Labels: map[string]string{"my.pgbouncer.label": "lucy"},
287287
}
@@ -375,8 +375,8 @@ func TestCustomAnnotations(t *testing.T) {
375375

376376
t.Run("Cluster", func(t *testing.T) {
377377
cluster := testCluster()
378-
cluster.ObjectMeta.Name = "global-cluster"
379-
cluster.ObjectMeta.Namespace = ns.Name
378+
cluster.Name = "global-cluster"
379+
cluster.Namespace = ns.Name
380380
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
381381
Name: "daisy-instance1",
382382
Replicas: initialize.Int32(1),
@@ -424,8 +424,8 @@ func TestCustomAnnotations(t *testing.T) {
424424

425425
t.Run("Instance", func(t *testing.T) {
426426
cluster := testCluster()
427-
cluster.ObjectMeta.Name = "instance-cluster"
428-
cluster.ObjectMeta.Namespace = ns.Name
427+
cluster.Name = "instance-cluster"
428+
cluster.Namespace = ns.Name
429429
cluster.Spec.InstanceSets = []v1beta1.PostgresInstanceSetSpec{{
430430
Name: "max-instance",
431431
Replicas: initialize.Int32(1),
@@ -475,8 +475,8 @@ func TestCustomAnnotations(t *testing.T) {
475475

476476
t.Run("PGBackRest", func(t *testing.T) {
477477
cluster := testCluster()
478-
cluster.ObjectMeta.Name = "pgbackrest-cluster"
479-
cluster.ObjectMeta.Namespace = ns.Name
478+
cluster.Name = "pgbackrest-cluster"
479+
cluster.Namespace = ns.Name
480480
cluster.Spec.Backups.PGBackRest.Metadata = &v1beta1.Metadata{
481481
Annotations: map[string]string{"my.pgbackrest.annotation": "lucy"},
482482
}
@@ -519,8 +519,8 @@ func TestCustomAnnotations(t *testing.T) {
519519

520520
t.Run("PGBouncer", func(t *testing.T) {
521521
cluster := testCluster()
522-
cluster.ObjectMeta.Name = "pgbouncer-cluster"
523-
cluster.ObjectMeta.Namespace = ns.Name
522+
cluster.Name = "pgbouncer-cluster"
523+
cluster.Namespace = ns.Name
524524
cluster.Spec.Proxy.PGBouncer.Metadata = &v1beta1.Metadata{
525525
Annotations: map[string]string{"my.pgbouncer.annotation": "lucy"},
526526
}
@@ -768,12 +768,12 @@ type: ClusterIP
768768
assert.NilError(t, err)
769769

770770
// Annotations present in the metadata.
771-
assert.Assert(t, cmp.MarshalMatches(service.ObjectMeta.Annotations, `
771+
assert.Assert(t, cmp.MarshalMatches(service.Annotations, `
772772
some: note
773773
`))
774774

775775
// Labels present in the metadata.
776-
assert.Assert(t, cmp.MarshalMatches(service.ObjectMeta.Labels, `
776+
assert.Assert(t, cmp.MarshalMatches(service.Labels, `
777777
happy: label
778778
postgres-operator.crunchydata.com/cluster: pg2
779779
postgres-operator.crunchydata.com/role: replica

internal/controller/postgrescluster/patroni_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ ownerReferences:
9797
assert.NilError(t, err)
9898

9999
// Annotations present in the metadata.
100-
assert.DeepEqual(t, service.ObjectMeta.Annotations, map[string]string{
100+
assert.DeepEqual(t, service.Annotations, map[string]string{
101101
"a": "v1",
102102
})
103103

104104
// Labels present in the metadata.
105-
assert.DeepEqual(t, service.ObjectMeta.Labels, map[string]string{
105+
assert.DeepEqual(t, service.Labels, map[string]string{
106106
"b": "v2",
107107
"postgres-operator.crunchydata.com/cluster": "pg2",
108108
"postgres-operator.crunchydata.com/patroni": "pg2-ha",
@@ -125,13 +125,13 @@ ownerReferences:
125125
assert.NilError(t, err)
126126

127127
// Annotations present in the metadata.
128-
assert.DeepEqual(t, service.ObjectMeta.Annotations, map[string]string{
128+
assert.DeepEqual(t, service.Annotations, map[string]string{
129129
"a": "v1",
130130
"c": "v3",
131131
})
132132

133133
// Labels present in the metadata.
134-
assert.DeepEqual(t, service.ObjectMeta.Labels, map[string]string{
134+
assert.DeepEqual(t, service.Labels, map[string]string{
135135
"b": "v2",
136136
"d": "v4",
137137
"postgres-operator.crunchydata.com/cluster": "pg2",
@@ -472,8 +472,8 @@ func TestReconcilePatroniStatus(t *testing.T) {
472472
ObjectMeta: naming.PatroniDistributedConfiguration(postgresCluster),
473473
}
474474
if writeAnnotation {
475-
endpoints.ObjectMeta.Annotations = make(map[string]string)
476-
endpoints.ObjectMeta.Annotations["initialize"] = systemIdentifier
475+
endpoints.Annotations = make(map[string]string)
476+
endpoints.Annotations["initialize"] = systemIdentifier
477477
}
478478
assert.NilError(t, tClient.Create(ctx, endpoints, &client.CreateOptions{}))
479479

0 commit comments

Comments
 (0)