-
-
Save thainanfrota/c5503679abeca7dc7850bc69f748c916 to your computer and use it in GitHub Desktop.
Update your kubeconfig with all EKS clusters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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