-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.go
90 lines (74 loc) · 3.4 KB
/
images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package images
import (
"fmt"
"k8s.io/klog/v2"
kubeadmapi "github.com/carlory/firefly/pkg/adm/apis/kubeadm"
"github.com/carlory/firefly/pkg/adm/constants"
kubeadmutil "github.com/carlory/firefly/pkg/adm/util"
)
// GetGenericImage generates and returns a platform agnostic image (backed by manifest list)
func GetGenericImage(prefix, image, tag string) string {
return fmt.Sprintf("%s/%s:%s", prefix, image, tag)
}
// GetKubernetesImage generates and returns the image for the components managed in the Kubernetes main repository,
// including the control-plane components and kube-proxy.
func GetKubernetesImage(image string, cfg *kubeadmapi.ClusterConfiguration) string {
repoPrefix := cfg.GetControlPlaneImageRepository()
kubernetesImageTag := kubeadmutil.KubernetesVersionToImageTag(cfg.KubernetesVersion)
return GetGenericImage(repoPrefix, image, kubernetesImageTag)
}
// GetEtcdImage generates and returns the image for etcd
func GetEtcdImage(cfg *kubeadmapi.ClusterConfiguration) string {
// Etcd uses default image repository by default
etcdImageRepository := cfg.ImageRepository
// unless an override is specified
if cfg.Etcd.Local != nil && cfg.Etcd.Local.ImageRepository != "" {
etcdImageRepository = cfg.Etcd.Local.ImageRepository
}
// Etcd uses an imageTag that corresponds to the etcd version matching the Kubernetes version
etcdImageTag := constants.DefaultEtcdVersion
etcdVersion, warning, err := constants.EtcdSupportedVersion(constants.SupportedEtcdVersion, cfg.KubernetesVersion)
if err == nil {
etcdImageTag = etcdVersion.String()
}
if warning != nil {
klog.Warningln(warning)
}
// unless an override is specified
if cfg.Etcd.Local != nil && cfg.Etcd.Local.ImageTag != "" {
etcdImageTag = cfg.Etcd.Local.ImageTag
}
return GetGenericImage(etcdImageRepository, constants.Etcd, etcdImageTag)
}
// GetControlPlaneImages returns a list of container images kubeadm expects to use on a control plane node
func GetControlPlaneImages(cfg *kubeadmapi.ClusterConfiguration) []string {
images := make([]string, 0)
// start with core kubernetes images
images = append(images, GetKubernetesImage(constants.KubeAPIServer, cfg))
images = append(images, GetKubernetesImage(constants.KubeControllerManager, cfg))
images = append(images, GetKubernetesImage(constants.KubeScheduler, cfg))
images = append(images, GetKubernetesImage(constants.KubeProxy, cfg))
// pause is not available on the ci image repository so use the default image repository.
images = append(images, GetPauseImage(cfg))
// if etcd is not external then add the image as it will be required
if cfg.Etcd.Local != nil {
images = append(images, GetEtcdImage(cfg))
}
return images
}
// GetPauseImage returns the image for the "pause" container
func GetPauseImage(cfg *kubeadmapi.ClusterConfiguration) string {
return GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion)
}