@@ -33,8 +33,8 @@ const (
3333 kubeProxyRepoPath = "eks/kube-proxy"
3434 coreDNSRepoPath = "eks/coredns"
3535
36- // Largest eksbuild tag we will try looking for.
37- maxEKSBuild = 20
36+ // Largest eksbuild tag we will try looking for (by binary search)
37+ maxEKSBuild = 128
3838)
3939
4040var (
@@ -625,30 +625,51 @@ func findLatestEKSBuild(token, repoDomain, repoPath, tagBase string) (string, er
625625 return tagBase , nil
626626 }
627627
628- var existingTag string
629- for i := 0 ; i < maxEKSBuild ; i ++ {
628+ left , right := 1 , maxEKSBuild
629+ for {
630+ i := ((right - left ) / 2 ) + left
631+ // Round .5 up
632+ i += (right - left ) % 2
633+
630634 version := fmt .Sprintf ("%s.%d" , tagBase , i + 1 )
631635 query := "v" + version
632636 logger .Debugf ("Trying %s" , query )
633637 tagExists , err := eksawshelper .TagExistsInRepo (token , repoDomain , repoPath , query )
634638 if err != nil {
635639 return "" , err
636640 }
641+ // adjust our bounds
637642 if tagExists {
638643 logger .Debugf ("Found %s" , query )
639- // Update the latest tag marker
640- existingTag = version
644+ // Smallest possible result is this one
645+ left = i
646+
647+ // Window has shrunk to just this, we have our answer
648+ if left == right {
649+ // Unless we're at the max value, then values may go higher
650+ if right == maxEKSBuild {
651+ // MAINTAINER'S NOTE: If we ever reach here, this is 100% a bug in kubergrunt. Investigation is
652+ // needed to resolve this, as it could be maxEKSBuild count is too small.
653+ return "" , commonerrors .ImpossibleErr ("TOO_MANY_EKS_BUILD_TAGS" )
654+ }
655+ logger .Debugf ("Returning %s" , version )
656+ return version , nil
657+ }
658+
641659 } else {
642660 logger .Debugf ("Not found %s" , query )
643- logger .Debugf ("Returning %s" , existingTag )
644- // At this point, the last existing tag we encountered is the latest, so we return it.
645- return existingTag , nil
661+
662+ // Searched entire range and found none
663+ if left == right {
664+ // MAINTAINER'S NOTE: If we ever reach here, this is 100% a bug in kubergrunt. Investigation is needed
665+ // to resolve this, as it could be the wrong version is being queried.
666+ return "" , commonerrors .ImpossibleErr ("NO_EKS_BUILD_TAGS" )
667+ }
668+
669+ // Largest possible result is right before this one
670+ right = i - 1
646671 }
647672 }
648-
649- // MAINTAINER'S NOTE: If we ever reach here, this is 100% a bug in kubergrunt. Investigation is needed to resolve
650- // this, as it could be either the wrong version is being queried, or the maxEKSBuild count is too small.
651- return "" , commonerrors .ImpossibleErr ("TOO_MANY_EKS_BUILD_TAGS" )
652673}
653674
654675// getRepoDomain is a conveniency function to construct the ECR docker repo URL domain.
0 commit comments