Skip to content

Commit

Permalink
ci: add a script to install sample external plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Eileen-Yu committed May 24, 2023
1 parent 497ab58 commit 81980a5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
46 changes: 46 additions & 0 deletions test/e2e/build-sample-external-plugin.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 81980a5

Please sign in to comment.