mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Add validation of apiserver-advertise-address
This commit is contained in:
parent
6a7656b693
commit
a0acc28b62
@ -144,7 +144,7 @@ func getAddonsSubCommands() []*cobra.Command {
|
|||||||
cmd.Flags().StringVar(&cfg.ImageRepository, "image-repository", cfg.ImageRepository, `Choose a container registry to pull control plane images from`)
|
cmd.Flags().StringVar(&cfg.ImageRepository, "image-repository", cfg.ImageRepository, `Choose a container registry to pull control plane images from`)
|
||||||
|
|
||||||
if properties.use == "all" || properties.use == "kube-proxy" {
|
if properties.use == "all" || properties.use == "kube-proxy" {
|
||||||
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, `The IP address or DNS name the API server is accessible on`)
|
cmd.Flags().StringVar(&cfg.API.AdvertiseAddress, "apiserver-advertise-address", cfg.API.AdvertiseAddress, `The IP address the API server is accessible on`)
|
||||||
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, `The port the API server is accessible on`)
|
cmd.Flags().Int32Var(&cfg.API.BindPort, "apiserver-bind-port", cfg.API.BindPort, `The port the API server is accessible on`)
|
||||||
cmd.Flags().StringVar(&cfg.Networking.PodSubnet, "pod-network-cidr", cfg.Networking.PodSubnet, `The range of IP addresses used for the Pod network`)
|
cmd.Flags().StringVar(&cfg.Networking.PodSubnet, "pod-network-cidr", cfg.Networking.PodSubnet, `The range of IP addresses used for the Pod network`)
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,14 @@ import (
|
|||||||
// SetInitDynamicDefaults checks and sets configuration values for Master node
|
// SetInitDynamicDefaults checks and sets configuration values for Master node
|
||||||
func SetInitDynamicDefaults(cfg *kubeadmapi.MasterConfiguration) error {
|
func SetInitDynamicDefaults(cfg *kubeadmapi.MasterConfiguration) error {
|
||||||
|
|
||||||
|
// validate cfg.API.AdvertiseAddress.
|
||||||
|
addressIP := net.ParseIP(cfg.API.AdvertiseAddress)
|
||||||
|
if addressIP == nil && cfg.API.AdvertiseAddress != "" {
|
||||||
|
return fmt.Errorf("couldn't use \"%s\" as \"apiserver-advertise-address\", must be ipv4 or ipv6 address", cfg.API.AdvertiseAddress)
|
||||||
|
}
|
||||||
// Choose the right address for the API Server to advertise. If the advertise address is localhost or 0.0.0.0, the default interface's IP address is used
|
// Choose the right address for the API Server to advertise. If the advertise address is localhost or 0.0.0.0, the default interface's IP address is used
|
||||||
// This is the same logic as the API Server uses
|
// This is the same logic as the API Server uses
|
||||||
ip, err := netutil.ChooseBindAddress(net.ParseIP(cfg.API.AdvertiseAddress))
|
ip, err := netutil.ChooseBindAddress(addressIP)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user