@@ -33,8 +33,8 @@ const (
33
33
kubeProxyRepoPath = "eks/kube-proxy"
34
34
coreDNSRepoPath = "eks/coredns"
35
35
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
38
38
)
39
39
40
40
var (
@@ -625,30 +625,51 @@ func findLatestEKSBuild(token, repoDomain, repoPath, tagBase string) (string, er
625
625
return tagBase , nil
626
626
}
627
627
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
+
630
634
version := fmt .Sprintf ("%s.%d" , tagBase , i + 1 )
631
635
query := "v" + version
632
636
logger .Debugf ("Trying %s" , query )
633
637
tagExists , err := eksawshelper .TagExistsInRepo (token , repoDomain , repoPath , query )
634
638
if err != nil {
635
639
return "" , err
636
640
}
641
+ // adjust our bounds
637
642
if tagExists {
638
643
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
+
641
659
} else {
642
660
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
646
671
}
647
672
}
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" )
652
673
}
653
674
654
675
// getRepoDomain is a conveniency function to construct the ECR docker repo URL domain.
0 commit comments