Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce --kube-image-mirror-country and kube-image-registry to karmadactl init #1764

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pkg/karmadactl/cmdinit/cmdinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func NewCmdInit(cmdOut io.Writer, parentCommand string) *cobra.Command {
klog.Infof("No default release version found. build version: %s", version.Get().String())
releaseVer = &version.ReleaseVersion{} // initialize to avoid panic
}

// kube image registry
flags.StringVarP(&opts.KubeImageMirrorCountry, "kube-image-mirror-country", "", "", "Country code of the kube image registry to be used. For Chinese mainland users, set it to cn")
flags.StringVarP(&opts.KubeImageRegistry, "kube-image-registry", "", "", "Kube image registry. For Chinese mainland users, you may use local gcr.io mirrors such as registry.cn-hangzhou.aliyuncs.com/google_containers to override default kube image registry")
// cert
flags.StringVar(&opts.ExternalIP, "cert-external-ip", "", "the external IP of Karmada certificate (e.g 192.168.1.2,172.16.1.2)")
flags.StringVar(&opts.ExternalDNS, "cert-external-dns", "", "the external DNS of Karmada certificate (e.g localhost,localhost.com)")
Expand All @@ -57,7 +59,7 @@ func NewCmdInit(cmdOut io.Writer, parentCommand string) *cobra.Command {
// etcd
flags.StringVarP(&opts.EtcdStorageMode, "etcd-storage-mode", "", "emptyDir",
"etcd data storage mode(emptyDir,hostPath,PVC). value is PVC, specify --storage-classes-name")
flags.StringVarP(&opts.EtcdImage, "etcd-image", "", "k8s.gcr.io/etcd:3.5.1-0", "etcd image")
flags.StringVarP(&opts.EtcdImage, "etcd-image", "", "", "etcd image")
flags.StringVarP(&opts.EtcdInitImage, "etcd-init-image", "", "docker.io/alpine:3.15.1", "etcd init container image")
flags.Int32VarP(&opts.EtcdReplicas, "etcd-replicas", "", 1, "etcd replica set, cluster 3,5...singular")
flags.StringVarP(&opts.EtcdHostDataPath, "etcd-data", "", "/var/lib/karmada-etcd", "etcd data path,valid in hostPath mode.")
Expand All @@ -68,11 +70,11 @@ func NewCmdInit(cmdOut io.Writer, parentCommand string) *cobra.Command {
flags.StringVar(&opts.CRDs, "crds", crdURL, "Karmada crds resource.(local file e.g. --crds /root/crds.tar.gz)")
flags.Int32VarP(&opts.KarmadaAPIServerNodePort, "port", "p", 32443, "Karmada apiserver service node port")
flags.StringVarP(&opts.KarmadaDataPath, "karmada-data", "d", "/etc/karmada", "karmada data path. kubeconfig cert and crds files")
flags.StringVarP(&opts.KarmadaAPIServerImage, "karmada-apiserver-image", "", "k8s.gcr.io/kube-apiserver:v1.21.7", "Kubernetes apiserver image")
flags.StringVarP(&opts.KarmadaAPIServerImage, "karmada-apiserver-image", "", "", "Kubernetes apiserver image")
flags.Int32VarP(&opts.KarmadaAPIServerReplicas, "karmada-apiserver-replicas", "", 1, "karmada apiserver replica set")
flags.StringVarP(&opts.KarmadaSchedulerImage, "karmada-scheduler-image", "", fmt.Sprintf("swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-scheduler:%s", releaseVer.PatchRelease()), "karmada scheduler image")
flags.Int32VarP(&opts.KarmadaSchedulerReplicas, "karmada-scheduler-replicas", "", 1, "karmada scheduler replica set")
flags.StringVarP(&opts.KubeControllerManagerImage, "karmada-kube-controller-manager-image", "", "k8s.gcr.io/kube-controller-manager:v1.21.7", "Kubernetes controller manager image")
flags.StringVarP(&opts.KubeControllerManagerImage, "karmada-kube-controller-manager-image", "", "", "Kubernetes controller manager image")
flags.Int32VarP(&opts.KubeControllerManagerReplicas, "karmada-kube-controller-manager-replicas", "", 1, "karmada kube controller manager replica set")
flags.StringVarP(&opts.KarmadaControllerManagerImage, "karmada-controller-manager-image", "", fmt.Sprintf("swr.ap-southeast-1.myhuaweicloud.com/karmada/karmada-controller-manager:%s", releaseVer.PatchRelease()), "karmada controller manager image")
flags.Int32VarP(&opts.KarmadaControllerManagerReplicas, "karmada-controller-manager-replicas", "", 1, "karmada controller manager replica set")
Expand All @@ -90,6 +92,12 @@ func initExample(parentCommand string) string {
# The karmada-apiserver binds the master node's IP by default` + "\n" +
fmt.Sprintf("%s init", parentCommand) + `

# China mainland registry mirror can be specified by using kube-image-mirror-country` + "\n" +
fmt.Sprintf("%s init --kube-image-mirror-country=cn", parentCommand) + `

# Kube registry can be specified by using kube-image-registry` + "\n" +
fmt.Sprintf("%s init --kube-image-registry=registry.cn-hangzhou.aliyuncs.com/google_containers", parentCommand) + `

# Specify the URL to download CRD tarball` + "\n" +
fmt.Sprintf("%s init --crds https://github.com/karmada-io/karmada/releases/download/v1.1.0/crds.tar.gz", parentCommand) + `

Expand Down
74 changes: 65 additions & 9 deletions pkg/karmadactl/cmdinit/kubernetes/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,32 @@ import (
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/utils"
)

var certList = []string{
options.CaCertAndKeyName,
options.EtcdServerCertAndKeyName,
options.EtcdClientCertAndKeyName,
options.KarmadaCertAndKeyName,
options.FrontProxyCaCertAndKeyName,
options.FrontProxyClientCertAndKeyName,
}
var (
imageRepositories = map[string]string{
"global": "k8s.gcr.io",
"cn": "registry.cn-hangzhou.aliyuncs.com/google_containers",
}

certList = []string{
options.CaCertAndKeyName,
options.EtcdServerCertAndKeyName,
options.EtcdClientCertAndKeyName,
options.KarmadaCertAndKeyName,
options.FrontProxyCaCertAndKeyName,
options.FrontProxyClientCertAndKeyName,
}

defaultKubeConfig = filepath.Join(homeDir(), ".kube", "config")

var defaultKubeConfig = filepath.Join(homeDir(), ".kube", "config")
defaultEtcdImage = "etcd:3.5.1-0"
defaultKubeAPIServerImage = "kube-apiserver:v1.21.7"
defaultKubeControllerManagerImage = "kube-controller-manager:v1.21.7"
)

// CommandInitOption holds all flags options for init.
type CommandInitOption struct {
KubeImageRegistry string
KubeImageMirrorCountry string
EtcdImage string
EtcdReplicas int32
EtcdInitImage string
Expand Down Expand Up @@ -448,6 +461,49 @@ func (i *CommandInitOption) RunInit(_ io.Writer, parentCommand string) error {
return nil
}

// get kube components registry
func (i *CommandInitOption) kubeRegistry() string {
registry := i.KubeImageRegistry
mirrorCountry := strings.ToLower(i.KubeImageMirrorCountry)

if registry != "" {
return registry
}

if mirrorCountry != "" {
value, ok := imageRepositories[mirrorCountry]
if ok {
return value
}
}

return imageRepositories["global"]
}

// get kube-apiserver image
func (i *CommandInitOption) kubeAPIServerImage() string {
if i.KarmadaAPIServerImage != "" {
return i.KarmadaAPIServerImage
}
return i.kubeRegistry() + "/" + defaultKubeAPIServerImage
}

// get kube-controller-manager image
func (i *CommandInitOption) kubeControllerManagerImage() string {
if i.KubeControllerManagerImage != "" {
return i.KubeControllerManagerImage
}
return i.kubeRegistry() + "/" + defaultKubeControllerManagerImage
}

// get etcd image
func (i *CommandInitOption) etcdImage() string {
if i.EtcdImage != "" {
return i.EtcdImage
}
return i.kubeRegistry() + "/" + defaultEtcdImage
}

func homeDir() string {
if h := os.Getenv("HOME"); h != "" {
return h
Expand Down
4 changes: 2 additions & 2 deletions pkg/karmadactl/cmdinit/kubernetes/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (i *CommandInitOption) makeKarmadaAPIServerDeployment() *appsv1.Deployment
Containers: []corev1.Container{
{
Name: karmadaAPIServerDeploymentAndServiceName,
Image: i.KarmadaAPIServerImage,
Image: i.kubeAPIServerImage(),
Command: i.karmadaAPIServerContainerCommand(),
Ports: []corev1.ContainerPort{
{
Expand Down Expand Up @@ -255,7 +255,7 @@ func (i *CommandInitOption) makeKarmadaKubeControllerManagerDeployment() *appsv1
Containers: []corev1.Container{
{
Name: kubeControllerManagerClusterRoleAndDeploymentAndServiceName,
Image: i.KubeControllerManagerImage,
Image: i.kubeControllerManagerImage(),
Command: []string{
"kube-controller-manager",
"--allocate-node-cidrs=true",
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/cmdinit/kubernetes/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (i *CommandInitOption) makeETCDStatefulSet() *appsv1.StatefulSet {
Containers: []corev1.Container{
{
Name: etcdStatefulSetAndServiceName,
Image: i.EtcdImage,
Image: i.etcdImage(),
Command: []string{
"/usr/local/bin/etcd",
fmt.Sprintf("--config-file=%s/%s", etcdContainerConfigDataMountPath, etcdConfigName),
Expand Down