1
0
Fork 0
mirror of https://github.com/imjasonh/gke-auth synced 2026-07-07 00:23:18 +00:00

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.
This commit is contained in:
minhthong582000 2026-06-05 00:58:18 +07:00
parent 939e332ebe
commit 8f2b6af6f1
2 changed files with 18 additions and 3 deletions

View file

@ -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[@]}"

View file

@ -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