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

CI: fix GHA CI not running unit tests in cmd #2972

Merged
merged 5 commits into from
Oct 27, 2021
Merged

Conversation

kolyshkin
Copy link
Contributor

This fixes GHA CI not running unit tests in cmd, and simplifies some things along the way. For details, see commit messages.

Please review commit by commit.

The code was correct but too long.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@google-cla google-cla bot added the cla: yes label Oct 22, 2021
@k8s-ci-robot
Copy link
Collaborator

Hi @kolyshkin. Thanks for your PR.

I'm waiting for a google member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@bobbypage
Copy link
Collaborator

/ok-to-test

@kolyshkin
Copy link
Contributor Author

@bobbypage PTAL (this fixes quite a big issue in GHA CI)

@kolyshkin
Copy link
Contributor Author

I'm waiting for a google member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Hmm, I followed the second link and got an impression that I need to be a kubernetes member in order to avoid waiting for /ok-to-test, and so I filed an issue about it (kubernetes/org#3053).

Only after doing that I realized that the first link points to https://github.com/orgs/google/people, not https://github.com/orgs/kubernetes/people.

@bobbypage please let me know if you're still OK to sponsor me for being a kubernetes member.

}

GO_FLAGS=${GO_FLAGS:-"-tags=netgo -race"}
BUILD_PACKAGES=${BUILD_PACKAGES:-}
PACKAGES=${PACKAGES:-"sudo"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

a little confused here, why do we need to install sudo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's in the commit message, copy/pasting here to save you a click:

Now, when these tests are enabled, we see that sudo is missing from the
image, so add it.

IOW some tests under ./cmd use sudo (although at the moment I don't remember which ones). Let me do this

-PACKAGES=${PACKAGES:-"sudo"}
+PACKAGES=${PACKAGES:-"apt"}

in this PR and see what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I'm not sure why but tests passes. I remember sudo was needed for integration tests, and these are unit tests. Maybe I mixed those up when writing this. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, there were 3 bugs in the code 🤦🏻

  1. sudo was no needed;
  2. s/BUILD_PACKAGES/PACKAGES/ was wrong, as tests need BUILD_PACKAGES to build test binaries;
  3. GO_FLAGS were not propagated to docker container, thus tests were not performed with proper tags -- this was also the reason why (2) was not resulted in a ❌ CI.

All fixed now 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, apparently I mixed this up; sudo removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

wow, thanks for the debugging and fixing this up :)

@bobbypage
Copy link
Collaborator

/ok-to-test

@bobbypage
Copy link
Collaborator

Thanks @kolyshkin for fixing this. +1 on your k8s sponsorship, happy to do that.

Makefile Show resolved Hide resolved
@kolyshkin
Copy link
Contributor Author

/hold

@kolyshkin kolyshkin marked this pull request as draft October 27, 2021 00:33
@kolyshkin kolyshkin force-pushed the fix-ci branch 2 times, most recently from 5491ea6 to 76b5d28 Compare October 27, 2021 01:31
1. Honor GO_FLAGS; if unset, use -race. As a result, integration tests
   are now built with -race.

2. Instead of using -short to avoid integration tests, filter out
   packages under integration.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
So, build/unit-in-container.sh never ran any tests under cmd.

This happened because the $(go list ...) in BUILD_CMD was not escaped,
and therefore the expansion happened before cd. Here is a demo:

	[kir@kir-rhat cadvisor]$ BUILD_CMD="pwd && cd cmd && echo $(pwd)"
	[kir@kir-rhat cadvisor]$ echo $BUILD_CMD
	pwd && cd cmd && echo /home/kir/go/src/github.com/google/cadvisor

The fix would be to escape the $ in $(go list):

	[kir@kir-rhat cadvisor]$ BUILD_CMD="pwd && cd cmd && echo \$(pwd)"
	[kir@kir-rhat cadvisor]$ echo $BUILD_CMD
	pwd && cd cmd && echo $(pwd)
	[kir@kir-rhat cadvisor]$ sh -c "$BUILD_CMD"
	/home/kir/go/src/github.com/google/cadvisor
	/home/kir/go/src/github.com/google/cadvisor/cmd

Yet, it's easier just to reuse the make test target which already has
the exclusion logic. For that to work properly with custom test configs
from ./build/config, we need to export GO_FLAGS env var into container.

While at it, slightly simplify the BUILD_CMD by adding -e to bash, so we
do not have to specify && every time.

Fixes: 74b513b
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin force-pushed the fix-ci branch 4 times, most recently from 7beb677 to 2cdb020 Compare October 27, 2021 02:16
1. Go package no longer needs to be in a particular directory
   (since Go 1.10 or so).

2. fetch-depth: 1 is the default -- no need to specify it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin force-pushed the fix-ci branch 4 times, most recently from 6a08747 to 2ae3813 Compare October 27, 2021 02:32
There is no need to spawn a docker container for unit tests; run
those locally.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
Copy link
Contributor Author

no longer a draft; PTAL @bobbypage

@bobbypage
Copy link
Collaborator

LGTM, thanks again for fixing this up.

@bobbypage bobbypage merged commit 2ca0f4f into google:master Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants