Skip to content

Commit

Permalink
Merge pull request kubernetes#98842 from hasheddan/automated-cherry-p…
Browse files Browse the repository at this point in the history
…ick-of-#98836-upstream-release-1.20

Automated cherry pick of kubernetes#98836: kubeadm: get k8s CI version markers from k8s infra bucket
  • Loading branch information
k8s-ci-robot committed Feb 8, 2021
2 parents af0ce4d + 0e3bf6d commit fa36209
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 5 additions & 2 deletions cmd/kubeadm/app/util/version.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit fa36209

Please sign in to comment.