Skip to content

Instantly share code, notes, and snippets.

@thainanfrota
Forked from maxtacu/eks-kubeconfig.go
Created June 18, 2024 18:36
Show Gist options
  • Save thainanfrota/c5503679abeca7dc7850bc69f748c916 to your computer and use it in GitHub Desktop.
Save thainanfrota/c5503679abeca7dc7850bc69f748c916 to your computer and use it in GitHub Desktop.
Update your kubeconfig with all EKS clusters
package main
import (
"encoding/json"
"fmt"
"log"
"os/exec"
)
type EKSClusters struct {
Clusters []string
}
func main() {
cmd := exec.Command("aws", "eks", "list-clusters")
stdout, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(string(stdout))
log.Fatal(err)
}
var clusterlist EKSClusters
json.Unmarshal(stdout, &clusterlist)
for _, clustername := range clusterlist.Clusters {
cmd := exec.Command("aws", "eks", "update-kubeconfig", "--name", clustername)
stdout, err := cmd.CombinedOutput()
if err != nil {
fmt.Println(string(stdout))
log.Fatal(err)
}
fmt.Println(string(stdout))
}
}
/* When you build the executable, try to make it as small as possible, you don't need ~3mb executable:
go build -ldflags="-s -w" eks-kubeconfig.go
upx --brute eks-kubeconfig
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment