From 8f2b6af6f16b4a6875b3fb2d7339a2a9006dd9fb Mon Sep 17 00:00:00 2001 From: minhthong582000 <55283557+minhthong582000@users.noreply.github.com> Date: Fri, 5 Jun 2026 00:58:18 +0700 Subject: [PATCH] Add --alias flag to customize kubeconfig context name By default the context/cluster/user entries in kubeconfig are named gke_{project}_{location}_{cluster}, which is verbose and hard to type. Add --alias so users can set a short, memorable name instead. --- action.yaml | 17 ++++++++++++++--- main.go | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/action.yaml b/action.yaml index cf7680e..34eefdc 100644 --- a/action.yaml +++ b/action.yaml @@ -17,6 +17,10 @@ inputs: cluster: description: "Name of the cluster" required: true + alias: + description: "Alias name for the kubeconfig context (defaults to gke_{project}_{location}_{cluster})" + required: false + default: "" registry_location: description: "Region or multi-region of the Artifact Registry instance" required: false @@ -53,6 +57,13 @@ runs: gke-auth --location=${{ inputs.registry_location }} --configure-docker fi - gke-auth --project=${{ inputs.project }} \ - --location=${{ inputs.location }} \ - --cluster=${{ inputs.cluster }} + args=( + --project=${{ inputs.project }} + --location=${{ inputs.location }} + --cluster=${{ inputs.cluster }} + ) + if [[ "${{ inputs.alias }}" != "" ]]; then + args+=(--alias=${{ inputs.alias }}) + fi + + gke-auth "${args[@]}" diff --git a/main.go b/main.go index a8c0ce4..d7a5102 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ var ( project = flag.String("project", "", "Name of the project") location = flag.String("location", "", "Location of the cluster") clusterName = flag.String("cluster", "", "Name of the cluster") + alias = flag.String("alias", "", "Alias name for the kubeconfig context (defaults to gke_{project}_{location}_{cluster})") get = flag.Bool("get", false, "If true, print auth information") clear = flag.Bool("clear", false, "If true, clear auth for this cluster") @@ -163,6 +164,9 @@ func main() { // get kubeconfig location key := fmt.Sprintf("gke_%s_%s_%s", *project, *location, *clusterName) + if *alias != "" { + key = *alias + } kcfgPath := clientcmd.RecommendedHomeFile if auth := cfg.AuthInfos[key]; auth != nil && auth.LocationOfOrigin != "" { kcfgPath = auth.LocationOfOrigin