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

Merge pull request #43 from minhthong582000/add-alias-flag

Add --alias flag to customize kubeconfig context name
This commit is contained in:
Jason Hall 2026-06-04 15:26:16 -04:00 committed by GitHub
commit c85c621c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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