Skip to content

Commit

Permalink
feat: add custom kubeconfig option as action input (#119)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Battiato <jonathan.battiato@enterprisedb.com>
  • Loading branch information
jbattiato authored Sep 30, 2024
1 parent 6f17223 commit 5d66646
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
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

0 comments on commit 5d66646

Please sign in to comment.