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

🐛 (eks sync-core-components): Increase maxEKSBuild, do binary search #216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
47 changes: 34 additions & 13 deletions eks/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const (
kubeProxyRepoPath = "eks/kube-proxy"
coreDNSRepoPath = "eks/coredns"

// Largest eksbuild tag we will try looking for.
maxEKSBuild = 20
// Largest eksbuild tag we will try looking for (by binary search)
maxEKSBuild = 128
)

var (
Expand Down Expand Up @@ -625,30 +625,51 @@ func findLatestEKSBuild(token, repoDomain, repoPath, tagBase string) (string, er
return tagBase, nil
}

var existingTag string
for i := 0; i < maxEKSBuild; i++ {
left, right := 1, maxEKSBuild
for {
i := ((right - left) / 2) + left
// Round .5 up
i += (right - left) % 2

version := fmt.Sprintf("%s.%d", tagBase, i+1)
query := "v" + version
logger.Debugf("Trying %s", query)
tagExists, err := eksawshelper.TagExistsInRepo(token, repoDomain, repoPath, query)
if err != nil {
return "", err
}
// adjust our bounds
if tagExists {
logger.Debugf("Found %s", query)
// Update the latest tag marker
existingTag = version
// Smallest possible result is this one
left = i

// Window has shrunk to just this, we have our answer
if left == right {
// Unless we're at the max value, then values may go higher
if right == maxEKSBuild {
// MAINTAINER'S NOTE: If we ever reach here, this is 100% a bug in kubergrunt. Investigation is
// needed to resolve this, as it could be maxEKSBuild count is too small.
return "", commonerrors.ImpossibleErr("TOO_MANY_EKS_BUILD_TAGS")
}
logger.Debugf("Returning %s", version)
return version, nil
}

} else {
logger.Debugf("Not found %s", query)
logger.Debugf("Returning %s", existingTag)
// At this point, the last existing tag we encountered is the latest, so we return it.
return existingTag, nil

// Searched entire range and found none
if left == right {
// MAINTAINER'S NOTE: If we ever reach here, this is 100% a bug in kubergrunt. Investigation is needed
// to resolve this, as it could be the wrong version is being queried.
return "", commonerrors.ImpossibleErr("NO_EKS_BUILD_TAGS")
}

// Largest possible result is right before this one
right = i - 1
}
}

// MAINTAINER'S NOTE: If we ever reach here, this is 100% a bug in kubergrunt. Investigation is needed to resolve
// this, as it could be either the wrong version is being queried, or the maxEKSBuild count is too small.
return "", commonerrors.ImpossibleErr("TOO_MANY_EKS_BUILD_TAGS")
}

// getRepoDomain is a conveniency function to construct the ECR docker repo URL domain.
Expand Down