-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Conversation
[APPROVALNOTIFIER] Needs approval from an approver in each of these OWNERS Files: We suggest the following people: |
fcece64
to
da6ec5a
Compare
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" |
|
Fixed, apparently I cannot count in golang. |
There was a problem hiding this 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 { | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this newline
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
a18a222
to
20efaf3
Compare
@k8s-bot gci gke e2e test this |
@k8s-bot kops aws e2e test this |
That's not what I wanted to happen... |
Zach and Kris, any thoughts? |
LGTM, seems fine. Can you prepare a PR to update https://github.com/kubernetes/community/blob/master/contributors/devel/e2e-tests.md? |
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 "${@}" |
There was a problem hiding this comment.
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 "${@}"
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Automatic merge from submit-queue (batch tested with PRs 40696, 39914, 40374) |
Replaces
hack/e2e.go
for a shim that passes the args tok8s.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 upgradekubetest
, and a--
to separate the shim args from the kubetest args, and the existing kubetest args like--down
--up
, etc. If onlyKUBETEST_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