Merge pull request #2550 from wuyingjun-lucky/m_test
introduce karmada-apiserver-advertise-address
This commit is contained in:
commit
6941012e9e
|
@ -47,6 +47,9 @@ var (
|
|||
# Private registry can be specified for all images
|
||||
%[1]s init --etcd-image local.registry.com/library/etcd:3.5.3-0
|
||||
|
||||
# Specify Karmada API Server IP address. If not set, the address on the master node will be used.
|
||||
%[1]s init --karmada-apiserver-advertise-address 192.168.1.2
|
||||
|
||||
# Deploy highly available(HA) karmada
|
||||
%[1]s init --karmada-apiserver-replicas 3 --etcd-replicas 3 --etcd-storage-mode PVC --storage-classes-name {StorageClassesName}
|
||||
|
||||
|
@ -115,6 +118,7 @@ func NewCmdInit(parentCommand string) *cobra.Command {
|
|||
// karmada
|
||||
crdURL := fmt.Sprintf("https://github.com/karmada-io/karmada/releases/download/%s/crds.tar.gz", releaseVer.FirstMinorRelease())
|
||||
flags.StringVar(&opts.CRDs, "crds", crdURL, "Karmada crds resource.(local file e.g. --crds /root/crds.tar.gz)")
|
||||
flags.StringVarP(&opts.KarmadaAPIServerAdvertiseAddress, "karmada-apiserver-advertise-address", "", "", "The IP address the Karmada API Server will advertise it's listening on. If not set, the address on the master node will be used.")
|
||||
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.KarmadaPkiPath, "karmada-pki", "", "/etc/karmada/pki", "Karmada pki path. Karmada cert files")
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"k8s.io/client-go/tools/clientcmd"
|
||||
certutil "k8s.io/client-go/util/cert"
|
||||
"k8s.io/klog/v2"
|
||||
netutils "k8s.io/utils/net"
|
||||
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/cert"
|
||||
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/karmada"
|
||||
|
@ -68,6 +69,7 @@ type CommandInitOption struct {
|
|||
EtcdPersistentVolumeSize string
|
||||
KarmadaAPIServerImage string
|
||||
KarmadaAPIServerReplicas int32
|
||||
KarmadaAPIServerAdvertiseAddress string
|
||||
KarmadaAPIServerNodePort int32
|
||||
KarmadaSchedulerImage string
|
||||
KarmadaSchedulerReplicas int32
|
||||
|
@ -96,6 +98,12 @@ type CommandInitOption struct {
|
|||
|
||||
// Validate Check that there are enough flags to run the command.
|
||||
func (i *CommandInitOption) Validate(parentCommand string) error {
|
||||
if i.KarmadaAPIServerAdvertiseAddress != "" {
|
||||
if netutils.ParseIPSloppy(i.KarmadaAPIServerAdvertiseAddress) == nil {
|
||||
return fmt.Errorf("karmada apiserver advertise address is not valid")
|
||||
}
|
||||
}
|
||||
|
||||
if i.EtcdStorageMode == etcdStorageModeHostPath && i.EtcdHostDataPath == "" {
|
||||
return fmt.Errorf("when etcd storage mode is hostPath, dataPath is not empty. See '%s init --help'", parentCommand)
|
||||
}
|
||||
|
@ -159,7 +167,7 @@ func (i *CommandInitOption) Complete() error {
|
|||
}
|
||||
}
|
||||
|
||||
if err := i.getKubeMasterIP(); err != nil {
|
||||
if err := i.getKarmadaAPIServerIP(); err != nil {
|
||||
return err
|
||||
}
|
||||
klog.Infof("karmada apiserver ip: %s", i.KarmadaAPIServerIP)
|
||||
|
|
|
@ -19,7 +19,12 @@ var (
|
|||
etcdSelectorLabels map[string]string
|
||||
)
|
||||
|
||||
func (i *CommandInitOption) getKubeMasterIP() error {
|
||||
func (i *CommandInitOption) getKarmadaAPIServerIP() error {
|
||||
if i.KarmadaAPIServerAdvertiseAddress != "" {
|
||||
i.KarmadaAPIServerIP = append(i.KarmadaAPIServerIP, utils.StringToNetIP(i.KarmadaAPIServerAdvertiseAddress))
|
||||
return nil
|
||||
}
|
||||
|
||||
nodeClient := i.KubeClientSet.CoreV1().Nodes()
|
||||
masterNodes, err := nodeClient.List(context.TODO(), metav1.ListOptions{LabelSelector: "node-role.kubernetes.io/master"})
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue