Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fake dynamic client listing bug #66078

Merged
merged 1 commit into from Jul 17, 2018

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Jul 11, 2018

The fake dynamic client used for unit testing had a bug that prevented list from working. Added a test and fixed the fake client.

@kubernetes/sig-api-machinery-bugs
/assign @tnozicka

NONE

@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Jul 11, 2018
@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 11, 2018
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 11, 2018
@fedebongio
Copy link
Contributor

/cc @caesarxuchao

Copy link
Contributor

@tnozicka tnozicka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deads thanks for the fix to unblock #50102

looks good and works in my branch where I've encountered this issue

if err != nil {
t.Fatal(err)
}
if len(listFirst.Items) != 3 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd prefer to verify the content with DeepEqual

@@ -33,6 +33,10 @@ import (
)

func NewSimpleDynamicClient(scheme *runtime.Scheme, objects ...runtime.Object) *FakeDynamicClient {
// in order to use List with this client, you have to have the v1.List registered in your scheme. Neat thing though
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/in/In

@deads2k
Copy link
Contributor Author

deads2k commented Jul 17, 2018

Nits addressed

@deads2k deads2k added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 17, 2018
@tnozicka
Copy link
Contributor

/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deads2k, tnozicka

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit da1bb02 into kubernetes:master Jul 17, 2018
@@ -33,6 +33,10 @@ import (
)

func NewSimpleDynamicClient(scheme *runtime.Scheme, objects ...runtime.Object) *FakeDynamicClient {
// In order to use List with this client, you have to have the v1.List registered in your scheme. Neat thing though
// it does NOT have to be the *same* list
scheme.AddKnownTypeWithName(schema.GroupVersionKind{Group: "fake-dynamic-client-group", Version: "v1", Kind: "List"}, &unstructured.UnstructuredList{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deads2k unfortunatelly this always writes to


making that a data race (if the scheme is reused between test runs) with informers (calling scheme.New and reading that map)

Copy link
Contributor

@tnozicka tnozicka Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the record:
(note that this is not master, but my branch switching pkg/cmd/kubectl/wait to informers)

 go test -race ./pkg/kubectl/cmd/wait 
==================
WARNING: DATA RACE
Write at 0x00c4205641b0 by goroutine 52:
  runtime.mapassign()
      /home/tnozicka/lib/go1.10.3/src/runtime/hashmap.go:505 +0x0
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime.(*Scheme).AddKnownTypeWithName()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go:206 +0x2fd
  k8s.io/kubernetes/vendor/k8s.io/client-go/dynamic/fake.NewSimpleDynamicClient()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/dynamic/fake/simple.go:38 +0xdc
  k8s.io/kubernetes/pkg/kubectl/cmd/wait.TestWaitForCondition.func3()
      /home/tnozicka/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/wait/wait_test.go:206 +0x9d
  k8s.io/kubernetes/pkg/kubectl/cmd/wait.TestWaitForCondition.func4()
      /home/tnozicka/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/wait/wait_test.go:227 +0x85
  testing.tRunner()
      /home/tnozicka/lib/go1.10.3/src/testing/testing.go:777 +0x16d

Previous read at 0x00c4205641b0 by goroutine 49:
  runtime.mapaccess2()
      /home/tnozicka/lib/go1.10.3/src/runtime/hashmap.go:395 +0x0
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime.(*Scheme).New()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/runtime/scheme.go:289 +0xa0
  k8s.io/kubernetes/vendor/k8s.io/client-go/testing.(*tracker).List()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/testing/fixture.go:201 +0x140
  k8s.io/kubernetes/vendor/k8s.io/client-go/testing.ObjectReaction.func1()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/testing/fixture.go:84 +0x14f1
  k8s.io/kubernetes/vendor/k8s.io/client-go/testing.(*SimpleReactor).React()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/testing/fixture.go:487 +0x64
  k8s.io/kubernetes/vendor/k8s.io/client-go/testing.(*Fake).Invokes()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/testing/fake.go:140 +0x275
  k8s.io/kubernetes/vendor/k8s.io/client-go/dynamic/fake.(*dynamicResourceClient).List()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/dynamic/fake/simple.go:283 +0xc8b
  k8s.io/kubernetes/pkg/kubectl/cmd/wait.InformerWait.func1()
      /home/tnozicka/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/wait/wait.go:234 +0x1a1
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/pager.SimplePageFunc.func1()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/pager/pager.go:38 +0x84
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/pager.(*ListPager).List()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/pager/pager.go:76 +0x148
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache.(*ListWatch).List()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache/listwatch.go:106 +0x239
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache.(*Reflector).ListAndWatch()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache/reflector.go:178 +0x2fd
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache.(*Reflector).Run.func1()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache/reflector.go:133 +0x4a
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:133 +0x61
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:134 +0xcd
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.Until()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:88 +0x5a
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache.(*Reflector).Run()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache/reflector.go:132 +0x256
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache.(*Reflector).Run-fm()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache/controller.go:122 +0x4b
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.(*Group).StartWithChannel.func1()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:54 +0x45
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.(*Group).Start.func1()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:71 +0x5c

Goroutine 52 (running) created at:
  testing.(*T).Run()
      /home/tnozicka/lib/go1.10.3/src/testing/testing.go:824 +0x564
  k8s.io/kubernetes/pkg/kubectl/cmd/wait.TestWaitForCondition()
      /home/tnozicka/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/wait/wait_test.go:226 +0x80b
  testing.tRunner()
      /home/tnozicka/lib/go1.10.3/src/testing/testing.go:777 +0x16d

Goroutine 49 (finished) created at:
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.(*Group).Start()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:69 +0x6f
  k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait.(*Group).StartWithChannel()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:53 +0xc7
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache.(*controller).Run()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/cache/controller.go:122 +0x38a
  k8s.io/kubernetes/vendor/k8s.io/client-go/tools/watch.NewIndexerInformerWatcher.func4()
      /home/tnozicka/go/src/k8s.io/kubernetes/vendor/k8s.io/client-go/tools/watch/informerwatcher.go:104 +0x5e

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making that a data race (if the scheme is reused between test runs) with informers (calling scheme.New and reading that map)

don't reuse the scheme.

@deads2k deads2k added this to the v1.11 milestone Sep 12, 2018
k8s-ci-robot added a commit that referenced this pull request Oct 4, 2018
…66078-upstream-release-1.11

Automated cherry pick of #66078: fix dynamic client listing bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants