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

Local integration tests #256

Merged

Conversation

bobcatfish
Copy link
Contributor

When starting to look into #251 I wanted to try to reproduce the test flakes locally but I immediately ran into two problems:

  1. The tests hardcode a GCP project and bucket, which means I have to have access to those to run the tests.
  2. The tests have to be triggered via integration_tests.sh to work, b/c it contains important setup, and this makes it a bit tough to run tests individually

(1) Can be resolved by adding me to these projects, but it turns out the tests can work just fine using a different project and bucket, so I've updated the tests such that these values can be provided as arguments to the tests.
(2) Now the setup (i.e. the creation of the build context) is done as part of the tests themselves, so we can run the tests directly with go test.

Bonuses:

  • The tests previously relied on TestRun being run before TestLayers because TestRun would actually build the images with docker and kaniko - this means running tests from TestLayers individually did not work. Now the tests will check if the images have been built before trying to use them, build them if they haven't been built, or use the previously built images if they have been.
  • There will now be no possibility of a collision if the tests are run simultaneously using the same GCS bucket b/c the context tarball name will include a UUID.

@bobcatfish
Copy link
Contributor Author

kokoro is going to love this, I can just feel it

@bobcatfish
Copy link
Contributor Author

image
o rly

@bobcatfish
Copy link
Contributor Author

bobcatfish commented Jul 25, 2018

integration/cleanup.go:25:1:warning: runOnInterrupt is unused (deadcode)
integration/gcs.go:60:1:warning: deleteFromGCS is unused (deadcode)
integration/gcs.go:48:1:warning: uploadBuildContext is unused (deadcode)
integration/gcs.go:28:1:warning: createIntegrationTarball is unused (deadcode)
integration/images.go:72:1:warning: findDockerFiles is unused (deadcode)
integration/images.go:64:1:warning: getDockerImage is unused (deadcode)

wut

@bobcatfish bobcatfish force-pushed the local_integration_tests branch 2 times, most recently from ab753a6 to a7dc7b3 Compare July 25, 2018 23:51
Copy link
Collaborator

@priyawadhwa priyawadhwa left a comment

Choose a reason for hiding this comment

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

This looks really great, thanks for fixing all of this!

DEVELOPMENT.md Outdated

#### Troubleshooting

If you see errors due to `container-diff` failing, try pulling the base images (specified in [the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just realized we could also get rid of this problem by using fully qualified images for all the Dockerfiles, so once this goes through hopefully we won't need this section!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooooo nice! and it's in, so I'll remove this from the doc

DEVELOPMENT.md Outdated
```shell
export GCS_BUCKET="gs://<your bucket>"
export IMAGE_REPO="gcr.io/somerepo"
go test -v --bucket $GCS_BUCKET --repo $IMAGE_REPO -run TestLayers/test_layer_Dockerfile_test_copy_bucket
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we have the flags here anyway, it might be easier to just pass in the names instead of having env variables as an extra step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kk sounds good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay so I'm going to do something halfway to what you are suggesting, just removing the export lines so it looks like this:

go test -v --bucket $GCS_BUCKET --repo $IMAGE_REPO -run TestLayers/test_layer_Dockerfile_test_copy_bucket`

One alternative would be to hardcode some defaults, but i think this makes it hard for ppl to know what they need to change:

go test -v --bucket gs://kaniko-test-bucket --repo gcr.io/kaniko-test -run TestLayers/test_layer_Dockerfile_test_copy_bucket`

Or we could do something like this, which is what I used to do all the time, but the thing is you can't copy and paste it:

go test -v --bucket <your bucket> --repo <your repo> -run TestLayers/test_layer_Dockerfile_test_copy_bucket`

I like leaving the env vars in b/c then if ppl use env vars they can copy & paste the command from the doc

Copy link
Collaborator

Choose a reason for hiding this comment

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

For sure, SGTM!

if err != nil {
return "", fmt.Errorf("Failed to create temporary directoy to hold tarball: %s", err)
}
uuid := randomString(32)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be simpler to use a timestamp here, since the context will be deleted anyway!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh good call!

t.Error(err)
t.Fail()
}
})
}
}

func checkLayers(image1, image2 string, offset int) error {
func checkLayers(t *testing.T, image1, image2 string, offset int) 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 do we need to pass t in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh thanks for catching that @sharifelgamal I'll remove it - I had tried out calling t.Helper() in this function to change the line number reported for failures, but I ended up thinking it's better reporting the line number inside checkLayers

@bobcatfish
Copy link
Contributor Author

PTAL @priyawadhwa @sharifelgamal

@bobcatfish
Copy link
Contributor Author

image

😅

@priyawadhwa
Copy link
Collaborator

LGTM, I think you just need to rebase & this should be ready to merge!

@bobcatfish
Copy link
Contributor Author

LGTM, I think you just need to rebase & this should be ready to merge!

HERE WE GO that flake better not happen, that would be ironic

<.<

@dlorenc
Copy link
Collaborator

dlorenc commented Jul 31, 2018

integration/images.go:68:1:warning: singleSnapshotImages is unused (deadcode)
integration/images.go:29:1:warning: singleSnapshotFlag is unused (deadcode)

No flake, but a lint error!

@bobcatfish
Copy link
Contributor Author

image

😥

To allow contributors to run the integration tests with their own GCS
buckets and image repos (since not all contributors will have accesss to
the projects used by the kaniko maintainers) this updates the
integration tests so that these can be provided on the command line.

This allows tests to be run individually, without using `make
integration-test`. Previously, part of the test setup was done
in the shell script (creating the context tarball that is required
for the tests that build images with context). Instead it will be
done in the test iself, so we can use `go test` to run tests
individually if we want to.

If we are running only one individual test, we don't want to build
all of the images, so this commit creates a builder which tracks which
images it has built and can be used by a tests to check if it should
build an image before running, or it will use the images that have
already been built by a previous test.

The name of the context tarball has also been made unique (it includes
the unix timestamp) to avoid potential test flakes if two tests using
the same GCS bucket run simultaneously.
@bobcatfish
Copy link
Contributor Author

7th time's a charm!

Copy link
Contributor

@sharifelgamal sharifelgamal left a comment

Choose a reason for hiding this comment

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

Awesome.

@bobcatfish bobcatfish merged commit 0d7eba9 into GoogleContainerTools:master Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants