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

change makefile test target for no longer be required manual steps to run the commands #3983

Merged

Conversation

camilamacedo86
Copy link
Contributor

@camilamacedo86 camilamacedo86 commented Oct 6, 2020

Description of the change:
Update the Makefile test target as discussed in the demo.

Motivation for the change:
Closes: #3692

Checklist

If the pull request includes user-facing changes, extra documentation is required:

Local Tests

 $ operator-sdk init 
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.6.2
Update go.mod:
$ go mod tidy
Running make:
$ make
/Users/camilamacedo/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager main.go
Next: define a resource with:
$ operator-sdk create api
camilamacedo@Camilas-MacBook-Pro ~/go/src/testmake (master) $ cat Makefile 
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

all: manager

# Run tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
	mkdir -p ${ENVTEST_ASSETS_DIR}
	test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
	source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

...

And to check that is running:

$ make test
/Users/camilamacedo/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
/Users/camilamacedo/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
mkdir -p /Users/camilamacedo/go/src/testmake/testbin
test -f /Users/camilamacedo/go/src/testmake/testbin/setup-envtest.sh || curl -sSLo /Users/camilamacedo/go/src/testmake/testbin/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
source /Users/camilamacedo/go/src/testmake/testbin/setup-envtest.sh; fetch_envtest_tools /Users/camilamacedo/go/src/testmake/testbin; setup_envtest_env /Users/camilamacedo/go/src/testmake/testbin; go test ./... -coverprofile cover.out
fetching envtest tools@1.16.4 (into '/Users/camilamacedo/go/src/testmake/testbin')
x bin/
x bin/etcd
x bin/kubectl
x bin/kube-apiserver
setting up env vars
?   	testmake	[no test files]
camilamacedo@Camilas-MacBook-Pro ~/go/src/testmake (master) $ 

changelog/fragments/00-template.yaml Outdated Show resolved Hide resolved
internal/plugins/manifests/init.go Outdated Show resolved Hide resolved
changelog/fragments/00-template.yaml Outdated Show resolved Hide resolved
@camilamacedo86
Copy link
Contributor Author

camilamacedo86 commented Oct 6, 2020

Hi @joelanford,

Tks for your review the changes are made. 👍 See that it is working:

$ make test
/Users/camilamacedo/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
/Users/camilamacedo/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
mkdir -p /Users/camilamacedo/go/src/testmake/testbin
test -f /Users/camilamacedo/go/src/testmake/testbin/setup-envtest.sh || curl -sSLo /Users/camilamacedo/go/src/testmake/testbin/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
source /Users/camilamacedo/go/src/testmake/testbin/setup-envtest.sh; fetch_envtest_tools /Users/camilamacedo/go/src/testmake/testbin; setup_envtest_env /Users/camilamacedo/go/src/testmake/testbin; go test ./... -coverprofile cover.out
fetching envtest tools@1.16.4 (into '/Users/camilamacedo/go/src/testmake/testbin')
x bin/
x bin/etcd
x bin/kubectl
x bin/kube-apiserver
setting up env vars
?   	testmake	[no test files]
camilamacedo@Camilas-MacBook-Pro ~/go/src/testmake (master) $ 

Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

This Makefile addition is unrelated to the manifests plugin, so it doesn't make sense to me to add it here. It should be added directly to the Go Makefile template, and it was in kubernetes-sigs/kubebuilder#1626 for go.kubebuilder.io/v3-alpha. So the right solution is to support the v3-alpha plugin in the operator-sdk binary so users can opt-in; this is the solution we discussed during triage.

@joelanford
Copy link
Member

@estroz Do you think there's a path for us to make the default scaffolding work with the Kubebuilder v2 plugin?

I think the problem we'll find with the v3-alpha plugin is that no one will use it until it is the default.

@estroz
Copy link
Member

estroz commented Oct 6, 2020

Yes, since this is a non-breaking change I think kubernetes-sigs/kubebuilder#1626 can be backported to the v2 plugin. @camilamacedo86 can you create a PR for this upstream?

@camilamacedo86
Copy link
Contributor Author

camilamacedo86 commented Oct 6, 2020

Hi @estroz,

I agree that in this case, we might able to push to v2+ as well. Could you please check the PR: kubernetes-sigs/kubebuilder#1711 for we are able to bump the kb commit here?

@camilamacedo86 camilamacedo86 changed the title change makefile test target for no longer be required manual steps to run the commands WIP: change makefile test target for no longer be required manual steps to run the commands Oct 6, 2020
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 6, 2020
@jberkhahn jberkhahn removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 12, 2020
@camilamacedo86 camilamacedo86 changed the title WIP: change makefile test target for no longer be required manual steps to run the commands change makefile test target for no longer be required manual steps to run the commands Oct 12, 2020
@camilamacedo86
Copy link
Contributor Author

camilamacedo86 commented Oct 12, 2020

HI @joelanford @estroz,
Based on the discussion in the bug triage meeting could you please let us know if we can get it to merge or fi has anything else that you would like o change before that?

@@ -18,12 +18,17 @@ package manifests
import (
Copy link
Member

Choose a reason for hiding this comment

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

These changes shouldn't be in the manifests plugin, they should be in their own internal/plugins/envtest plugin.

internal/plugins/manifests/init.go Outdated Show resolved Hide resolved
@jberkhahn
Copy link
Contributor

can confirm that this works, but I agree with @estroz that it should be in its own file, and then we can just delete it when the upstream fix gets merged

@camilamacedo86 camilamacedo86 force-pushed the makefile-test-update branch 4 times, most recently from 4488fb4 to 45340d9 Compare October 13, 2020 19:51
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

Some nits, otherwise lgtm

Comment on lines 26 to 27
// ControllerRuntimeEnvTestVersion version to be used to download the envtest setup script
// todo: update the tag release when the next version of the project be released with this script
const controllerRuntimeEnvTestVersion = "v0.6.3"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// ControllerRuntimeEnvTestVersion version to be used to download the envtest setup script
// todo: update the tag release when the next version of the project be released with this script
const controllerRuntimeEnvTestVersion = "v0.6.3"
// controllerRuntimeVersion version to be used to download the envtest setup script
// todo: update the tag release when the next version of the project be released with this script
const controllerRuntimeVersion = "v0.6.3"


makefileBytes = []byte(strings.Replace(string(makefileBytes),
"# Run tests\ntest: generate fmt vet manifests\n\tgo test ./... -coverprofile cover.out",
fmt.Sprintf(makefileTestTarget, controllerRuntimeEnvTestVersion), 1))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Sprintf(makefileTestTarget, controllerRuntimeEnvTestVersion), 1))
fmt.Sprintf(makefileTestTarget, controllerRuntimeVersion), 1))

Comment on lines 58 to 62
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/%s/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out`
Copy link
Member

Choose a reason for hiding this comment

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

Consistency nit:

Suggested change
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/%s/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out`
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p $(ENVTEST_ASSETS_DIR)
test -f $(ENVTEST_ASSETS_DIR)/setup-envtest.sh || curl -sSLo $(ENVTEST_ASSETS_DIR)/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/%s/hack/setup-envtest.sh
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out`

Comment on lines 26 to 27
// ControllerRuntimeEnvTestVersion version to be used to download the envtest setup script
const controllerRuntimeEnvTestVersion = "v0.6.3"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// ControllerRuntimeEnvTestVersion version to be used to download the envtest setup script
const controllerRuntimeEnvTestVersion = "v0.6.3"
// controllerRuntimeVersion version to be used to download the envtest setup script
const controllerRuntimeVersion = "v0.6.3"

// See the License for the specific language governing permissions and
// limitations under the License.

// TODO: it will no longer required when the default plugin be v3+
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this going into v2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not decided and merged to v2 yet. We might clarify it.

@jberkhahn
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 13, 2020
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.

A couple of nits.

Comment on lines 5 to 6
Change the makefile target test for no longer be required manually changes and
steps to setup the envtest.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Change the makefile target test for no longer be required manually changes and
steps to setup the envtest.
In Go projects, resolved an issue that caused failing tests by changing the Makefile's `test` target to automatically download and configure the necessary `envtest` binaries.

Comment on lines 20 to 21
"github.com/operator-framework/operator-sdk/internal/plugins/envtest"

Copy link
Member

Choose a reason for hiding this comment

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

This should be grouped with the other SDK imports.

@camilamacedo86 camilamacedo86 mentioned this pull request Oct 14, 2020
internal/plugins/envtest/init.go Outdated Show resolved Hide resolved
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.

/lgtm

After addressing Eric's filemode suggestion.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 14, 2020
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 14, 2020
@@ -14,4 +14,4 @@ make install
go run ./hack/generate/samples/generate_all.go

# Make sure repo is still in a clean state.
git diff --exit-code
git diff --exit-code -- . ':!testdata/go/memcached-operator/bin/*'
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed for now. We can address in a follow-up.

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.

@@ -110,3 +110,7 @@ website/public/
website/resources/
website/node_modules/
website/tech-doc-hugo

# samples bin
testdata/go/memcached-operator/bin/*
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed for now. We can address in a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IHMO we should keep in order to ensure that the bin will not be committed never and ever,

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 14, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 14, 2020
@asmacdo
Copy link
Member

asmacdo commented Oct 14, 2020

The Ansible test is failing. RUN ansible-galaxy collection install -r ${HOME}/requirements.yml is timing out. This times out for me locally, and others are seeing this as well. Since Ansible galaxy appears to be down, please do not restart that job for a while.

@camilamacedo86 camilamacedo86 merged commit c36f1b6 into operator-framework:master Oct 14, 2020
@camilamacedo86 camilamacedo86 deleted the makefile-test-update branch October 14, 2020 23:08
camilamacedo86 added a commit to camilamacedo86/operator-sdk that referenced this pull request Oct 15, 2020
camilamacedo86 added a commit to camilamacedo86/operator-sdk that referenced this pull request Oct 15, 2020
camilamacedo86 added a commit that referenced this pull request Oct 19, 2020
@anmol372 anmol372 mentioned this pull request Nov 10, 2020
2 tasks
obnoxxx added a commit to obnoxxx/samba-operator that referenced this pull request Feb 8, 2021
The test make target required some preparations,specifically
etcd was not found in the expected location. This adds the changes
from operator-framework/operator-sdk#3983
to the test target to make it autonomous.

Signed-off-by: Michael Adam <obnox@redhat.com>
obnoxxx added a commit to samba-in-kubernetes/samba-operator that referenced this pull request Feb 8, 2021
The test make target required some preparations,specifically
etcd was not found in the expected location. This adds the changes
from operator-framework/operator-sdk#3983
to the test target to make it autonomous.

Signed-off-by: Michael Adam <obnox@redhat.com>
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.

Makefile should not need to be modified to get tests to run
6 participants