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>
This commit is contained in:
Chuck Ha 2018-06-07 10:42:44 -04:00
parent c2e3d0526d
commit 6cad0100ad
No known key found for this signature in database
GPG Key ID: D2B2A4E41BEF2D78
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)
})
}
}