k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kubeadm/app/images/images.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package images 18 19 import ( 20 "fmt" 21 22 "k8s.io/klog/v2" 23 24 kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" 25 kubeadmapiv1beta3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta3" 26 "k8s.io/kubernetes/cmd/kubeadm/app/constants" 27 kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" 28 ) 29 30 // GetGenericImage generates and returns a platform agnostic image (backed by manifest list) 31 func GetGenericImage(prefix, image, tag string) string { 32 return fmt.Sprintf("%s/%s:%s", prefix, image, tag) 33 } 34 35 // GetKubernetesImage generates and returns the image for the components managed in the Kubernetes main repository, 36 // including the control-plane components and kube-proxy. 37 func GetKubernetesImage(image string, cfg *kubeadmapi.ClusterConfiguration) string { 38 repoPrefix := cfg.GetControlPlaneImageRepository() 39 kubernetesImageTag := kubeadmutil.KubernetesVersionToImageTag(cfg.KubernetesVersion) 40 return GetGenericImage(repoPrefix, image, kubernetesImageTag) 41 } 42 43 // GetDNSImage generates and returns the image for CoreDNS. 44 func GetDNSImage(cfg *kubeadmapi.ClusterConfiguration) string { 45 // DNS uses default image repository by default 46 dnsImageRepository := cfg.ImageRepository 47 // unless an override is specified 48 if cfg.DNS.ImageRepository != "" { 49 dnsImageRepository = cfg.DNS.ImageRepository 50 } 51 // Handle the renaming of the official image from "registry.k8s.io/coredns" to "registry.k8s.io/coredns/coredns 52 if dnsImageRepository == kubeadmapiv1beta3.DefaultImageRepository { 53 dnsImageRepository = fmt.Sprintf("%s/coredns", dnsImageRepository) 54 } 55 // DNS uses an imageTag that corresponds to the DNS version matching the Kubernetes version 56 dnsImageTag := constants.CoreDNSVersion 57 58 // unless an override is specified 59 if cfg.DNS.ImageTag != "" { 60 dnsImageTag = cfg.DNS.ImageTag 61 } 62 return GetGenericImage(dnsImageRepository, constants.CoreDNSImageName, dnsImageTag) 63 } 64 65 // GetEtcdImage generates and returns the image for etcd 66 func GetEtcdImage(cfg *kubeadmapi.ClusterConfiguration) string { 67 // Etcd uses default image repository by default 68 etcdImageRepository := cfg.ImageRepository 69 // unless an override is specified 70 if cfg.Etcd.Local != nil && cfg.Etcd.Local.ImageRepository != "" { 71 etcdImageRepository = cfg.Etcd.Local.ImageRepository 72 } 73 // Etcd uses an imageTag that corresponds to the etcd version matching the Kubernetes version 74 etcdImageTag := constants.DefaultEtcdVersion 75 etcdVersion, warning, err := constants.EtcdSupportedVersion(constants.SupportedEtcdVersion, cfg.KubernetesVersion) 76 if err == nil { 77 etcdImageTag = etcdVersion.String() 78 } 79 if warning != nil { 80 klog.V(1).Infof("WARNING: %v", warning) 81 } 82 // unless an override is specified 83 if cfg.Etcd.Local != nil && cfg.Etcd.Local.ImageTag != "" { 84 etcdImageTag = cfg.Etcd.Local.ImageTag 85 } 86 return GetGenericImage(etcdImageRepository, constants.Etcd, etcdImageTag) 87 } 88 89 // GetControlPlaneImages returns a list of container images kubeadm expects to use on a control plane node 90 func GetControlPlaneImages(cfg *kubeadmapi.ClusterConfiguration) []string { 91 images := make([]string, 0) 92 93 // start with core kubernetes images 94 images = append(images, GetKubernetesImage(constants.KubeAPIServer, cfg)) 95 images = append(images, GetKubernetesImage(constants.KubeControllerManager, cfg)) 96 images = append(images, GetKubernetesImage(constants.KubeScheduler, cfg)) 97 98 // if Proxy addon is not disable then add the image 99 if cfg.Proxy.Disabled { 100 klog.V(1).Infof("skipping the kube-proxy image pull since the bundled addon is disabled") 101 } else { 102 images = append(images, GetKubernetesImage(constants.KubeProxy, cfg)) 103 } 104 // if DNS addon is not disable then add the image 105 if cfg.DNS.Disabled { 106 klog.V(1).Infof("skipping the CoreDNS image pull since the bundled addon is disabled") 107 } else { 108 images = append(images, GetDNSImage(cfg)) 109 } 110 111 // pause is not available on the ci image repository so use the default image repository. 112 images = append(images, GetPauseImage(cfg)) 113 114 // if etcd is not external then add the image as it will be required 115 if cfg.Etcd.Local != nil { 116 images = append(images, GetEtcdImage(cfg)) 117 } 118 119 return images 120 } 121 122 // GetPauseImage returns the image for the "pause" container 123 func GetPauseImage(cfg *kubeadmapi.ClusterConfiguration) string { 124 return GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion) 125 }