Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add custom kubeconfig option as action input #119

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ jobs:
kubectl cluster-info
kubectl get nodes

test-with-custom-kubeconfig:
runs-on: ubuntu-latest
env:
KUBECONFIG: "./kubeconfig"
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Create kind cluster with custom kubeconfig
uses: ./
with:
kubeconfig: "${{ env.KUBECONFIG }}"
cluster_name: "kube-config-test"

- name: Test
run: |
grep "kube-config-test" ${KUBECONFIG}

test-with-custom-kubectl-version:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ inputs:
config:
description: "The path to the kind config file"
required: false
kubeconfig:
description: "The path to the kubeconfig config file"
required: false
node_image:
description: "The Docker image for the cluster nodes"
required: false
Expand Down
16 changes: 16 additions & 0 deletions kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Usage: $(basename "$0") <options>
--help Display help
-v, --version The kind version to use (default: $DEFAULT_KIND_VERSION)
-c, --config The path to the kind config file
-K, --kubeconfig The path to the kubeconfig config file
-i, --node-image The Docker image for the cluster nodes
-n, --cluster-name The name of the cluster to create (default: chart-testing)
-w, --wait The duration to wait for the control plane to become ready (default: 60s)
Expand All @@ -42,6 +43,7 @@ EOF
main() {
local version="${DEFAULT_KIND_VERSION}"
local config=
local kubeconfig=
local node_image=
local cluster_name="${DEFAULT_CLUSTER_NAME}"
local wait=60s
Expand Down Expand Up @@ -117,6 +119,16 @@ parse_command_line() {
exit 1
fi
;;
-K|--kubeconfig)
if [[ -n "${2:-}" ]]; then
kubeconfig="$2"
shift
else
echo "ERROR: '--kubeconfig' cannot be empty." >&2
show_help
exit 1
fi
;;
-i|--node-image)
if [[ -n "${2:-}" ]]; then
node_image="$2"
Expand Down Expand Up @@ -220,6 +232,10 @@ create_kind_cluster() {
args+=("--config=${config}")
fi

if [[ -n "${kubeconfig}" ]]; then
args+=("--kubeconfig=${kubeconfig}")
fi

if [[ -n "${verbosity}" ]]; then
args+=("--verbosity=${verbosity}")
fi
Expand Down
4 changes: 4 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ main() {
args+=(--config "${INPUT_CONFIG}")
fi

if [[ -n "${INPUT_KUBECONFIG:-}" ]]; then
args+=(--kubeconfig "${INPUT_KUBECONFIG}")
fi

if [[ -n "${INPUT_NODE_IMAGE:-}" ]]; then
args+=(--node-image "${INPUT_NODE_IMAGE}")
fi
Expand Down