Created
July 30, 2024 15:43
-
-
Save dipankardas011/55b1e42606f9ffef60de3f7cbc4f9759 to your computer and use it in GitHub Desktop.
kubernetes version check for eks
This file contains hidden or 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 ( | |
"context" | |
"fmt" | |
"log" | |
"github.com/aws/aws-sdk-go-v2/config" | |
"github.com/aws/aws-sdk-go-v2/service/eks" | |
"github.com/aws/aws-sdk-go/aws" | |
) | |
func main() { | |
// Load the AWS SDK configuration | |
// cfg, err := config.LoadDefaultConfig(context.TODO()) | |
cfg, err := config.LoadDefaultConfig(context.TODO(), | |
config.WithSharedConfigProfile("ksctl"), config.WithRegion("ap-south-1")) | |
if err != nil { | |
log.Fatalf("Unable to load SDK config, %v", err) | |
} | |
// Create an EKS client | |
client := eks.NewFromConfig(cfg) | |
// Create the input for DescribeAddonVersions | |
input1 := &eks.DescribeAddonVersionsInput{} | |
// Call DescribeAddonVersions | |
result11, err := client.DescribeAddonVersions(context.TODO(), input1) | |
if err != nil { | |
log.Fatalf("Unable to describe addon versions, %v", err) | |
} | |
// Extract and print the unique add-on names | |
addons := make(map[string]struct{}) | |
for _, addon := range result11.Addons { | |
if addon.AddonName != nil { | |
addons[*addon.AddonName] = struct{}{} | |
} | |
} | |
fmt.Println("Available EKS core add-ons:") | |
for addon := range addons { | |
fmt.Println(addon) | |
} | |
////////////// | |
fmt.Println("=====================================") | |
input := &eks.DescribeAddonVersionsInput{ | |
AddonName: aws.String("vpc-cni"), // You can change this to any core addon | |
KubernetesVersion: aws.String(""), // Empty string to get all versions | |
} | |
// Call DescribeAddonVersions | |
result, err := client.DescribeAddonVersions(context.TODO(), input) | |
if err != nil { | |
log.Fatalf("Unable to describe addon versions, %v", err) | |
} | |
// Extract and print the Kubernetes versions | |
versions := make(map[string]struct{}) | |
for _, addon := range result.Addons { | |
for _, addonVersion := range addon.AddonVersions { | |
for _, k8sVersion := range addonVersion.Compatibilities { | |
if k8sVersion.ClusterVersion != nil { | |
versions[*k8sVersion.ClusterVersion] = struct{}{} | |
} | |
} | |
} | |
} | |
fmt.Println("Available Kubernetes versions:") | |
for version := range versions { | |
fmt.Println(version) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment