Skip to content

Commit 61f1afd

Browse files
authored
Merge pull request #12 from essobedo/configure-resource-limits
Allow to provide resource limits in case of Mac OS
2 parents b53ad9c + 5abb3b4 commit 61f1afd

File tree

5 files changed

+87
-8
lines changed

5 files changed

+87
-8
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ jobs:
2929
kubectl cluster-info
3030
kubectl get storageclass standard
3131
32+
test-with-custom-resource-limits:
33+
runs-on: macos-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v1
37+
38+
- name: Create kind cluster with custom resource limits
39+
uses: ./
40+
with:
41+
cpu: "3"
42+
disk: "5"
43+
memory: "11"
44+
- name: Test
45+
run: |
46+
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"
47+
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"
48+
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"
49+
3250
test-with-custom-name:
3351
strategy:
3452
matrix:

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ For more information on inputs, see the [API Documentation](https://developer.gi
2828
- `knative_serving`: The version of Knative Serving to install on the Kind cluster (not installed by default - example: `v1.0.0`)
2929
- `knative_kourier`: The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: `v1.0.0`)
3030
- `knative_eventing`: The version of Knative Eventing to install on the Kind cluster (not installed by default - example: `v1.0.0`)
31+
- `cpu`: Number of CPUs to be allocated to the virtual machine (default: 2). For Mac OS only.
32+
- `memory`: Size of the memory in GiB to be allocated to the virtual machine (default: 12). For Mac OS only.
33+
- `disk`: Size of the disk in GiB to be allocated to the virtual machine (default: 60). For Mac OS only.
3134

3235
### Example Workflow
3336

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ inputs:
2727
description: "The version of Knative Net Kourier to install on the Kind cluster (not installed by default - example: v1.0.0)"
2828
knative_eventing:
2929
description: "The version of Knative Eventing to install on the Kind cluster (not installed by default - example: v1.0.0)"
30+
cpu:
31+
description: "For Mac OS only: Number of CPUs to be allocated to the virtual machine (default: 2)"
32+
memory:
33+
description: "For Mac OS only: Size of the memory in GiB to be allocated to the virtual machine (default: 12)"
34+
disk:
35+
description: "For Mac OS only: Size of the disk in GiB to be allocated to the virtual machine (default: 60)"
3036
runs:
3137
using: "node16"
3238
main: "main.js"

main.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_S
2121
main() {
2222
args_kind=()
2323
args_knative=()
24+
args_registry=()
2425

2526
if [[ -n "${INPUT_VERSION:-}" ]]; then
2627
args_kind+=(--version "${INPUT_VERSION}")
@@ -62,9 +63,21 @@ main() {
6263
args_knative+=(--knative-eventing "${INPUT_KNATIVE_EVENTING}")
6364
fi
6465

66+
if [[ -n "${INPUT_CPU:-}" ]]; then
67+
args_registry+=(--cpu "${INPUT_CPU}")
68+
fi
69+
70+
if [[ -n "${INPUT_DISK:-}" ]]; then
71+
args_registry+=(--disk "${INPUT_DISK}")
72+
fi
73+
74+
if [[ -n "${INPUT_MEMORY:-}" ]]; then
75+
args_registry+=(--memory "${INPUT_MEMORY}")
76+
fi
77+
6578
if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then
66-
if [[ ${args:+exist} == "exist" ]] && [[ ${#args[@]} -gt 0 ]]; then
67-
"$SCRIPT_DIR/registry.sh" "${args[@]}"
79+
if [[ ${#args_registry[@]} -gt 0 ]]; then
80+
"$SCRIPT_DIR/registry.sh" "${args_registry[@]}"
6881
else
6982
"$SCRIPT_DIR/registry.sh"
7083
fi
@@ -83,8 +96,8 @@ main() {
8396
fi
8497

8598
if [[ -z "${INPUT_REGISTRY:-}" ]] || [[ "$(echo ${INPUT_REGISTRY} | tr '[:upper:]' '[:lower:]')" = "true" ]]; then
86-
if [[ ${args:+exist} == "exist" ]] && [[ ${#args[@]} -gt 0 ]]; then
87-
"$SCRIPT_DIR/registry.sh" "--document" "true" "${args[@]}"
99+
if [[ ${#args_registry[@]} -gt 0 ]]; then
100+
"$SCRIPT_DIR/registry.sh" "--document" "true" "${args_registry[@]}"
88101
else
89102
"$SCRIPT_DIR/registry.sh" "--document" "true"
90103
fi

registry.sh

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ DEFAULT_REGISTRY_IMAGE=registry:2
2020
DEFAULT_REGISTRY_NAME=kind-registry
2121
DEFAULT_REGISTRY_PORT=5000
2222
DEFAULT_CLUSTER_NAME=kind
23+
DEFAULT_CPU=2
24+
DEFAULT_MEMORY=12
25+
DEFAULT_DISK=60
2326

2427
show_help() {
2528
cat << EOF
2629
Usage: $(basename "$0") <options>
2730
2831
-h, --help Display help
29-
--registry-image The registry image to use (default: registry:2)
30-
--registry-name The registry name to use
31-
--registry-port The local port used to bind the registry
32+
--cpu Number of CPUs to be allocated to the virtual machine (default: $DEFAULT_CPU). For Mac OS only
33+
--disk Size of the disk in GiB to be allocated to the virtual machine (default: $DEFAULT_DISK). For Mac OS only
34+
--memory Size of the memory in GiB to be allocated to the virtual machine (default: $DEFAULT_MEMORY). For Mac OS only
35+
--registry-image The registry image to use (default: $DEFAULT_REGISTRY_IMAGE)
36+
--registry-name The registry name to use (default: $DEFAULT_REGISTRY_NAME)
37+
--registry-port The local port used to bind the registry (default: $DEFAULT_REGISTRY_PORT)
3238
-n, --cluster-name The name of the cluster to create (default: $DEFAULT_CLUSTER_NAME)"
3339
--document Document the local registry
3440
@@ -40,6 +46,9 @@ main() {
4046
local registry_name="$DEFAULT_REGISTRY_NAME"
4147
local registry_port="$DEFAULT_REGISTRY_PORT"
4248
local cluster_name="$DEFAULT_CLUSTER_NAME"
49+
local cpu="$DEFAULT_CPU"
50+
local disk="$DEFAULT_DISK"
51+
local memory="$DEFAULT_MEMORY"
4352
local document=false
4453

4554
parse_command_line "$@"
@@ -63,6 +72,36 @@ parse_command_line() {
6372
show_help
6473
exit
6574
;;
75+
--cpu)
76+
if [[ -n "${2:-}" ]]; then
77+
cpu="$2"
78+
shift
79+
else
80+
echo "ERROR: '--cpu' cannot be empty." >&2
81+
show_help
82+
exit 1
83+
fi
84+
;;
85+
--disk)
86+
if [[ -n "${2:-}" ]]; then
87+
disk="$2"
88+
shift
89+
else
90+
echo "ERROR: '--disk' cannot be empty." >&2
91+
show_help
92+
exit 1
93+
fi
94+
;;
95+
--memory)
96+
if [[ -n "${2:-}" ]]; then
97+
memory="$2"
98+
shift
99+
else
100+
echo "ERROR: '--memory' cannot be empty." >&2
101+
show_help
102+
exit 1
103+
fi
104+
;;
66105
--registry-image)
67106
if [[ -n "${2:-}" ]]; then
68107
registry_image="$2"
@@ -126,7 +165,7 @@ install_docker() {
126165
if [ "$RUNNER_OS" == "macOS" ] && ! [ -x "$(command -v docker)" ]; then
127166
echo 'Installing docker...'
128167
brew install docker colima
129-
colima start
168+
colima start --cpu "$cpu" --memory "$memory" --disk "$disk"
130169
fi
131170
}
132171

0 commit comments

Comments
 (0)