Merge pull request #103023 from tiloso/staticcheck-apiserver-clientgo
Fix staticcheck in k8s.io/{apiserver/pkg/storage,client-go/rest/watch}
Kubernetes-commit: 95390e6476fca15b0f55cde2c142ec18ca57aee0
This commit is contained in:
commit
40e3125ca9
4
go.mod
4
go.mod
|
|
@ -47,7 +47,7 @@ require (
|
|||
gopkg.in/square/go-jose.v2 v2.2.2
|
||||
k8s.io/api v0.0.0-20210908033022-d21f9c983267
|
||||
k8s.io/apimachinery v0.0.0-20210908032828-9fff050305a4
|
||||
k8s.io/client-go v0.0.0-20210901080746-a31b18a6ac98
|
||||
k8s.io/client-go v0.0.0-20210909033324-84f9a96f0692
|
||||
k8s.io/component-base v0.0.0-20210901040900-bed685b9e6f5
|
||||
k8s.io/klog/v2 v2.9.0
|
||||
k8s.io/kube-openapi v0.0.0-20210817084001-7fbd8d59e5b8
|
||||
|
|
@ -60,6 +60,6 @@ require (
|
|||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20210908033022-d21f9c983267
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210908032828-9fff050305a4
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20210901080746-a31b18a6ac98
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20210909033324-84f9a96f0692
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20210901040900-bed685b9e6f5
|
||||
)
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -943,8 +943,8 @@ k8s.io/api v0.0.0-20210908033022-d21f9c983267 h1:vq/GfYuNAtReYwup5R1uEGEIvwHtZIV
|
|||
k8s.io/api v0.0.0-20210908033022-d21f9c983267/go.mod h1:c9QgRUT16khyA/63Nk32bm7l2r3/kd5zvB45ofzM0N0=
|
||||
k8s.io/apimachinery v0.0.0-20210908032828-9fff050305a4 h1:m0WqN0kyu1lmvNxu0J3NwNoCBPBsIxFfpSM4QtJH2eA=
|
||||
k8s.io/apimachinery v0.0.0-20210908032828-9fff050305a4/go.mod h1:YwXrbrp8hgDAA01lpP9HPMC6PS55tjfs3EAatyMMfeM=
|
||||
k8s.io/client-go v0.0.0-20210901080746-a31b18a6ac98 h1:1LPKIcr86ISGq5rqn83aw+Mjj/U4beT7FeXS6phRKbA=
|
||||
k8s.io/client-go v0.0.0-20210901080746-a31b18a6ac98/go.mod h1:LoKqAR7bihkfO2dEj4ExEfomATALXYAb4dj5K9ZVaT8=
|
||||
k8s.io/client-go v0.0.0-20210909033324-84f9a96f0692 h1:N+TDzFe9yy8Bzcu+J94HQlatyXH6d2a5E1hc8k+hGoI=
|
||||
k8s.io/client-go v0.0.0-20210909033324-84f9a96f0692/go.mod h1:gKL6iSLRLlXHp066tvf0uHU8bHcEjMPz/voCRzh+bmQ=
|
||||
k8s.io/component-base v0.0.0-20210901040900-bed685b9e6f5 h1:qdnAC/+ttUxQ4Xhsk+zTX7UAdmCB2NZThIenpzu3lgU=
|
||||
k8s.io/component-base v0.0.0-20210901040900-bed685b9e6f5/go.mod h1:qzazD/5P6Dbqm3mFJ5CzzrxN4Bi8hHMC/hGVlq+Y+6k=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package cacher
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
goruntime "runtime"
|
||||
|
|
@ -649,6 +650,7 @@ func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {
|
|||
|
||||
// run the collision test for 3 seconds to let ~2 buckets expire
|
||||
stopCh := make(chan struct{})
|
||||
var watchErr error
|
||||
time.AfterFunc(3*time.Second, func() { close(stopCh) })
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
|
|
@ -664,7 +666,8 @@ func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {
|
|||
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
w, err := cacher.Watch(ctx, "pods/ns", storage.ListOptions{ResourceVersion: "0", Predicate: pred})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create watch: %v", err)
|
||||
watchErr = fmt.Errorf("Failed to create watch: %v", err)
|
||||
return
|
||||
}
|
||||
w.Stop()
|
||||
}
|
||||
|
|
@ -687,6 +690,10 @@ func TestCacherNoLeakWithMultipleWatchers(t *testing.T) {
|
|||
// wait for adding/removing watchers to end
|
||||
wg.Wait()
|
||||
|
||||
if watchErr != nil {
|
||||
t.Fatal(watchErr)
|
||||
}
|
||||
|
||||
// wait out the expiration period and pop expired watchers
|
||||
time.Sleep(2 * time.Second)
|
||||
cacher.bookmarkWatchers.popExpiredWatchers()
|
||||
|
|
@ -742,6 +749,7 @@ func testCacherSendBookmarkEvents(t *testing.T, allowWatchBookmarks, expectedBoo
|
|||
}
|
||||
|
||||
resourceVersion := uint64(1000)
|
||||
errc := make(chan error, 1)
|
||||
go func() {
|
||||
deadline := time.Now().Add(time.Second)
|
||||
for i := 0; time.Now().Before(deadline); i++ {
|
||||
|
|
@ -752,7 +760,8 @@ func testCacherSendBookmarkEvents(t *testing.T, allowWatchBookmarks, expectedBoo
|
|||
ResourceVersion: fmt.Sprintf("%v", resourceVersion+uint64(i)),
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to add a pod: %v", err)
|
||||
errc <- fmt.Errorf("failed to add a pod: %v", err)
|
||||
return
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
|
@ -762,6 +771,9 @@ func testCacherSendBookmarkEvents(t *testing.T, allowWatchBookmarks, expectedBoo
|
|||
lastObservedRV := uint64(0)
|
||||
for {
|
||||
select {
|
||||
case err := <-errc:
|
||||
t.Fatal(err)
|
||||
return
|
||||
case event, ok := <-w.ResultChan():
|
||||
if !ok {
|
||||
t.Fatal("Unexpected closed")
|
||||
|
|
@ -945,7 +957,6 @@ func TestDispatchingBookmarkEventsWithConcurrentStop(t *testing.T) {
|
|||
|
||||
select {
|
||||
case <-done:
|
||||
break
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("receive result timeout")
|
||||
}
|
||||
|
|
@ -994,6 +1005,8 @@ func TestBookmarksOnResourceVersionUpdates(t *testing.T) {
|
|||
|
||||
expectedRV := 2000
|
||||
|
||||
var rcErr error
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
|
|
@ -1001,7 +1014,8 @@ func TestBookmarksOnResourceVersionUpdates(t *testing.T) {
|
|||
for {
|
||||
event, ok := <-w.ResultChan()
|
||||
if !ok {
|
||||
t.Fatalf("Unexpected closed channel")
|
||||
rcErr = errors.New("Unexpected closed channel")
|
||||
return
|
||||
}
|
||||
rv, err := cacher.versioner.ObjectResourceVersion(event.Object)
|
||||
if err != nil {
|
||||
|
|
@ -1017,6 +1031,9 @@ func TestBookmarksOnResourceVersionUpdates(t *testing.T) {
|
|||
cacher.watchCache.UpdateResourceVersion(strconv.Itoa(expectedRV))
|
||||
|
||||
wg.Wait()
|
||||
if rcErr != nil {
|
||||
t.Fatal(rcErr)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeTimeBudget struct{}
|
||||
|
|
|
|||
|
|
@ -149,7 +149,8 @@ func TestCachingObjectRaces(t *testing.T) {
|
|||
}
|
||||
accessor, err := meta.Accessor(object.GetObject())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get accessor: %v", err)
|
||||
t.Errorf("failed to get accessor: %v", err)
|
||||
return
|
||||
}
|
||||
if selfLink := accessor.GetSelfLink(); selfLink != "selfLink" {
|
||||
t.Errorf("unexpected selfLink: %s", selfLink)
|
||||
|
|
|
|||
|
|
@ -887,6 +887,7 @@ func TestWatchBookmarksWithCorrectResourceVersion(t *testing.T) {
|
|||
defer watcher.Stop()
|
||||
|
||||
done := make(chan struct{})
|
||||
errc := make(chan error, 1)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
defer wg.Wait() // We must wait for the waitgroup to exit before we terminate the cache or the server in prior defers
|
||||
|
|
@ -901,7 +902,8 @@ func TestWatchBookmarksWithCorrectResourceVersion(t *testing.T) {
|
|||
pod := fmt.Sprintf("foo-%d", i)
|
||||
err := createPod(etcdStorage, makeTestPod(pod))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create pod %v: %v", pod, err)
|
||||
errc <- fmt.Errorf("failed to create pod %v: %v", pod, err)
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Second / 100)
|
||||
}
|
||||
|
|
@ -910,27 +912,36 @@ func TestWatchBookmarksWithCorrectResourceVersion(t *testing.T) {
|
|||
|
||||
bookmarkReceived := false
|
||||
lastObservedResourceVersion := uint64(0)
|
||||
for event := range watcher.ResultChan() {
|
||||
rv, err := v.ObjectResourceVersion(event.Object)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse resourceVersion from %#v", event)
|
||||
}
|
||||
if event.Type == watch.Bookmark {
|
||||
bookmarkReceived = true
|
||||
// bookmark event has a RV greater than or equal to the before one
|
||||
if rv < lastObservedResourceVersion {
|
||||
t.Fatalf("Unexpected bookmark resourceVersion %v less than observed %v)", rv, lastObservedResourceVersion)
|
||||
|
||||
for {
|
||||
select {
|
||||
case err := <-errc:
|
||||
t.Fatal(err)
|
||||
case event, ok := <-watcher.ResultChan():
|
||||
if !ok {
|
||||
// Make sure we have received a bookmark event
|
||||
if !bookmarkReceived {
|
||||
t.Fatalf("Unpexected error, we did not received a bookmark event")
|
||||
}
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// non-bookmark event has a RV greater than anything before
|
||||
if rv <= lastObservedResourceVersion {
|
||||
t.Fatalf("Unexpected event resourceVersion %v less than or equal to bookmark %v)", rv, lastObservedResourceVersion)
|
||||
rv, err := v.ObjectResourceVersion(event.Object)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse resourceVersion from %#v", event)
|
||||
}
|
||||
if event.Type == watch.Bookmark {
|
||||
bookmarkReceived = true
|
||||
// bookmark event has a RV greater than or equal to the before one
|
||||
if rv < lastObservedResourceVersion {
|
||||
t.Fatalf("Unexpected bookmark resourceVersion %v less than observed %v)", rv, lastObservedResourceVersion)
|
||||
}
|
||||
} else {
|
||||
// non-bookmark event has a RV greater than anything before
|
||||
if rv <= lastObservedResourceVersion {
|
||||
t.Fatalf("Unexpected event resourceVersion %v less than or equal to bookmark %v)", rv, lastObservedResourceVersion)
|
||||
}
|
||||
}
|
||||
lastObservedResourceVersion = rv
|
||||
}
|
||||
lastObservedResourceVersion = rv
|
||||
}
|
||||
// Make sure we have received a bookmark event
|
||||
if !bookmarkReceived {
|
||||
t.Fatalf("Unpexected error, we did not received a bookmark event")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,12 +186,13 @@ func TestTimeouts(t *testing.T) {
|
|||
func TestIntermittentConnectionLoss(t *testing.T) {
|
||||
t.Parallel()
|
||||
var (
|
||||
wg1 sync.WaitGroup
|
||||
wg2 sync.WaitGroup
|
||||
timeout = 30 * time.Second
|
||||
blackOut = 1 * time.Second
|
||||
data = []byte("test data")
|
||||
endpoint = newEndpoint()
|
||||
wg1 sync.WaitGroup
|
||||
wg2 sync.WaitGroup
|
||||
timeout = 30 * time.Second
|
||||
blackOut = 1 * time.Second
|
||||
data = []byte("test data")
|
||||
endpoint = newEndpoint()
|
||||
encryptErr error
|
||||
)
|
||||
// Start KMS Plugin
|
||||
f, err := mock.NewBase64Plugin(endpoint.path)
|
||||
|
|
@ -229,7 +230,7 @@ func TestIntermittentConnectionLoss(t *testing.T) {
|
|||
wg1.Done()
|
||||
_, err := service.Encrypt(data)
|
||||
if err != nil {
|
||||
t.Fatalf("failed when executing encrypt, error: %v", err)
|
||||
encryptErr = fmt.Errorf("failed when executing encrypt, error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -247,6 +248,10 @@ func TestIntermittentConnectionLoss(t *testing.T) {
|
|||
t.Log("Restarted KMS Plugin")
|
||||
|
||||
wg2.Wait()
|
||||
|
||||
if encryptErr != nil {
|
||||
t.Error(encryptErr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsupportedVersion(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue