Skip to content

Commit

Permalink
Merge pull request kubernetes#102506 from ykakarap/automated-cherry-p…
Browse files Browse the repository at this point in the history
…ick-of-#102502-upstream-release-1.21

Automated cherry pick of kubernetes#102502: use subpath for coredns only for default repository
  • Loading branch information
k8s-ci-robot committed Jun 2, 2021
2 parents 178fd74 + 38a41e1 commit 49be907
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/kubeadm/app/constants/constants.go
Expand Up @@ -328,7 +328,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"
Expand Down
5 changes: 5 additions & 0 deletions cmd/kubeadm/app/images/images.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -52,6 +53,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)

Expand Down
50 changes: 50 additions & 0 deletions cmd/kubeadm/app/images/images_test.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -237,3 +238,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,
)
}
}
}

0 comments on commit 49be907

Please sign in to comment.