Skip to content

Commit

Permalink
🐛 (eks sync-core-components): Increase maxEKSBuild, do binary search
Browse files Browse the repository at this point in the history
There are in fact 10 builds of eks/coredns:1.9.3-eksbuild. This jumps the threshold from 10 to 128, and switches to doing a binary search rather than a forward crawl to keep the request count down.
  • Loading branch information
ThisGuyCodes committed Nov 21, 2023
1 parent decec19 commit 9caad3a
Showing 1 changed file with 34 additions and 13 deletions.
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 = 10
// 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

0 comments on commit 9caad3a

Please sign in to comment.