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

Add client-go example using fake client in test. #65291

Merged
merged 1 commit into from Jun 22, 2018

Conversation

misterikkit
Copy link

@misterikkit misterikkit commented Jun 21, 2018

What this PR does / why we need it:

This adds an example showing the steps needed to get a working
SharedInformerFactory with a fake client for testing.

Special notes for your reviewer:
I had a really hard time figuring out how to use this utility correctly. I don't think this example is sufficient documentation, but it's a good start.

Release note:

NONE

/sig api-machinery
/kind documentation

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/documentation Categorizes issue or PR as related to documentation. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jun 21, 2018
@misterikkit
Copy link
Author

/assign @caesarxuchao

@sttts
Copy link
Contributor

sttts commented Jun 21, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 21, 2018
@misterikkit
Copy link
Author

/assign @lavalamp
/retest

@@ -104,6 +104,7 @@ filegroup(
"//staging/src/k8s.io/client-go/discovery:all-srcs",
"//staging/src/k8s.io/client-go/dynamic:all-srcs",
"//staging/src/k8s.io/client-go/examples/create-update-delete-deployment:all-srcs",
"//staging/src/k8s.io/client-go/examples/fake-client:all-srcs",
Copy link
Member

Choose a reason for hiding this comment

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

@ixdy (please route to better person if not you)--Is there a reason why we need this BUILD file? If so, can we make it not change for every subdir added? It kind of defeats the purpose of having nested OWNERS files.

Copy link
Member

Choose a reason for hiding this comment

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

The package-srcs glob only extends recursively to the next deepest package (i.e. BUILD file), so we have the all-srcs rule which includes that package.

We could create BUILD files in the root of all of the staging repos; then only those packages would be listed here, and subsequent changes underneath each repo would affect only that BUILD file.

This is why, for example, there is a pkg/BUILD file - there's no go sources in pkg/, but it prevents any directory changes in pkg/ from percolating up to the root OWNERS file.

Copy link
Member

Choose a reason for hiding this comment

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

(I'd be happy to do this change in a follow-up PR. I've got a different PR open right now affecting a bunch of BUILD files, and I'd like to avoid conflicting with myself.)

@lavalamp
Copy link
Member

/approve

For build file change

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 21, 2018
Copy link
Member

@caesarxuchao caesarxuchao left a comment

Choose a reason for hiding this comment

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

Thanks, Jonathon!

Just two nits.

// This sleep allows the informer goroutine to warm up and call List before we
// send any events to it. This is for proof-of-concept; your tests should not
// sleep.
time.Sleep(time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

You can use a for loop to block on podInformer.HasSynced().

Copy link
Author

Choose a reason for hiding this comment

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

Done

})

// Make sure informers are running.
go informers.Start(ctx.Done())
Copy link
Member

Choose a reason for hiding this comment

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

As you said, no need to wrap in a goroutine.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@caesarxuchao caesarxuchao removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 21, 2018
This adds an example showing the steps needed to get a working
SharedInformerFactory with a fake client for testing.
@caesarxuchao
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 21, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: caesarxuchao, lavalamp, misterikkit, sttts

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

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 65301, 65291, 65307, 63845, 65313). If you want to cherry-pick this change to another branch, please follow the instructions here.

k8s-github-robot pushed a commit that referenced this pull request Jun 24, 2018
Automatic merge from submit-queue (batch tested with PRs 63773, 65411). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

client-go/examples/fake-client: add doc.go to fix go build warnings

The publishing bot is currently broken (#56876 (comment)). This is due to the following error:

```
[24 Jun 18 15:08 UTC]: Running smoke tests for branch master
[24 Jun 18 15:08 UTC]: /bin/bash -xec "godep restore\ngo build ./...\ngo test $(go list ./... | grep -v /vendor/)\n"
	+ godep restore
	+ go build ./...
	go build k8s.io/client-go/examples/fake-client: no non-test Go files in /go-workspace/src/k8s.io/client-go/examples/fake-client
[24 Jun 18 15:09 UTC]: exit status 1
    	+ godep restore
    	+ go build ./...
    	go build k8s.io/client-go/examples/fake-client: no non-test Go files in /go-workspace/src/k8s.io/client-go/examples/fake-client

[24 Jun 18 15:09 UTC]: exit status 1```
```

The fakeclient package does not have any non-test go files. The test file was added in #65291 2 days ago.

This causes `go build` to give a warning: `no non-test Go files in /go-workspace/src/k8s.io/client-go/examples/fake-client`, which breaks the publishing bot. This PR adds a dummy doc.go file in the package to avoid this warning and fix the publishing bot.

**Release note**:

```release-note
NONE
```
k8s-publishing-bot added a commit to kubernetes/client-go that referenced this pull request Jun 24, 2018
Automatic merge from submit-queue (batch tested with PRs 63773, 65411). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

client-go/examples/fake-client: add doc.go to fix go build warnings

The publishing bot is currently broken (kubernetes/kubernetes#56876 (comment)). This is due to the following error:

```
[24 Jun 18 15:08 UTC]: Running smoke tests for branch master
[24 Jun 18 15:08 UTC]: /bin/bash -xec "godep restore\ngo build ./...\ngo test $(go list ./... | grep -v /vendor/)\n"
	+ godep restore
	+ go build ./...
	go build k8s.io/client-go/examples/fake-client: no non-test Go files in /go-workspace/src/k8s.io/client-go/examples/fake-client
[24 Jun 18 15:09 UTC]: exit status 1
    	+ godep restore
    	+ go build ./...
    	go build k8s.io/client-go/examples/fake-client: no non-test Go files in /go-workspace/src/k8s.io/client-go/examples/fake-client

[24 Jun 18 15:09 UTC]: exit status 1```
```

The fakeclient package does not have any non-test go files. The test file was added in kubernetes/kubernetes#65291 2 days ago.

This causes `go build` to give a warning: `no non-test Go files in /go-workspace/src/k8s.io/client-go/examples/fake-client`, which breaks the publishing bot. This PR adds a dummy doc.go file in the package to avoid this warning and fix the publishing bot.

**Release note**:

```release-note
NONE
```

Kubernetes-commit: 7a9a30a4f7eae900bffd4b477a431a999de350dd
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/documentation Categorizes issue or PR as related to documentation. 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

8 participants