Merge pull request #81742 from praseodym/fix-staticcheck-pkg/registry

Fix staticcheck failures for pkg/registry/...
This commit is contained in:
Kubernetes Prow Robot 2020-06-23 02:55:41 -07:00 committed by GitHub
commit db8a88721e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 18 deletions

View File

@ -6,13 +6,6 @@ pkg/controller/podautoscaler
pkg/controller/replicaset
pkg/controller/resourcequota
pkg/controller/statefulset
pkg/registry/autoscaling/horizontalpodautoscaler/storage
pkg/registry/core/namespace/storage
pkg/registry/core/persistentvolumeclaim/storage
pkg/registry/core/resourcequota/storage
pkg/registry/core/service/ipallocator
pkg/registry/core/service/portallocator
pkg/registry/core/service/storage
pkg/util/coverage
test/e2e/apps
test/e2e/autoscaling

View File

@ -205,6 +205,9 @@ func TestUpdateStatus(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
obj, err := storage.Get(ctx, "foo", &metav1.GetOptions{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
autoscalerOut := obj.(*autoscaling.HorizontalPodAutoscaler)
// only compare the meaningful update b/c we can't compare due to metadata
if !apiequality.Semantic.DeepEqual(autoscalerIn.Status, autoscalerOut.Status) {

View File

@ -253,7 +253,9 @@ func ShouldDeleteNamespaceDuringUpdate(ctx context.Context, key string, obj, exi
}
func shouldHaveOrphanFinalizer(options *metav1.DeleteOptions, haveOrphanFinalizer bool) bool {
//lint:ignore SA1019 backwards compatibility
if options.OrphanDependents != nil {
//lint:ignore SA1019 backwards compatibility
return *options.OrphanDependents
}
if options.PropagationPolicy != nil {
@ -263,7 +265,9 @@ func shouldHaveOrphanFinalizer(options *metav1.DeleteOptions, haveOrphanFinalize
}
func shouldHaveDeleteDependentsFinalizer(options *metav1.DeleteOptions, haveDeleteDependentsFinalizer bool) bool {
//lint:ignore SA1019 backwards compatibility
if options.OrphanDependents != nil {
//lint:ignore SA1019 backwards compatibility
return *options.OrphanDependents == false
}
if options.PropagationPolicy != nil {

View File

@ -163,6 +163,9 @@ func TestUpdateStatus(t *testing.T) {
key, _ := storage.KeyFunc(ctx, "foo")
pvcStart := validNewPersistentVolumeClaim("foo", metav1.NamespaceDefault)
err := storage.Storage.Create(ctx, key, pvcStart, nil, 0, false)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
pvc := &api.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{

View File

@ -200,6 +200,9 @@ func TestUpdateStatus(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
obj, err := storage.Get(ctx, "foo", &metav1.GetOptions{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
rqOut := obj.(*api.ResourceQuota)
// only compare the meaningful update b/c we can't compare due to metadata
if !apiequality.Semantic.DeepEqual(resourcequotaIn.Status, rqOut.Status) {

View File

@ -335,14 +335,14 @@ func TestSnapshot(t *testing.T) {
if err != nil {
t.Fatal(err)
}
other, err := NewCIDRRange(otherCidr)
_, err = NewCIDRRange(otherCidr)
if err != nil {
t.Fatal(err)
}
if err := r.Restore(otherCidr, dst.Data); err != ErrMismatchedNetwork {
t.Fatal(err)
}
other, err = NewCIDRRange(network)
other, err := NewCIDRRange(network)
if err != nil {
t.Fatal(err)
}

View File

@ -196,14 +196,14 @@ func TestSnapshot(t *testing.T) {
if err != nil {
t.Fatal(err)
}
other, err := NewPortAllocator(*otherPr)
_, err = NewPortAllocator(*otherPr)
if err != nil {
t.Fatal(err)
}
if err := r.Restore(*otherPr, dst.Data); err != ErrMismatchedNetwork {
t.Fatal(err)
}
other, err = NewPortAllocator(*pr2)
other, err := NewPortAllocator(*pr2)
if err != nil {
t.Fatal(err)
}

View File

@ -17,7 +17,6 @@ limitations under the License.
package storage
import (
"bytes"
"context"
"net"
"reflect"
@ -1840,13 +1839,13 @@ func TestServiceRegistryResourceLocation(t *testing.T) {
}
// Test a non-existent name + port.
location, _, err = redirector.ResourceLocation(ctx, "foo:q")
_, _, err = redirector.ResourceLocation(ctx, "foo:q")
if err == nil {
t.Errorf("Unexpected nil error")
}
// Test a non-existent name + port (using second ip).
location, _, err = redirector.ResourceLocation(ctx, "foo-second-ip:q")
_, _, err = redirector.ResourceLocation(ctx, "foo-second-ip:q")
if err == nil {
t.Errorf("Unexpected nil error")
}
@ -3171,22 +3170,22 @@ func TestAllocGetters(t *testing.T) {
alloc := storage.getAllocatorByClusterIP(tc.svc)
if tc.expectClusterIPPrimary {
if !bytes.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
if !net.IP.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
t.Fatalf("expected clusterIP primary allocator, but primary allocator was not selected")
}
} else {
if !bytes.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
if !net.IP.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
t.Errorf("expected clusterIP secondary allocator, but secondary allocator was not selected")
}
}
alloc = storage.getAllocatorBySpec(tc.svc)
if tc.expectSpecPrimary {
if !bytes.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
if !net.IP.Equal(alloc.CIDR().IP, storage.serviceIPs.CIDR().IP) {
t.Errorf("expected spec primary allocator, but primary allocator was not selected")
}
} else {
if !bytes.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
if !net.IP.Equal(alloc.CIDR().IP, storage.secondaryServiceIPs.CIDR().IP) {
t.Errorf("expected spec secondary allocator, but secondary allocator was not selected")
}
}