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

Convert hack/e2e.go to a test-infra/kubetest shim #40374

Merged
merged 1 commit into from
Feb 3, 2017

Conversation

fejta
Copy link
Contributor

@fejta fejta commented Jan 24, 2017

Replaces hack/e2e.go for a shim that passes the args to k8s.io/test-infra/kubetest
Adds fejta to hack/OWNERS
Adds e2e_test.go for unit test coverage of the shim.

Usage: go run hack/e2e.go [--get=true] [--old=1d] -- KUBETEST_ARGS
In other words there is are --get and --old shim flags, which control how we upgrade kubetest, and a -- to separate the shim args from the kubetest args, and the existing kubetest args like --down --up, etc. If only KUBETEST_ARGS are used then you can skip the -- (although golang will complain about it).

Once this is ready to go I will update the kubekins-e2e image to copy this file from test-infra: https://github.com/kubernetes/test-infra/blob/master/jenkins/e2e-image/Dockerfile#L70

ref kubernetes/test-infra#1475

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 24, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note-label-needed labels Jan 24, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] Needs approval from an approver in each of these OWNERS Files:

We suggest the following people:
cc @ihmccreery
You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@fejta fejta added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Jan 24, 2017
@fejta
Copy link
Contributor Author

fejta commented Jan 24, 2017

I realize this has an XXL tab, but it is WAY less scary than it looks: almost all of this is deleting the old e2e.go and replacing it with a few lines of "go get -u k8s.io/test-infra/kubetest && kubetest ARGS"

@fejta
Copy link
Contributor Author

fejta commented Jan 24, 2017

@k8s-bot gci gke e2e test this
@k8s-bot kubemark e2e test this

@fejta fejta assigned fejta and unassigned spiffxp and spxtr Jan 25, 2017
@fejta
Copy link
Contributor Author

fejta commented Jan 25, 2017

W0124 14:56:27.167] 2017/01/24 14:56:27 e2e.go:946: Running: ./test/kubemark/run-e2e-tests.sh --ginkgo.focus=\[Feature:Empty\] --gather-resource-usage=true --garbage-collector-enabled=true
W0124 14:56:27.167] Project: k8s-jkns-pr-kubemark
W0124 14:56:27.167] Zone: us-central1-f
W0124 14:56:27.167] Trying to find master named 'k6k-e2e-agent-pr-16-0-kubemark-master'
W0124 14:56:27.167] Looking for address 'k6k-e2e-agent-pr-16-0-kubemark-master-ip'
W0124 14:56:27.647] Using master: k6k-e2e-agent-pr-16-0-kubemark-master (external IP: 35.184.81.178)
W0124 14:56:29.773] flag provided but not defined: -v
W0124 14:56:29.774] Usage of /tmp/go-build615123988/command-line-arguments/_obj/exe/e2e:
W0124 14:56:29.774]   -get
W0124 14:56:29.774]     	go get -u kubetest if old or not installed (default true)
W0124 14:56:29.774]   -old duration
W0124 14:56:29.774]     	Consider kubetest old if it exceeds this (default 24h0m0s)
W0124 14:56:29.774] 2017/01/24 14:56:29 e2e.go:40: NOTICE: go run hack/e2e.go is now a shim for test-infra/kubetest
W0124 14:56:29.775] 2017/01/24 14:56:29 e2e.go:41:   Usage: go run hack/e2e.go [--get=true] [--old=24h] -- [KUBETEST_ARGS]
W0124 14:56:29.775] 2017/01/24 14:56:29 e2e.go:42:   The separator is required to use --get or --old flags
W0124 14:56:29.775] 2017/01/24 14:56:29 e2e.go:43:   The -- flag separator also suppresses this message
W0124 14:56:29.776] panic: runtime error: slice bounds out of range
W0124 14:56:29.776] 
W0124 14:56:29.776] goroutine 1 [running]:
W0124 14:56:29.776] panic(0x5a1060, 0xc82001a0d0)
W0124 14:56:29.776] 	/usr/local/go/src/runtime/panic.go:481 +0x3e6
W0124 14:56:29.777] main.main()
W0124 14:56:29.777] 	/workspace/kubernetes/hack/e2e.go:44 +0xbd8
W0124 14:56:29.777] exit status 2
W0124 14:56:29.781] 2017/01/24 14:56:29 e2e.go:948: Step './test/kubemark/run-e2e-tests.sh --ginkgo.focus=\[Feature:Empty\] --gather-resource-usage=true --garbage-collector-enabled=true' finished in 2.747092566s

@fejta
Copy link
Contributor Author

fejta commented Jan 25, 2017

Fixed, apparently I cannot count in golang. args[-5:] does not work as it does in python. Added unit tests for this parsing since apparently I should have in the first place!

Copy link
Contributor

@spxtr spxtr left a comment

Choose a reason for hiding this comment

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

gofmt your code!

hack/e2e.go Outdated
if _, err := f.Write(out); err != nil {
log.Fatalf("Error writing XML data: %s", err)
func parse(args []string)flags {
//
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

hack/e2e.go Outdated

func (b bash) Up() error {
return finishRunning(exec.Command("./hack/e2e-internal/e2e-up.sh"))
// Struct that allows unit tests to override functionality.
Copy link
Contributor

Choose a reason for hiding this comment

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

I usually see this done with a global variable for small packages. Something like var osStat = os.Stat and then in tests override it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds like a race condition if tests run concurrently

Copy link
Contributor

Choose a reason for hiding this comment

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

Unit tests can only run concurrently if they call t.Parallel().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this something you want me to add in this PR?

hack/e2e.go Outdated
if err != nil {
return nil, err
// Try to find kubetest, either GOPATH/bin/kubetest or PATH
func (t tester) look() (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

look isn't a very descriptive name... I'd suggest findKubetest or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

hack/e2e.go Outdated
// Upgrade if kubetest does not exist or has not been updated today
func (t tester) getKubetest(get bool, old time.Duration) (string, error) {
// Find kubetest installation
p, err := t.look()

Copy link
Contributor

Choose a reason for hiding this comment

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

remove this newline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

hack/e2e.go Outdated
old := fs.Duration("old", oldDefault, "Consider kubetest old if it exceeds this")
var a []string
if err := fs.Parse(args[1:]); err != nil {
log.Print("NOTICE: go run hack/e2e.go is now a shim for test-infra/kubetest")
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we plan on eventually removing hack/e2e.go, or will this be sticking around indefinitely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing eventually

hack/e2e_test.go Outdated
returnError error
}{
{ // 0: Pass when on GOPATH/bin
false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer explicitly stating the struct members that you're setting in this kind of thing, since it's super hard to read these entries when it's just a list of values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please elaborate, table driven testing is explicitly what our style guide recommends:
https://github.com/kubernetes/community/blob/master/contributors/devel/testing.md#unit-tests

I agree that table driven testing is illegible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just learned about annoyingStruct{foo: 1, bar: false} thanks!

@fejta
Copy link
Contributor Author

fejta commented Jan 25, 2017

@k8s-bot gci gke e2e test this

@fejta
Copy link
Contributor Author

fejta commented Jan 25, 2017

@k8s-bot kops aws e2e test this

@spxtr
Copy link
Contributor

spxtr commented Jan 26, 2017

$ go run hack/e2e.go -help
Usage of /tmp/go-build302892506/command-line-arguments/_obj/exe/e2e:
  -get
    	go get -u kubetest if old or not installed (default true)
  -old duration
    	Consider kubetest old if it exceeds this (default 24h0m0s)
2017/01/26 14:18:52 e2e.go:50: NOTICE: go run hack/e2e.go is now a shim for test-infra/kubetest
2017/01/26 14:18:52 e2e.go:51:   Usage: go run hack/e2e.go [--get=true] [--old=24h0m0s] -- [KUBETEST_ARGS]
2017/01/26 14:18:52 e2e.go:52:   The separator is required to use --get or --old flags
2017/01/26 14:18:52 e2e.go:53:   The -- flag separator also suppresses this message
2017/01/26 14:18:52 e2e.go:139: Updating kubetest binary...
^Csignal: interrupt

That's not what I wanted to happen...

@fejta
Copy link
Contributor Author

fejta commented Jan 30, 2017

Zach and Kris, any thoughts?

@zmerlynn
Copy link
Member

LGTM, seems fine. Can you prepare a PR to update https://github.com/kubernetes/community/blob/master/contributors/devel/e2e-tests.md?

@fejta fejta unassigned jbeda and lavalamp Jan 31, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2017
hack/e2e.go Outdated
@@ -14,968 +14,144 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// e2e.go runs the e2e test suite. No non-standard package dependencies; call with "go run".
// User-interface for test-infra/kubetest/e2e.go
// Equivalent to go get -u k8s.io/test-infra/kubetest/e2e.go && kubetest "${@}"
Copy link
Contributor

Choose a reason for hiding this comment

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

go get -u k8s.io/test-infra/kubetest && kubetest "${@}"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
if _, err := f.Write(out); err != nil {
log.Fatalf("Error writing XML data: %s", err)
func parse(args []string) (flags, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you doing it this way instead of just having flag.Bool var blocks and calling flag.Parse in main?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To assist with unit testing

Copy link
Contributor

Choose a reason for hiding this comment

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

I looked at the unit test, and it seems to mostly test that the flag package works properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I added this unit test because it is non-trivial and I messed it up multiple times. These unit tests are what give me confidence it does the right thing. Specifically that go run hack/e2e.go --get=false --blah --foo sends --blah and --foo to kubetest.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 2, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 3, 2017
@fejta fejta added approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Feb 3, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 40696, 39914, 40374)

@k8s-github-robot k8s-github-robot merged commit c78745e into kubernetes:master Feb 3, 2017
@fejta fejta deleted the e2e branch February 3, 2017 23:10
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. 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants