Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #98836: kubeadm: get k8s CI version markers from k8s infra bucket #98842

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmd/kubeadm/app/util/version.go
Expand Up @@ -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_\.+]+)$`)
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
10 changes: 4 additions & 6 deletions cmd/kubeadm/app/util/version_test.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -195,16 +196,13 @@ 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.
{"unknown/latest-1", "", "", false},
}
// kubeReleaseBucketURL can be overridden during network tests, thus ensure
// it will contain value corresponding to expected outcome for this unit test
kubeReleaseBucketURL = "https://dl.k8s.io"

for _, tc := range cases {
t.Run(fmt.Sprintf("input:%s/label:%s", tc.input, tc.label), func(t *testing.T) {
Expand Down