2016-10-21 21:45:42 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package images
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
|
2017-08-08 12:07:21 +00:00
|
|
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
2016-10-21 21:45:42 +00:00
|
|
|
)
|
|
|
|
|
2017-02-01 22:05:14 +00:00
|
|
|
const (
|
2017-07-12 11:43:29 +00:00
|
|
|
testversion = "v10.1.2-alpha.1.100+0123456789abcdef+SOMETHING"
|
|
|
|
expected = "v10.1.2-alpha.1.100_0123456789abcdef_SOMETHING"
|
Switch to k8s.gcr.io vanity domain
This is the 2nd attempt. The previous was reverted while we figured out
the regional mirrors (oops).
New plan: k8s.gcr.io is a read-only facade that auto-detects your source
region (us, eu, or asia for now) and pulls from the closest. To publish
an image, push k8s-staging.gcr.io and it will be synced to the regionals
automatically (similar to today). For now the staging is an alias to
gcr.io/google_containers (the legacy URL).
When we move off of google-owned projects (working on it), then we just
do a one-time sync, and change the google-internal config, and nobody
outside should notice.
We can, in parallel, change the auto-sync into a manual sync - send a PR
to "promote" something from staging, and a bot activates it. Nice and
visible, easy to keep track of.
2018-01-17 19:36:53 +00:00
|
|
|
gcrPrefix = "k8s.gcr.io"
|
2017-02-01 22:05:14 +00:00
|
|
|
)
|
2016-10-21 21:45:42 +00:00
|
|
|
|
|
|
|
func TestGetCoreImage(t *testing.T) {
|
2017-08-08 12:07:21 +00:00
|
|
|
var tests = []struct {
|
|
|
|
image, repo, version, override, expected string
|
2016-10-21 21:45:42 +00:00
|
|
|
}{
|
2017-08-08 12:07:21 +00:00
|
|
|
{
|
|
|
|
override: "override",
|
|
|
|
expected: "override",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image: constants.Etcd,
|
|
|
|
repo: gcrPrefix,
|
|
|
|
expected: fmt.Sprintf("%s/%s-%s:%s", gcrPrefix, "etcd", runtime.GOARCH, constants.DefaultEtcdVersion),
|
2016-10-21 21:45:42 +00:00
|
|
|
},
|
2017-08-08 12:07:21 +00:00
|
|
|
{
|
|
|
|
image: constants.KubeAPIServer,
|
|
|
|
repo: gcrPrefix,
|
|
|
|
version: testversion,
|
|
|
|
expected: fmt.Sprintf("%s/%s-%s:%s", gcrPrefix, "kube-apiserver", runtime.GOARCH, expected),
|
2016-10-21 21:45:42 +00:00
|
|
|
},
|
2017-08-08 12:07:21 +00:00
|
|
|
{
|
|
|
|
image: constants.KubeControllerManager,
|
|
|
|
repo: gcrPrefix,
|
|
|
|
version: testversion,
|
|
|
|
expected: fmt.Sprintf("%s/%s-%s:%s", gcrPrefix, "kube-controller-manager", runtime.GOARCH, expected),
|
2016-10-21 21:45:42 +00:00
|
|
|
},
|
2017-08-08 12:07:21 +00:00
|
|
|
{
|
|
|
|
image: constants.KubeScheduler,
|
|
|
|
repo: gcrPrefix,
|
|
|
|
version: testversion,
|
|
|
|
expected: fmt.Sprintf("%s/%s-%s:%s", gcrPrefix, "kube-scheduler", runtime.GOARCH, expected),
|
2016-10-21 21:45:42 +00:00
|
|
|
},
|
|
|
|
}
|
2017-08-08 12:07:21 +00:00
|
|
|
for _, rt := range tests {
|
|
|
|
actual := GetCoreImage(rt.image, rt.repo, rt.version, rt.override)
|
|
|
|
if actual != rt.expected {
|
2016-10-21 21:45:42 +00:00
|
|
|
t.Errorf(
|
|
|
|
"failed GetCoreImage:\n\texpected: %s\n\t actual: %s",
|
2017-08-08 12:07:21 +00:00
|
|
|
rt.expected,
|
2016-10-21 21:45:42 +00:00
|
|
|
actual,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|