diff --git a/Makefile b/Makefile index 3e49bccab68..b771f3ff4ac 100644 --- a/Makefile +++ b/Makefile @@ -140,12 +140,12 @@ test-legacy: ## Run the legacy tests (go/v2) of the testdata directory ./test/testdata/test_legacy.sh .PHONY: test-e2e-local -test-e2e-local: ## Run the end-to-end tests locally +test-e2e-local: build-external-plugin ## Run the end-to-end tests locally ## To keep the same kind cluster between test runs, use `SKIP_KIND_CLEANUP=1 make test-e2e-local` ./test/e2e/local.sh .PHONY: test-e2e-ci -test-e2e-ci: ## Run the end-to-end tests (used in the CI)` +test-e2e-ci: build-external-plugin ## Run the end-to-end tests (used in the CI)` ./test/e2e/ci.sh .PHONY: test-book @@ -157,3 +157,7 @@ test-book: ## Run the cronjob tutorial's unit tests to make sure we don't break .PHONY: test-license test-license: ## Run the license check ./test/check-license.sh + +.PHONY: build-external-plugin +build-external-plugin: ## Build external plugin + ./test/e2e/build-sample-external-plugin.sh diff --git a/test/e2e/build-sample-external-plugin.sh b/test/e2e/build-sample-external-plugin.sh new file mode 100755 index 00000000000..cf04f17205d --- /dev/null +++ b/test/e2e/build-sample-external-plugin.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Copyright 2023 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +# TODO: Dynamically set exteranl plugin destination based on OS platform +EXTERNAL_PLUGIN_DESTINATION_PREFIX="${HOME}/Library/Application Support/kubebuilder/plugins" +PLUGIN_NAME="sampleexternalplugin" +PLUGIN_VERSION="v1" +EXTERNAL_PLUGIN_DESTINATION="${EXTERNAL_PLUGIN_DESTINATION_PREFIX}/${PLUGIN_NAME}/${PLUGIN_VERSION}" +EXTERNAL_PLUGIN_PATH="${EXTERNAL_PLUGIN_DESTINATION}/${PLUGIN_NAME}" + +if [ -d "$EXTERNAL_PLUGIN_DESTINATION" ]; then + echo "$EXTERNAL_PLUGIN_DESTINATION does exist." + if [ -e "$EXTERNAL_PLUGIN_PATH" ]; then + echo "clean up old binary..." + rm "$EXTERNAL_PLUGIN_PATH" + fi +else + mkdir -p "$EXTERNAL_PLUGIN_DESTINATION" +fi + +SOURCE_DIR="./docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1" +cd $SOURCE_DIR && go build -o $PLUGIN_NAME && mv $PLUGIN_NAME "$EXTERNAL_PLUGIN_PATH" + +kubebuilder init --plugins="${PLUGIN_NAME}/${PLUGIN_VERSION}" --help | grep --quiet "$PLUGIN_NAME" + +if [ $? -eq 0 ]; then + echo "External plugin is built at: $EXTERNAL_PLUGIN_DESTINATION" +else + echo "FAIL to build external plugin" + exit 1 +fi