Skip to content

Commit

Permalink
Merge pull request #12 from essobedo/configure-resource-limits
Browse files Browse the repository at this point in the history
Allow to provide resource limits in case of Mac OS
  • Loading branch information
squakez authored Feb 9, 2023
2 parents b53ad9c + 5abb3b4 commit 61f1afd
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 17 additions & 4 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
47 changes: 43 additions & 4 deletions registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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") <options>
-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
Expand All @@ -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 "$@"
Expand All @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 61f1afd

Please sign in to comment.