From 9caad3a13ce5167c5d112a10a0a1ca2a05624dc9 Mon Sep 17 00:00:00 2001 From: Travis Johnson Date: Tue, 21 Nov 2023 17:10:26 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(eks=20sync-core-components):=20?= =?UTF-8?q?Increase=20maxEKSBuild,=20do=20binary=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- eks/sync.go | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/eks/sync.go b/eks/sync.go index 87a864b..1929c33 100644 --- a/eks/sync.go +++ b/eks/sync.go @@ -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 ( @@ -625,8 +625,12 @@ 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) @@ -634,21 +638,38 @@ func findLatestEKSBuild(token, repoDomain, repoPath, tagBase string) (string, er 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.