-
Notifications
You must be signed in to change notification settings - Fork 1.2k
🏃 setup-envtest.sh: standalone script for setting up envtest #1092
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
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: joelanford The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold I realized there are a few more places to integrate this. |
f672368
to
fe03072
Compare
/hold cancel |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -e |
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.
set -e | |
set -o errexit | |
set -o nounset | |
set -o pipefail |
} | ||
|
||
# fetch k8s API gen tools and make it available under envtest_root_dir/bin. | ||
function fetch_envtest_tools { |
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.
What do you think about checking and returning early if SKIP_FETCH_TOOLS
is already set?
goarch=amd64 | ||
goos="unknown" | ||
|
||
if [[ "$OSTYPE" == "linux-gnu" ]]; then |
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.
if [[ "$OSTYPE" == "linux-gnu" ]]; then | |
if [[ "$OSTYPE" == "linux"* ]]; then |
k8s_version=1.16.4 | ||
goarch=amd64 | ||
goos="unknown" |
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.
What about passing these in? So they're not hardcoded and they can be set dynamically when we call fetch_envtest_tools
?
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.
WDYT about:
- Auto-detecting GOOS and GOARCH by running
go env GOOS
andgo env GOARCH
? - Defaulting, but allow overriding the k8s version?
ENVTEST_K8S_VERSION="${ENVTEST_K8S_VERSION:-1.16.4}"
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.
Sounds good to me
if [[ -z "${KUBEBUILDER_ASSETS}" ]]; then | ||
export KUBEBUILDER_ASSETS=$1/bin | ||
fi |
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.
if [[ -z "${KUBEBUILDER_ASSETS}" ]]; then | |
export KUBEBUILDER_ASSETS=$1/bin | |
fi | |
if [[ -z "${KUBEBUILDER_ASSETS}" ]]; then | |
header_text "setting up kubebuilder-tools@${k8s_version} env vars" | |
export KUBEBUILDER_ASSETS=$1/bin | |
fi |
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 KUBEBUILDER_ASSETS preferable to what we were doing before
export PATH=${tmp_root}/kubebuilder/bin:$PATH
export TEST_ASSET_KUBECTL=${tmp_root}/kubebuilder/bin/kubectl
export TEST_ASSET_KUBE_APISERVER=${tmp_root}/kubebuilder/bin/kube-apiserver
export TEST_ASSET_ETCD=${tmp_root}/kubebuilder/bin/etcd
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 removed calls to header_text
because that lives in common.sh
, and I didn't want to force users to download two scripts for this.
If the header text is important, I could copy that code into this script. But I figured callers of these functions could call header_text
.
For environment variables, I opted to keep the existing environment setup as what's in master
, but I'm not opposed to making this change.
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.
Yeah let's copy it, it's great to see some styled output when running it
return 0 | ||
fi | ||
fi | ||
|
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.
header_text "fetching envtest-tools@${k8s_version}" |
fi | ||
|
||
setup_envs | ||
header_text "setting up envtest environment" |
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.
header_text "setting up envtest environment" | |
header_text "setting up envtest@${k8s_version}" |
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.
Tested locally and it worked 👍
$ . ../sigs.k8s.io/controller-runtime/hack/setup-envtest.sh && envtest_assets_dir=$(pwd)/test/assets && fetch_envtest_tools “$envtest_assets_dir” && setup_envtest_env “$envtest_assets_dir”
camilamacedo@Camilas-MacBook-Pro ~/go/src/envtest $ 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
go test ./... -coverprofile cover.out
? github.com/example-inc/memcached-operator [no test files]
? github.com/example-inc/memcached-operator/api/v1beta1 [no test files]
ok github.com/example-inc/memcached-operator/controllers 4.988s coverage: 0.0% of statements
camilamacedo@Camilas-MacBook-Pro ~/go/src/envtest $
/lgtm
🏃 hack/setup-envtest.sh: follow-up from #1092
kubebuilder is not an actual dependency and is only installed in order to pull the binary assets required for the envtest package. This change pulls a controller-runtime script that helps with installing these assets, independently of kubebuilder. This means that we don't depend on the latter to release a new version which has pulled updates from upstream. This is apparently the recommended method (also how kubebuilder sets up new projects), see: - kubernetes-sigs/controller-runtime#1092 - https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v3/Makefile#L17-L21 Signed-off-by: Dimitrios Karagiannis <[email protected]>
kubebuilder is not an actual dependency and is only installed in order to pull the binary assets required for the envtest package. This change pulls a controller-runtime script that helps with installing these assets, independently of kubebuilder. This means that we don't depend on the latter to release a new version which has pulled updates from upstream. This is apparently the recommended method (also how kubebuilder sets up new projects), see: - kubernetes-sigs/controller-runtime#1092 - https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v3/Makefile#L17-L21 Signed-off-by: Dimitrios Karagiannis <[email protected]>
envtest
is a test framework provided bycontroller-runtime
that simplifies running integration tests for controllers.Currently, it is not straightforward to setup envtest without also setting up kubebuilder. However, Kubebuilder is not a prerequisite to use
envtest
.This PR splits out the envtest setup code from controller-runtime's CI scripts such that users could easily download and use the envtest setup code in their own CI scripts.
It would work like this: