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

test/test-framework: add go.mod, go.sum and build/Dockerfile #2202

Merged
merged 7 commits into from
Nov 19, 2019

Conversation

estroz
Copy link
Member

@estroz estroz commented Nov 15, 2019

Description of the change:

  • test/test-framework: add go.mod, go.sum and build/Dockerfile
  • hack/generate/gen-test-framework.sh: remove workarounds for lack of go.mod, go.sum, build/Dockerfile
  • internal/scaffold/crd_test.go: modularizing test/test-framework broke the Go project test because submodules are not packages of a module, which caused CRD generator errors. Changing wd to test/test-framework fixed the issue

Motivation for the change: test/test-framework contains a working operator that we use for testing. It should be as close to a standalone operator built with the SDK as possible.

@openshift-ci-robot openshift-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 15, 2019

# Remove files that are required and created just to exec the commands.
trap_add 'rm -rf $DOCKERFILE go.mod go.sum' EXIT

Copy link
Member

Choose a reason for hiding this comment

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

Does go.sum need to be checked in? If so, maybe we should run go mod tidy in this script to make it easier to keep up-to-date?

Copy link
Member Author

Choose a reason for hiding this comment

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

tidy is already run in sanity-check.sh

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that helps us. Does go mod tidy run recursively against all other modules (e.g. test/test-framework) in the repo? I don't think it does.

If we include it here, a developer can run make gen-test-framework after making changes in the test framework to pick up all of the necessary changes. go.mod and go.sum will get updated along with the other generated files.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I see what you mean. It does not. I will add it here.


require (
github.com/go-openapi/spec v0.19.0
github.com/operator-framework/operator-sdk v0.12.1-0.20191112211508-82fc57de5e5b
Copy link
Member

Choose a reason for hiding this comment

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

Does this become another file that needs to be checked and updated during releases?

I'm wondering if we can incorporate operator-sdk print-deps in the gen-test-framework script to keep this up-to-date?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was the reason that I thought would be easier not to keep them committed.

Copy link
Member Author

@estroz estroz Nov 15, 2019

Choose a reason for hiding this comment

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

The replace line at the bottom should take care of that issue.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it quite takes care of it. If I understand Go modules correctly, I think this would result in the compiled test-framework using all the resolved require dependencies of github.com/operator-framework/operator-sdk v0.12.1-0.20191112211508-82fc57de5e5b and then substituting just operator-sdk for the one listed in the replace.

Copy link
Member Author

@estroz estroz Nov 18, 2019

Choose a reason for hiding this comment

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

On further investigation it looks like you are correct. This shouldn't be an issue if we do

$ cd test/test-framework
$ operator-sdk print-deps > go.mod
$ echo -e "\nreplace github.com/operator-framework/operator-sdk => ../../" >> go.mod
$ go build ./...
$ go mod tidy

in gen-test-framework, as well as update the require version. This will avoid passing incompatible transitive dependencies to test-framework and make sure that pinned dependencies are up-to-date. One somewhat annoying issue that crops up here is that resolving branch master will cause an inconsistent require for the SDK whenever master has been updated. We can get around this with some go mod edit logic.

@camilamacedo86 I understand where you're coming from. Making the test-framework a module adds complexity to our sanity check and release process, while saving some unit tests from writing a mock go.mod. Therefore making test-framework a module might not be the right move.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for the propose to use the testdata as a project mock and ensure that it is updated has no need to do it. If we would like to facilitate the update of the testadata we can create a make target that will do as it is done in the check. Wdyt?

hack/generate/gen-test-framework.sh: remove workarounds for lack
of go.mod, go.sum, build/Dockerfile

internal/scaffold/crd_test.go: modularizing test/test-framework
broke the Go project test because submodules are not packages of
a module, which caused CRD generator errors. Changing wd to
test/test-framework fixed the issue
Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

🥇 /lgtm /approved

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 18, 2019
@estroz estroz force-pushed the test-framework-add-modules branch 2 times, most recently from e58e863 to 0738ae9 Compare November 18, 2019 23:43
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 18, 2019
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

Nice workaround with the go mod edit fu! Just a nit and a thought for a possible follow-up. Otherwise LGTM.

trap_add 'rm -rf $DOCKERFILE go.mod go.sum' EXIT
# Ensure test-framework is up-to-date with current Go project dependencies.
# NOTE: the SDK dependency version still needs updating on a new release.
sdk_version="$(go list -m -f '{{.Version}}' github.com/operator-framework/operator-sdk)"
Copy link
Member

Choose a reason for hiding this comment

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

TIL about this command! If there's equivalent go code, maybe in a future PR, we should consider outputting this version in the go.mod scaffold directly. Though maybe it's moot with the kubebuilder transition.

trap_add 'rm -f pkg/apis/cache/v1alpha1/zz_generated.openapi.go' EXIT
Copy link
Member

Choose a reason for hiding this comment

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

In @camilamacedo86's previous PR, we intentionally left off the -f flag to rm so that if we accidentally forget about removing these lines when we get rid of the openapi.go code generator, this will fail, and we will be reminded to remove this.

@estroz estroz merged commit 3b2f684 into operator-framework:master Nov 19, 2019
@estroz estroz deleted the test-framework-add-modules branch November 19, 2019 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants