use subpath for coredns only for default repository

This commit is contained in:
Yuvaraj Kakaraparthi 2021-06-01 11:57:37 -07:00
parent 5edccec32b
commit 97ba90cbfb
3 changed files with 56 additions and 1 deletions

View File

@ -326,7 +326,7 @@ const (
CoreDNSDeploymentName = "coredns"
// CoreDNSImageName specifies the name of the image for CoreDNS add-on
CoreDNSImageName = "coredns/coredns"
CoreDNSImageName = "coredns"
// CoreDNSVersion is the version of CoreDNS to be deployed if it is used
CoreDNSVersion = "v1.8.0"

View File

@ -21,6 +21,7 @@ import (
"k8s.io/klog/v2"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
)
@ -46,6 +47,10 @@ func GetDNSImage(cfg *kubeadmapi.ClusterConfiguration) string {
if cfg.DNS.ImageRepository != "" {
dnsImageRepository = cfg.DNS.ImageRepository
}
// Handle the renaming of the official image from "k8s.gcr.io/coredns" to "k8s.gcr.io/coredns/coredns
if dnsImageRepository == kubeadmapiv1beta2.DefaultImageRepository {
dnsImageRepository = fmt.Sprintf("%s/coredns", dnsImageRepository)
}
// DNS uses an imageTag that corresponds to the DNS version matching the Kubernetes version
dnsImageTag := constants.GetDNSVersion(cfg.DNS.Type)

View File

@ -22,6 +22,7 @@ import (
"testing"
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
)
@ -229,3 +230,52 @@ func TestGetAllImages(t *testing.T) {
})
}
}
func TestGetDNSImage(t *testing.T) {
var tests = []struct {
expected string
cfg *kubeadmapi.ClusterConfiguration
}{
{
expected: "foo.io/coredns:v1.8.0",
cfg: &kubeadmapi.ClusterConfiguration{
ImageRepository: "foo.io",
DNS: kubeadmapi.DNS{
Type: kubeadmapi.CoreDNS,
},
},
},
{
expected: kubeadmapiv1beta2.DefaultImageRepository + "/coredns/coredns:v1.8.0",
cfg: &kubeadmapi.ClusterConfiguration{
ImageRepository: kubeadmapiv1beta2.DefaultImageRepository,
DNS: kubeadmapi.DNS{
Type: kubeadmapi.CoreDNS,
},
},
},
{
expected: "foo.io/coredns/coredns:v1.8.0",
cfg: &kubeadmapi.ClusterConfiguration{
ImageRepository: "foo.io",
DNS: kubeadmapi.DNS{
Type: kubeadmapi.CoreDNS,
ImageMeta: kubeadmapi.ImageMeta{
ImageRepository: "foo.io/coredns",
},
},
},
},
}
for _, test := range tests {
actual := GetDNSImage(test.cfg)
if actual != test.expected {
t.Errorf(
"failed to GetDNSImage:\n\texpected: %s\n\t actual: %s",
test.expected,
actual,
)
}
}
}