Unverified Commit 6cad0100 authored by Chuck Ha's avatar Chuck Ha

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: 's avatarChuck Ha <ha.chuck@gmail.com>
parent c2e3d052
......@@ -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(
......
......@@ -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
......
......@@ -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)
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment