Skip to content

Commit d4887be

Browse files
authored
Add cloud provider (#135)
Signed-off-by: Walthier David <walthierdavid42@gmail.com>
1 parent d730aaf commit d4887be

File tree

6 files changed

+70
-1
lines changed

6 files changed

+70
-1
lines changed

.github/workflows/test.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,23 @@ jobs:
258258
259259
curl -X DELETE $LOCAL_REGISTRY/v2/localbusybox/manifests/$DIGEST
260260
[[ "$(curl -Ls $LOCAL_REGISTRY/v2/localbusybox/tags/list | jq .tags)" == null ]]
261-
261+
262+
test-with-cloud-provider-enabled:
263+
runs-on: ubuntu-latest
264+
steps:
265+
- name: Checkout
266+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
267+
268+
- name: Create kind cluster with cloud provider
269+
uses: ./
270+
with:
271+
cloud_provider: true
272+
273+
- name: Test
274+
run: |
275+
if ps aux | grep -v grep | grep cloud-provider-kind; then
276+
echo "Cloud provider is present."
277+
else
278+
echo "Cloud provider is not present."
279+
exit 1
280+
fi

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ For more information on inputs, see the [API Documentation](https://developer.gi
2929
- `registry_enable_delete`: Enable delete operations on the registry (default: false)
3030
- `install_only`: Skips cluster creation, only install kind (default: false)
3131
- `ignore_failed_clean`: Whether to ignore the post delete cluster action failing (default: false)
32+
- `cloud_provider`: Whether to use cloud provider loadbalancer (default: false)
3233

3334
### Example Workflow
3435

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ inputs:
6161
description: "Whether to ignore the post-delete the cluster (default: false)"
6262
default: "false"
6363
required: false
64+
cloud_provider:
65+
description: "Whether to use cloud provider loadbalancer (default: false)"
66+
required: false
67+
default: "false"
6468
runs:
6569
using: "node20"
6670
main: "main.js"

cleanup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ main() {
2525
args=(--name "${INPUT_CLUSTER_NAME:-$DEFAULT_CLUSTER_NAME}")
2626
registry_args=("${INPUT_REGISTRY_NAME:-$DEFAULT_REGISTRY_NAME}")
2727

28+
if [[ "${INPUT_CLOUD_PROVIDER:-false}" == true ]]; then
29+
rm -f /usr/local/bin/cloud-provider-kind || true
30+
rm -rf cloud-provider-kind || true
31+
rm -f /tmp/cloud-provider.log || true
32+
rm -f cloud-provider-kind_*_checksums.txt || true
33+
fi
34+
2835
docker rm -f "${registry_args[@]}" || "${INPUT_IGNORE_FAILED_CLEAN}"
2936

3037
kind delete cluster "${args[@]}" || "${INPUT_IGNORE_FAILED_CLEAN}"

kind.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set -o pipefail
2121
DEFAULT_KIND_VERSION=v0.26.0
2222
DEFAULT_CLUSTER_NAME=chart-testing
2323
DEFAULT_KUBECTL_VERSION=v1.31.4
24+
DEFAULT_CLOUD_PROVIDER_KIND_VERSION=0.6.0
2425

2526
show_help() {
2627
cat << EOF
@@ -37,6 +38,7 @@ Usage: $(basename "$0") <options>
3738
-k, --kubectl-version The kubectl version to use (default: $DEFAULT_KUBECTL_VERSION)
3839
-o, --install-only Skips cluster creation, only install kind (default: false)
3940
--with-registry Enables registry config dir for the cluster (default: false)
41+
--cloud-provider Enables cloud provider for the cluster (default: false)
4042
4143
EOF
4244
}
@@ -53,6 +55,7 @@ main() {
5355
local install_only=false
5456
local with_registry=false
5557
local config_with_registry_path="/etc/kind-registry/config.yaml"
58+
local cloud_provider=
5659

5760
parse_command_line "$@"
5861

@@ -198,6 +201,14 @@ parse_command_line() {
198201
with_registry=true
199202
fi
200203
;;
204+
--cloud-provider)
205+
if [[ -n "${2:-}" ]]; then
206+
cloud_provider="$2"
207+
shift
208+
else
209+
cloud_provider=true
210+
fi
211+
;;
201212
*)
202213
break
203214
;;
@@ -249,6 +260,25 @@ EOF
249260
sudo chmod a+r "$config_with_registry_path"
250261
}
251262

263+
install_cloud_provider(){
264+
echo "Setting up cloud-provider-kind..."
265+
curl -sSLo cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_linux_amd64.tar.gz https://github.com/kubernetes-sigs/cloud-provider-kind/releases/download/v${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}/cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_linux_amd64.tar.gz > /dev/null 2>&1
266+
curl -sSLo cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_checksums.txt https://github.com/kubernetes-sigs/cloud-provider-kind/releases/download/v${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}/cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_checksums.txt
267+
268+
grep "cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_linux_amd64.tar.gz" < "cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_checksums.txt" | sha256sum -c
269+
270+
mkdir -p cloud-provider-kind-tmp
271+
tar -xzf cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_linux_amd64.tar.gz -C cloud-provider-kind-tmp
272+
chmod +x cloud-provider-kind-tmp/cloud-provider-kind
273+
sudo mv cloud-provider-kind-tmp/cloud-provider-kind /usr/local/bin/
274+
rm -rf cloud-provider-kind-tmp cloud-provider-kind_${DEFAULT_CLOUD_PROVIDER_KIND_VERSION}_linux_amd64.tar.gz
275+
276+
echo "cloud-provider-kind set up successfully ✅"
277+
278+
cloud-provider-kind > /tmp/cloud-provider.log 2>&1 &
279+
echo "cloud-provider-kind started ✅"
280+
}
281+
252282
create_kind_cluster() {
253283
echo 'Creating kind cluster...'
254284
local args=(create cluster "--name=${cluster_name}" "--wait=${wait}")
@@ -278,6 +308,10 @@ create_kind_cluster() {
278308
fi
279309
fi
280310

311+
if [[ "${cloud_provider}" == true ]]; then
312+
install_cloud_provider
313+
fi
314+
281315
"${kind_dir}/kind" "${args[@]}"
282316
}
283317

main.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ main() {
8181
registry_args+=(--enable-delete "${INPUT_REGISTRY_ENABLE_DELETE}")
8282
fi
8383

84+
if [[ -n "${INPUT_CLOUD_PROVIDER:-}" ]]; then
85+
args+=(--cloud-provider "${INPUT_CLOUD_PROVIDER}")
86+
fi
87+
8488
"${SCRIPT_DIR}/kind.sh" ${args[@]+"${args[@]}"}
8589

8690
if [[ "${INPUT_REGISTRY:-}" == true ]]; then

0 commit comments

Comments
 (0)