diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dea1a60..8b54e6c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,6 +29,24 @@ jobs: kubectl cluster-info kubectl get storageclass standard + test-with-custom-resource-limits: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Create kind cluster with custom resource limits + uses: ./ + with: + cpu: "3" + disk: "5" + memory: "11" + - name: Test + run: | + kubectl get node $(kubectl get node -o custom-columns=":metadata.name") -o custom-columns="CPU:.status.capacity.cpu" | grep "3" 1> /dev/null && echo "CPU OK" + kubectl get node $(kubectl get node -o custom-columns=":metadata.name") -o custom-columns="DISK:.status.capacity.ephemeral-storage" | grep -E "5\d{6}Ki" 1> /dev/null && echo "Disk OK" + kubectl get node $(kubectl get node -o custom-columns=":metadata.name") -o custom-columns="MEMORY:.status.capacity.memory" | grep -E "11\d{6}Ki" 1> /dev/null && echo "Memory OK" + test-with-custom-name: strategy: matrix: diff --git a/README.md b/README.md index b20e660..cc9cb55 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ For more information on inputs, see the [API Documentation](https://developer.gi - `knative_serving`: The version of Knative Serving to install on the Kind cluster (not installed by default - example: `v1.0.0`) - `knative_kourier`: The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: `v1.0.0`) - `knative_eventing`: The version of Knative Eventing to install on the Kind cluster (not installed by default - example: `v1.0.0`) +- `cpu`: Number of CPUs to be allocated to the virtual machine (default: 2). For Mac OS only. +- `memory`: Size of the memory in GiB to be allocated to the virtual machine (default: 12). For Mac OS only. +- `disk`: Size of the disk in GiB to be allocated to the virtual machine (default: 60). For Mac OS only. ### Example Workflow diff --git a/action.yml b/action.yml index c1a17eb..f5ada58 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,12 @@ inputs: description: "The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: v1.0.0)" knative_eventing: description: "The version of Knative Eventing to install on the Kind cluster (not installed by default - example: v1.0.0)" + cpu: + description: "For Mac OS only: Number of CPUs to be allocated to the virtual machine (default: 2)" + memory: + description: "For Mac OS only: Size of the memory in GiB to be allocated to the virtual machine (default: 12)" + disk: + description: "For Mac OS only: Size of the disk in GiB to be allocated to the virtual machine (default: 60)" runs: using: "node16" main: "main.js" diff --git a/main.sh b/main.sh index c922445..7433fbb 100755 --- a/main.sh +++ b/main.sh @@ -21,6 +21,7 @@ SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_S main() { args_kind=() args_knative=() + args_registry=() if [[ -n "${INPUT_VERSION:-}" ]]; then args_kind+=(--version "${INPUT_VERSION}") @@ -62,9 +63,21 @@ main() { args_knative+=(--knative-eventing "${INPUT_KNATIVE_EVENTING}") fi + if [[ -n "${INPUT_CPU:-}" ]]; then + args_registry+=(--cpu "${INPUT_CPU}") + fi + + if [[ -n "${INPUT_DISK:-}" ]]; then + args_registry+=(--disk "${INPUT_DISK}") + fi + + if [[ -n "${INPUT_MEMORY:-}" ]]; then + args_registry+=(--memory "${INPUT_MEMORY}") + fi + if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then - if [[ ${args:+exist} == "exist" ]] && [[ ${#args[@]} -gt 0 ]]; then - "$SCRIPT_DIR/registry.sh" "${args[@]}" + if [[ ${#args_registry[@]} -gt 0 ]]; then + "$SCRIPT_DIR/registry.sh" "${args_registry[@]}" else "$SCRIPT_DIR/registry.sh" fi @@ -83,8 +96,8 @@ main() { fi if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then - if [[ ${args:+exist} == "exist" ]] && [[ ${#args[@]} -gt 0 ]]; then - "$SCRIPT_DIR/registry.sh" "--document" "true" "${args[@]}" + if [[ ${#args_registry[@]} -gt 0 ]]; then + "$SCRIPT_DIR/registry.sh" "--document" "true" "${args_registry[@]}" else "$SCRIPT_DIR/registry.sh" "--document" "true" fi diff --git a/registry.sh b/registry.sh index 13c0ec6..29cfa8d 100755 --- a/registry.sh +++ b/registry.sh @@ -20,15 +20,21 @@ DEFAULT_REGISTRY_IMAGE=registry:2 DEFAULT_REGISTRY_NAME=kind-registry DEFAULT_REGISTRY_PORT=5000 DEFAULT_CLUSTER_NAME=kind +DEFAULT_CPU=2 +DEFAULT_MEMORY=12 +DEFAULT_DISK=60 show_help() { cat << EOF Usage: $(basename "$0") -h, --help Display help - --registry-image The registry image to use (default: registry:2) - --registry-name The registry name to use - --registry-port The local port used to bind the registry + --cpu Number of CPUs to be allocated to the virtual machine (default: $DEFAULT_CPU). For Mac OS only + --disk Size of the disk in GiB to be allocated to the virtual machine (default: $DEFAULT_DISK). For Mac OS only + --memory Size of the memory in GiB to be allocated to the virtual machine (default: $DEFAULT_MEMORY). For Mac OS only + --registry-image The registry image to use (default: $DEFAULT_REGISTRY_IMAGE) + --registry-name The registry name to use (default: $DEFAULT_REGISTRY_NAME) + --registry-port The local port used to bind the registry (default: $DEFAULT_REGISTRY_PORT) -n, --cluster-name The name of the cluster to create (default: $DEFAULT_CLUSTER_NAME)" --document Document the local registry @@ -40,6 +46,9 @@ main() { local registry_name="$DEFAULT_REGISTRY_NAME" local registry_port="$DEFAULT_REGISTRY_PORT" local cluster_name="$DEFAULT_CLUSTER_NAME" + local cpu="$DEFAULT_CPU" + local disk="$DEFAULT_DISK" + local memory="$DEFAULT_MEMORY" local document=false parse_command_line "$@" @@ -63,6 +72,36 @@ parse_command_line() { show_help exit ;; + --cpu) + if [[ -n "${2:-}" ]]; then + cpu="$2" + shift + else + echo "ERROR: '--cpu' cannot be empty." >&2 + show_help + exit 1 + fi + ;; + --disk) + if [[ -n "${2:-}" ]]; then + disk="$2" + shift + else + echo "ERROR: '--disk' cannot be empty." >&2 + show_help + exit 1 + fi + ;; + --memory) + if [[ -n "${2:-}" ]]; then + memory="$2" + shift + else + echo "ERROR: '--memory' cannot be empty." >&2 + show_help + exit 1 + fi + ;; --registry-image) if [[ -n "${2:-}" ]]; then registry_image="$2" @@ -126,7 +165,7 @@ install_docker() { if [ "$RUNNER_OS" == "macOS" ] && ! [ -x "$(command -v docker)" ]; then echo 'Installing docker...' brew install docker colima - colima start + colima start --cpu "$cpu" --memory "$memory" --disk "$disk" fi }