Skip to content

Commit

Permalink
Fixed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ckannon committed May 10, 2022
1 parent d66b6c9 commit 752bbed
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/minikube/bootstrapper/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ func Pause(v semver.Version, mirror string) string {
// https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants_unix.go
pv := "3.6"
imageName := "pause"
pv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), imageName), pv)
majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor)

if pVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok {
pv = pVersion
} else {
pv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), imageName), pv)
}

return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), pv)
Expand Down Expand Up @@ -80,23 +81,23 @@ func componentImage(name string, v semver.Version, mirror string) string {
func findLatestTagFromRepository(url string, lastKnownGood string) string {
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)

errorMsg := fmt.Sprintf("Failed to get latest image version for %s, reverting to version %s.", url, lastKnownGood)
if err != nil {
klog.Infof("Failed to get latest image version for %s, reverting to version %s\n", url, lastKnownGood)
klog.Warningf("%s Error %v", errorMsg, err)
return lastKnownGood
}

resp, err := client.Do(req)

if err != nil || resp.StatusCode != http.StatusOK {
klog.Infof("Failed to get latest image version for %s, reverting to version %s\n", url, lastKnownGood)
klog.Warningf("%s Error %v", errorMsg, err)
return lastKnownGood
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
if err != nil {
klog.Infof("Failed to read latest image version for %s, reverting to version %s\n", url, lastKnownGood)
klog.Warningf("%s Error %v", errorMsg, err)
return lastKnownGood
}

Expand All @@ -108,7 +109,7 @@ func findLatestTagFromRepository(url string, lastKnownGood string) string {
tags := TagsResponse{}
err = json.Unmarshal(body, &tags)
if err != nil || len(tags.Tags) < 1 {
klog.Infof("Failed to read latest image version for %s, reverting to version %s\n", url, lastKnownGood)
klog.Warningf("%s Error %v", errorMsg, err)
return lastKnownGood
}
lastTagNum := len(tags.Tags) - 1
Expand All @@ -123,14 +124,15 @@ func coreDNS(v semver.Version, mirror string) string {

in := "coredns/coredns"
cv := "v1.8.6"
cv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), in), cv)
if semver.MustParseRange("<1.21.0-alpha.1")(v) {
in = "coredns"
}

majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor)
if cVersion, ok := constants.KubeadmImages[majorMinorVersion][in]; ok {
cv = cVersion
} else {
cv = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), in), cv)
}

return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), in), cv)
Expand All @@ -143,10 +145,11 @@ func etcd(v semver.Version, mirror string) string {
// https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/constants/constants.go
ev := "3.5.0-0"
imageName := "etcd"
ev = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), ev), ev)
majorMinorVersion := fmt.Sprintf("v%d.%d", v.Major, v.Minor)
if eVersion, ok := constants.KubeadmImages[majorMinorVersion][imageName]; ok {
ev = eVersion
} else {
ev = findLatestTagFromRepository(fmt.Sprintf(tagURLTemplate, kubernetesRepo(mirror), ev), ev)
}

return fmt.Sprintf("%s:%s", path.Join(kubernetesRepo(mirror), imageName), ev)
Expand Down

0 comments on commit 752bbed

Please sign in to comment.