Skip to content

Commit

Permalink
Upgrade only the patch versions for cilium on release branch (#3724)
Browse files Browse the repository at this point in the history
* Upgrade only the patch versions for cilium on release branch

* Add support for Cilium version in display command
  • Loading branch information
sp1999 authored Sep 5, 2024
1 parent e512376 commit 64f0fff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
19 changes: 15 additions & 4 deletions tools/version-tracker/pkg/commands/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import (
"gopkg.in/yaml.v3"

"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/constants"
"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/ecrpublic"
"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/git"
"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/github"
"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/types"
)

// Run contains the business logic to execute the `display` subcommand.
func Run(displayOptions *types.DisplayOptions) error {
projectName := displayOptions.ProjectName

// Check if branch name environment variable has been set.
branchName, ok := os.LookupEnv(constants.BranchNameEnvVar)
if !ok {
Expand Down Expand Up @@ -126,10 +129,18 @@ func Run(displayOptions *types.DisplayOptions) error {
isTrackedByCommitHash = true
}

// Get latest revision for the project from GitHub.
latestRevision, _, err := github.GetLatestRevision(client, org, repoName, currentRevision, branchName, isTrackedByCommitHash, releaseBranched)
if err != nil {
return fmt.Errorf("getting latest revision from GitHub: %v", err)
var latestRevision string
if projectName == "cilium/cilium" {
latestRevision, _, err = ecrpublic.GetLatestRevision(constants.CiliumImageRepository, currentRevision, branchName)
if err != nil {
return fmt.Errorf("getting latest revision from ECR Public: %v", err)
}
} else {
// Get latest revision for the project from GitHub.
latestRevision, _, err = github.GetLatestRevision(client, org, repoName, currentRevision, branchName, isTrackedByCommitHash, releaseBranched)
if err != nil {
return fmt.Errorf("getting latest revision from GitHub: %v", err)
}
}

// Check if we should print only the latest version of the project.
Expand Down
2 changes: 1 addition & 1 deletion tools/version-tracker/pkg/commands/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func Run(upgradeOptions *types.UpgradeOptions) error {
var latestRevision string
var needsUpgrade bool
if projectName == "cilium/cilium" {
latestRevision, needsUpgrade, err = ecrpublic.GetLatestRevision(constants.CiliumImageRepository, currentRevision)
latestRevision, needsUpgrade, err = ecrpublic.GetLatestRevision(constants.CiliumImageRepository, currentRevision, branchName)
if err != nil {
return fmt.Errorf("getting latest revision from ECR Public: %v", err)
}
Expand Down
13 changes: 11 additions & 2 deletions tools/version-tracker/pkg/ecrpublic/ecrpublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"encoding/json"
"fmt"
"os/exec"
"regexp"
"strings"

"github.com/aws/eks-anywhere/pkg/semver"

"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/constants"
"github.com/aws/eks-anywhere-build-tooling/tools/version-tracker/pkg/util/command"
)

func GetLatestRevision(imageRepository, currentRevision string) (string, bool, error) {
func GetLatestRevision(imageRepository, currentRevision, branchName string) (string, bool, error) {
var latestRevision string
currentRevisionSemver, err := semver.New(currentRevision)
if err != nil {
Expand All @@ -21,7 +23,7 @@ func GetLatestRevision(imageRepository, currentRevision string) (string, bool, e
skopeoListTagsCmd := exec.Command("skopeo", "list-tags", fmt.Sprintf("docker://%s", imageRepository))
listTagsOutput, err := command.ExecCommand(skopeoListTagsCmd)
if err != nil {
return "", false, fmt.Errorf("running Go version command: %v", err)
return "", false, fmt.Errorf("running Skopeo list-tags command: %v", err)
}

var tagsList interface{}
Expand All @@ -44,6 +46,13 @@ func GetLatestRevision(imageRepository, currentRevision string) (string, bool, e
return "", false, fmt.Errorf("getting semver for Cilium tag [%s]: %v", tag, err)
}

if branchName != constants.MainBranchName {
tagRegex := regexp.MustCompile(fmt.Sprintf(`^v%d.%d.\d+`, currentRevisionSemver.Major, currentRevisionSemver.Minor))
if !tagRegex.MatchString(tag) {
continue
}
}

if tagSemver.GreaterThan(latestRevisionSemver) {
latestRevisionSemver = tagSemver
latestRevision = tag
Expand Down

0 comments on commit 64f0fff

Please sign in to comment.