mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Extract Method for kubeadm
Signed-off-by: PingWang <wang.ping5@zte.com.cn>
This commit is contained in:
parent
90e9f29bad
commit
38fe68658d
@ -404,29 +404,18 @@ func GetAPIServerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames
|
|||||||
// `advertise address` and localhost are included in the SAN since this is the interfaces the etcd static pod listens on.
|
// `advertise address` and localhost are included in the SAN since this is the interfaces the etcd static pod listens on.
|
||||||
// The user can override the listen address with `Etcd.ExtraArgs` and add SANs with `Etcd.ServerCertSANs`.
|
// The user can override the listen address with `Etcd.ExtraArgs` and add SANs with `Etcd.ServerCertSANs`.
|
||||||
func GetEtcdAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) {
|
func GetEtcdAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) {
|
||||||
// advertise address
|
return getAltNames(cfg, kubeadmconstants.EtcdServerCertName)
|
||||||
advertiseAddress := net.ParseIP(cfg.LocalAPIEndpoint.AdvertiseAddress)
|
|
||||||
if advertiseAddress == nil {
|
|
||||||
return nil, errors.Errorf("error parsing LocalAPIEndpoint AdvertiseAddress %q: is not a valid textual representation of an IP address", cfg.LocalAPIEndpoint.AdvertiseAddress)
|
|
||||||
}
|
|
||||||
|
|
||||||
// create AltNames with defaults DNSNames/IPs
|
|
||||||
altNames := &certutil.AltNames{
|
|
||||||
DNSNames: []string{cfg.NodeRegistration.Name, "localhost"},
|
|
||||||
IPs: []net.IP{advertiseAddress, net.IPv4(127, 0, 0, 1), net.IPv6loopback},
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.Etcd.Local != nil {
|
|
||||||
appendSANsToAltNames(altNames, cfg.Etcd.Local.ServerCertSANs, kubeadmconstants.EtcdServerCertName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return altNames, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetEtcdPeerAltNames builds an AltNames object for generating the etcd peer certificate.
|
// GetEtcdPeerAltNames builds an AltNames object for generating the etcd peer certificate.
|
||||||
// Hostname and `API.AdvertiseAddress` are included if the user chooses to promote the single node etcd cluster into a multi-node one (stacked etcd).
|
// Hostname and `API.AdvertiseAddress` are included if the user chooses to promote the single node etcd cluster into a multi-node one (stacked etcd).
|
||||||
// The user can override the listen address with `Etcd.ExtraArgs` and add SANs with `Etcd.PeerCertSANs`.
|
// The user can override the listen address with `Etcd.ExtraArgs` and add SANs with `Etcd.PeerCertSANs`.
|
||||||
func GetEtcdPeerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) {
|
func GetEtcdPeerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames, error) {
|
||||||
|
return getAltNames(cfg, kubeadmconstants.EtcdPeerCertName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// getAltNames builds an AltNames object with the cfg and certName.
|
||||||
|
func getAltNames(cfg *kubeadmapi.InitConfiguration, certName string) (*certutil.AltNames, error) {
|
||||||
// advertise address
|
// advertise address
|
||||||
advertiseAddress := net.ParseIP(cfg.LocalAPIEndpoint.AdvertiseAddress)
|
advertiseAddress := net.ParseIP(cfg.LocalAPIEndpoint.AdvertiseAddress)
|
||||||
if advertiseAddress == nil {
|
if advertiseAddress == nil {
|
||||||
@ -441,9 +430,12 @@ func GetEtcdPeerAltNames(cfg *kubeadmapi.InitConfiguration) (*certutil.AltNames,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Etcd.Local != nil {
|
if cfg.Etcd.Local != nil {
|
||||||
appendSANsToAltNames(altNames, cfg.Etcd.Local.PeerCertSANs, kubeadmconstants.EtcdPeerCertName)
|
if certName == kubeadmconstants.EtcdServerCertName {
|
||||||
|
appendSANsToAltNames(altNames, cfg.Etcd.Local.ServerCertSANs, kubeadmconstants.EtcdServerCertName)
|
||||||
|
} else if certName == kubeadmconstants.EtcdPeerCertName {
|
||||||
|
appendSANsToAltNames(altNames, cfg.Etcd.Local.PeerCertSANs, kubeadmconstants.EtcdPeerCertName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return altNames, nil
|
return altNames, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user