kubeadm: get k8s CI version markers from k8s infra bucket

Updates kubeadm version resolution to use kubernetes community infra
bucket to fetch appropriate k8s ci versions. The images are already
being pulled from the kubernetes community infra bucket meaning that a
mismatch can occur when the ci version is fetched from the google infra
bucket and the image is not yet present on k8s infra.

Follow-up to kubernetes/kubernetes#97087

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This commit is contained in:
hasheddan 2021-02-06 10:59:15 -06:00
parent 25d5d657c7
commit 1d164d0747
No known key found for this signature in database
GPG Key ID: BD68BC686A14C271
2 changed files with 9 additions and 5 deletions

View File

@ -39,6 +39,7 @@ const (
var (
kubeReleaseBucketURL = "https://dl.k8s.io"
kubeCIBucketURL = "https://storage.googleapis.com/k8s-release-dev"
kubeReleaseRegex = regexp.MustCompile(`^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)([-0-9a-zA-Z_\.+]*)?$`)
kubeReleaseLabelRegex = regexp.MustCompile(`^((latest|stable)+(-[1-9](\.[1-9]([0-9])?)?)?)\z`)
kubeBucketPrefixes = regexp.MustCompile(`^((release|ci|ci-cross)/)?([-\w_\.+]+)$`)
@ -160,7 +161,7 @@ func normalizedBuildVersion(version string) string {
// Internal helper: split version parts,
// Return base URL and cleaned-up version
func splitVersion(version string) (string, string, error) {
var urlSuffix string
var bucketURL, urlSuffix string
subs := kubeBucketPrefixes.FindAllStringSubmatch(version, 1)
if len(subs) != 1 || len(subs[0]) != 4 {
return "", "", errors.Errorf("invalid version %q", version)
@ -170,10 +171,12 @@ func splitVersion(version string) (string, string, error) {
case strings.HasPrefix(subs[0][2], "ci"):
// Just use whichever the user specified
urlSuffix = subs[0][2]
bucketURL = kubeCIBucketURL
default:
urlSuffix = "release"
bucketURL = kubeReleaseBucketURL
}
url := fmt.Sprintf("%s/%s", kubeReleaseBucketURL, urlSuffix)
url := fmt.Sprintf("%s/%s", bucketURL, urlSuffix)
return url, subs[0][3], nil
}

View File

@ -19,11 +19,12 @@ package util
import (
"errors"
"fmt"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
"path"
"strings"
"testing"
"time"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
)
func TestEmptyVersion(t *testing.T) {
@ -195,8 +196,8 @@ func TestSplitVersion(t *testing.T) {
{"release/v1.7.0", "https://dl.k8s.io/release", "v1.7.0", true},
{"release/latest-1.7", "https://dl.k8s.io/release", "latest-1.7", true},
// CI builds area
{"ci/latest", "https://dl.k8s.io/ci", "latest", true},
{"ci/latest-1.7", "https://dl.k8s.io/ci", "latest-1.7", true},
{"ci/latest", "https://storage.googleapis.com/k8s-release-dev/ci", "latest", true},
{"ci/latest-1.7", "https://storage.googleapis.com/k8s-release-dev/ci", "latest-1.7", true},
// unknown label in default (release) area: splitVersion validate only areas.
{"unknown-1", "https://dl.k8s.io/release", "unknown-1", true},
// unknown area, not valid input.