images.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package images
  14. import (
  15. "fmt"
  16. "k8s.io/klog"
  17. kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
  18. "k8s.io/kubernetes/cmd/kubeadm/app/constants"
  19. kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
  20. )
  21. const extraHyperKubeNote = ` The "useHyperKubeImage" field will be removed from future kubeadm config versions and possibly ignored in future releases.`
  22. // GetGenericImage generates and returns a platform agnostic image (backed by manifest list)
  23. func GetGenericImage(prefix, image, tag string) string {
  24. return fmt.Sprintf("%s/%s:%s", prefix, image, tag)
  25. }
  26. // GetKubernetesImage generates and returns the image for the components managed in the Kubernetes main repository,
  27. // including the control-plane components and kube-proxy. If specified, the HyperKube image will be used.
  28. func GetKubernetesImage(image string, cfg *kubeadmapi.ClusterConfiguration) string {
  29. if cfg.UseHyperKubeImage && image != constants.HyperKube {
  30. klog.Warningf(`WARNING: DEPRECATED use of the "hyperkube" image in place of %q.`+extraHyperKubeNote, image)
  31. image = constants.HyperKube
  32. }
  33. repoPrefix := cfg.GetControlPlaneImageRepository()
  34. kubernetesImageTag := kubeadmutil.KubernetesVersionToImageTag(cfg.KubernetesVersion)
  35. return GetGenericImage(repoPrefix, image, kubernetesImageTag)
  36. }
  37. // GetDNSImage generates and returns the image for the DNS, that can be CoreDNS or kube-dns.
  38. // Given that kube-dns uses 3 containers, an additional imageName parameter was added
  39. func GetDNSImage(cfg *kubeadmapi.ClusterConfiguration, imageName string) string {
  40. // DNS uses default image repository by default
  41. dnsImageRepository := cfg.ImageRepository
  42. // unless an override is specified
  43. if cfg.DNS.ImageRepository != "" {
  44. dnsImageRepository = cfg.DNS.ImageRepository
  45. }
  46. // DNS uses an imageTag that corresponds to the DNS version matching the Kubernetes version
  47. dnsImageTag := constants.GetDNSVersion(cfg.DNS.Type)
  48. // unless an override is specified
  49. if cfg.DNS.ImageTag != "" {
  50. dnsImageTag = cfg.DNS.ImageTag
  51. }
  52. return GetGenericImage(dnsImageRepository, imageName, dnsImageTag)
  53. }
  54. // GetEtcdImage generates and returns the image for etcd
  55. func GetEtcdImage(cfg *kubeadmapi.ClusterConfiguration) string {
  56. // Etcd uses default image repository by default
  57. etcdImageRepository := cfg.ImageRepository
  58. // unless an override is specified
  59. if cfg.Etcd.Local != nil && cfg.Etcd.Local.ImageRepository != "" {
  60. etcdImageRepository = cfg.Etcd.Local.ImageRepository
  61. }
  62. // Etcd uses an imageTag that corresponds to the etcd version matching the Kubernetes version
  63. etcdImageTag := constants.DefaultEtcdVersion
  64. etcdVersion, warning, err := constants.EtcdSupportedVersion(constants.SupportedEtcdVersion, cfg.KubernetesVersion)
  65. if err == nil {
  66. etcdImageTag = etcdVersion.String()
  67. }
  68. if warning != nil {
  69. klog.Warningln(warning)
  70. }
  71. // unless an override is specified
  72. if cfg.Etcd.Local != nil && cfg.Etcd.Local.ImageTag != "" {
  73. etcdImageTag = cfg.Etcd.Local.ImageTag
  74. }
  75. return GetGenericImage(etcdImageRepository, constants.Etcd, etcdImageTag)
  76. }
  77. // GetPauseImage returns the image for the "pause" container
  78. func GetPauseImage(cfg *kubeadmapi.ClusterConfiguration) string {
  79. return GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion)
  80. }
  81. // GetControlPlaneImages returns a list of container images kubeadm expects to use on a control plane node
  82. func GetControlPlaneImages(cfg *kubeadmapi.ClusterConfiguration) []string {
  83. imgs := []string{}
  84. // start with core kubernetes images
  85. if cfg.UseHyperKubeImage {
  86. klog.Warningln(`WARNING: DEPRECATED use of the "hyperkube" image for the Kubernetes control plane.` + extraHyperKubeNote)
  87. imgs = append(imgs, GetKubernetesImage(constants.HyperKube, cfg))
  88. } else {
  89. imgs = append(imgs, GetKubernetesImage(constants.KubeAPIServer, cfg))
  90. imgs = append(imgs, GetKubernetesImage(constants.KubeControllerManager, cfg))
  91. imgs = append(imgs, GetKubernetesImage(constants.KubeScheduler, cfg))
  92. imgs = append(imgs, GetKubernetesImage(constants.KubeProxy, cfg))
  93. }
  94. // pause is not available on the ci image repository so use the default image repository.
  95. imgs = append(imgs, GetPauseImage(cfg))
  96. // if etcd is not external then add the image as it will be required
  97. if cfg.Etcd.Local != nil {
  98. imgs = append(imgs, GetEtcdImage(cfg))
  99. }
  100. // Append the appropriate DNS images
  101. if cfg.DNS.Type == kubeadmapi.CoreDNS {
  102. imgs = append(imgs, GetDNSImage(cfg, constants.CoreDNSImageName))
  103. } else {
  104. imgs = append(imgs, GetDNSImage(cfg, constants.KubeDNSKubeDNSImageName))
  105. imgs = append(imgs, GetDNSImage(cfg, constants.KubeDNSSidecarImageName))
  106. imgs = append(imgs, GetDNSImage(cfg, constants.KubeDNSDnsMasqNannyImageName))
  107. }
  108. return imgs
  109. }