Merge pull request #64881 from chuckha/ci-cross

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Use repo prefix when generating image names

CI defines its own custom repository. The function responsible
for listing all images now takes this into account.

Closes kubernetes/kubeadm#901

Signed-off-by: Chuck Ha <ha.chuck@gmail.com>

**What this PR does / why we need it**:
This fixes ci-cross.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes kubernetes/kubeadm#901

**Special notes for your reviewer**:

```release-note
NONE
```
pull/8/head
Kubernetes Submit Queue 2018-06-07 13:44:54 -07:00 committed by GitHub
commit 16921ae7a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 5 deletions

View File

@ -27,7 +27,10 @@ go_test(
name = "go_default_test",
srcs = ["images_test.go"],
embed = [":go_default_library"],
deps = ["//cmd/kubeadm/app/constants:go_default_library"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/constants:go_default_library",
],
)
filegroup(

View File

@ -47,11 +47,14 @@ func GetCoreImage(image, repoPrefix, k8sVersion, overrideImage string) string {
// GetAllImages returns a list of container images kubeadm expects to use on a control plane node
func GetAllImages(cfg *kubeadmapi.MasterConfiguration) []string {
repoPrefix := cfg.GetControlPlaneImageRepository()
imgs := []string{}
imgs = append(imgs, GetCoreImage(constants.KubeAPIServer, cfg.ImageRepository, cfg.KubernetesVersion, cfg.UnifiedControlPlaneImage))
imgs = append(imgs, GetCoreImage(constants.KubeControllerManager, cfg.ImageRepository, cfg.KubernetesVersion, cfg.UnifiedControlPlaneImage))
imgs = append(imgs, GetCoreImage(constants.KubeScheduler, cfg.ImageRepository, cfg.KubernetesVersion, cfg.UnifiedControlPlaneImage))
imgs = append(imgs, fmt.Sprintf("%v/%v-%v:%v", cfg.ImageRepository, constants.KubeProxy, runtime.GOARCH, kubeadmutil.KubernetesVersionToImageTag(cfg.KubernetesVersion)))
imgs = append(imgs, GetCoreImage(constants.KubeAPIServer, repoPrefix, cfg.KubernetesVersion, cfg.UnifiedControlPlaneImage))
imgs = append(imgs, GetCoreImage(constants.KubeControllerManager, repoPrefix, cfg.KubernetesVersion, cfg.UnifiedControlPlaneImage))
imgs = append(imgs, GetCoreImage(constants.KubeScheduler, repoPrefix, cfg.KubernetesVersion, cfg.UnifiedControlPlaneImage))
imgs = append(imgs, fmt.Sprintf("%v/%v-%v:%v", repoPrefix, constants.KubeProxy, runtime.GOARCH, kubeadmutil.KubernetesVersionToImageTag(cfg.KubernetesVersion)))
// pause, etcd and kube-dns are not available on the ci image repository so use the default image repository.
imgs = append(imgs, fmt.Sprintf("%v/pause-%v:%v", cfg.ImageRepository, runtime.GOARCH, "3.1"))
// if etcd is not external then add the image as it will be required

View File

@ -19,8 +19,10 @@ package images
import (
"fmt"
"runtime"
"strings"
"testing"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
)
@ -73,3 +75,46 @@ func TestGetCoreImage(t *testing.T) {
}
}
}
func TestGetAllImages(t *testing.T) {
testcases := []struct {
name string
cfg *kubeadmapi.MasterConfiguration
expect string
}{
{
name: "defined CIImageRepository",
cfg: &kubeadmapi.MasterConfiguration{
CIImageRepository: "test.repo",
},
expect: "test.repo",
},
{
name: "undefined CIImagerRepository should contain the default image prefix",
cfg: &kubeadmapi.MasterConfiguration{
ImageRepository: "real.repo",
},
expect: "real.repo",
},
{
name: "test that etcd is returned when it is not external",
cfg: &kubeadmapi.MasterConfiguration{
Etcd: kubeadmapi.Etcd{
Local: &kubeadmapi.LocalEtcd{},
},
},
expect: constants.Etcd,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
imgs := GetAllImages(tc.cfg)
for _, img := range imgs {
if strings.Contains(img, tc.expect) {
return
}
}
t.Fatalf("did not find %q in %q", tc.expect, imgs)
})
}
}