Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade only the patch versions for cilium on release branch #3724

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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