Skip to content

Commit db8a887

Browse files
authored
Merge pull request kubernetes#81742 from praseodym/fix-staticcheck-pkg/registry
Fix staticcheck failures for pkg/registry/...
2 parents ad63459 + e3a0ca2 commit db8a887

File tree

8 files changed

+23
-18
lines changed

8 files changed

+23
-18
lines changed

hack/.staticcheck_failures

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ pkg/controller/podautoscaler
66
pkg/controller/replicaset
77
pkg/controller/resourcequota
88
pkg/controller/statefulset
9-
pkg/registry/autoscaling/horizontalpodautoscaler/storage
10-
pkg/registry/core/namespace/storage
11-
pkg/registry/core/persistentvolumeclaim/storage
12-
pkg/registry/core/resourcequota/storage
13-
pkg/registry/core/service/ipallocator
14-
pkg/registry/core/service/portallocator
15-
pkg/registry/core/service/storage
169
pkg/util/coverage
1710
test/e2e/apps
1811
test/e2e/autoscaling

pkg/registry/autoscaling/horizontalpodautoscaler/storage/storage_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func TestUpdateStatus(t *testing.T) {
205205
t.Fatalf("Unexpected error: %v", err)
206206
}
207207
obj, err := storage.Get(ctx, "foo", &metav1.GetOptions{})
208+
if err != nil {
209+
t.Fatalf("Unexpected error: %v", err)
210+
}
208211
autoscalerOut := obj.(*autoscaling.HorizontalPodAutoscaler)
209212
// only compare the meaningful update b/c we can't compare due to metadata
210213
if !apiequality.Semantic.DeepEqual(autoscalerIn.Status, autoscalerOut.Status) {

pkg/registry/core/namespace/storage/storage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ func ShouldDeleteNamespaceDuringUpdate(ctx context.Context, key string, obj, exi
253253
}
254254

255255
func shouldHaveOrphanFinalizer(options *metav1.DeleteOptions, haveOrphanFinalizer bool) bool {
256+
//lint:ignore SA1019 backwards compatibility
256257
if options.OrphanDependents != nil {
258+
//lint:ignore SA1019 backwards compatibility
257259
return *options.OrphanDependents
258260
}
259261
if options.PropagationPolicy != nil {
@@ -263,7 +265,9 @@ func shouldHaveOrphanFinalizer(options *metav1.DeleteOptions, haveOrphanFinalize
263265
}
264266

265267
func shouldHaveDeleteDependentsFinalizer(options *metav1.DeleteOptions, haveDeleteDependentsFinalizer bool) bool {
268+
//lint:ignore SA1019 backwards compatibility
266269
if options.OrphanDependents != nil {
270+
//lint:ignore SA1019 backwards compatibility
267271
return *options.OrphanDependents == false
268272
}
269273
if options.PropagationPolicy != nil {

pkg/registry/core/persistentvolumeclaim/storage/storage_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ func TestUpdateStatus(t *testing.T) {
163163
key, _ := storage.KeyFunc(ctx, "foo")
164164
pvcStart := validNewPersistentVolumeClaim("foo", metav1.NamespaceDefault)
165165
err := storage.Storage.Create(ctx, key, pvcStart, nil, 0, false)
166+
if err != nil {
167+
t.Fatalf("Unexpected error: %v", err)
168+
}
166169

167170
pvc := &api.PersistentVolumeClaim{
168171
ObjectMeta: metav1.ObjectMeta{

pkg/registry/core/resourcequota/storage/storage_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ func TestUpdateStatus(t *testing.T) {
200200
t.Fatalf("Unexpected error: %v", err)
201201
}
202202
obj, err := storage.Get(ctx, "foo", &metav1.GetOptions{})
203+
if err != nil {
204+
t.Fatalf("Unexpected error: %v", err)
205+
}
203206
rqOut := obj.(*api.ResourceQuota)
204207
// only compare the meaningful update b/c we can't compare due to metadata
205208
if !apiequality.Semantic.DeepEqual(resourcequotaIn.Status, rqOut.Status) {

pkg/registry/core/service/ipallocator/allocator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ func TestSnapshot(t *testing.T) {
335335
if err != nil {
336336
t.Fatal(err)
337337
}
338-
other, err := NewCIDRRange(otherCidr)
338+
_, err = NewCIDRRange(otherCidr)
339339
if err != nil {
340340
t.Fatal(err)
341341
}
342342
if err := r.Restore(otherCidr, dst.Data); err != ErrMismatchedNetwork {
343343
t.Fatal(err)
344344
}
345-
other, err = NewCIDRRange(network)
345+
other, err := NewCIDRRange(network)
346346
if err != nil {
347347
t.Fatal(err)
348348
}

pkg/registry/core/service/portallocator/allocator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ func TestSnapshot(t *testing.T) {
196196
if err != nil {
197197
t.Fatal(err)
198198
}
199-
other, err := NewPortAllocator(*otherPr)
199+
_, err = NewPortAllocator(*otherPr)
200200
if err != nil {
201201
t.Fatal(err)
202202
}
203203
if err := r.Restore(*otherPr, dst.Data); err != ErrMismatchedNetwork {
204204
t.Fatal(err)
205205
}
206-
other, err = NewPortAllocator(*pr2)
206+
other, err := NewPortAllocator(*pr2)
207207
if err != nil {
208208
t.Fatal(err)
209209
}

pkg/registry/core/service/storage/rest_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package storage
1818

1919
import (
20-
"bytes"
2120
"context"
2221
"net"
2322
"reflect"
@@ -1840,13 +1839,13 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
18401839
}
18411840

18421841
// Test a non-existent name + port.
1843-
location, _, err = redirector.ResourceLocation(ctx, "foo:q")
1842+
_, _, err = redirector.ResourceLocation(ctx, "foo:q")
18441843
if err == nil {
18451844
t.Errorf("Unexpected nil error")
18461845
}
18471846

18481847
// Test a non-existent name + port (using second ip).
1849-
location, _, err = redirector.ResourceLocation(ctx, "foo-second-ip:q")
1848+
_, _, err = redirector.ResourceLocation(ctx, "foo-second-ip:q")
18501849
if err == nil {
18511850
t.Errorf("Unexpected nil error")
18521851
}
@@ -3171,22 +3170,22 @@ func TestAllocGetters(t *testing.T) {
31713170

31723171
alloc := storage.getAllocatorByClusterIP(tc.svc)
31733172
if tc.expectClusterIPPrimary {
3174-
if !bytes.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
3173+
if !net.IP.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
31753174
t.Fatalf("expected clusterIP primary allocator, but primary allocator was not selected")
31763175
}
31773176
} else {
3178-
if !bytes.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
3177+
if !net.IP.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
31793178
t.Errorf("expected clusterIP secondary allocator, but secondary allocator was not selected")
31803179
}
31813180
}
31823181

31833182
alloc = storage.getAllocatorBySpec(tc.svc)
31843183
if tc.expectSpecPrimary {
3185-
if !bytes.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
3184+
if !net.IP.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
31863185
t.Errorf("expected spec primary allocator, but primary allocator was not selected")
31873186
}
31883187
} else {
3189-
if !bytes.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
3188+
if !net.IP.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
31903189
t.Errorf("expected spec secondary allocator, but secondary allocator was not selected")
31913190
}
31923191
}

0 commit comments

Comments
 (0)