Allows to configure load balancer start/end IP
parent
d9fe5afa86
commit
377a4746f9
|
@ -18,8 +18,12 @@ package config
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/exit"
|
||||
"k8s.io/minikube/pkg/minikube/out"
|
||||
"k8s.io/minikube/pkg/minikube/service"
|
||||
|
@ -178,6 +182,30 @@ var addonsConfigureCmd = &cobra.Command{
|
|||
out.WarningT("ERROR creating `registry-creds-acr` secret")
|
||||
}
|
||||
|
||||
case "metallb":
|
||||
profile := viper.GetString(config.MachineProfile)
|
||||
cfg, err := config.Load(profile)
|
||||
if err != nil {
|
||||
out.ErrT(out.FatalType, "Failed to load config {{.profile}}", out.V{"profile": profile})
|
||||
}
|
||||
|
||||
validator := func(s string) bool {
|
||||
return net.ParseIP(s) != nil
|
||||
}
|
||||
|
||||
if cfg.KubernetesConfig.LoadBalancerStartIP == "" {
|
||||
cfg.KubernetesConfig.LoadBalancerStartIP = AskForStaticValidatedValue("-- Enter Load Balancer Start IP: ", validator)
|
||||
}
|
||||
|
||||
if cfg.KubernetesConfig.LoadBalancerEndIP == "" {
|
||||
cfg.KubernetesConfig.LoadBalancerEndIP = AskForStaticValidatedValue("-- Enter Load Balancer End IP: ", validator)
|
||||
}
|
||||
|
||||
err = config.SaveProfile(profile, cfg)
|
||||
if err != nil {
|
||||
out.ErrT(out.FatalType, "Failed to save config {{.profile}}", out.V{"profile": profile})
|
||||
}
|
||||
|
||||
default:
|
||||
out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon})
|
||||
return
|
||||
|
|
|
@ -153,3 +153,23 @@ func posString(slice []string, element string) int {
|
|||
func containsString(slice []string, element string) bool {
|
||||
return posString(slice, element) != -1
|
||||
}
|
||||
|
||||
// AskForStaticValidatedValue asks for a single value to enter and check for valid input
|
||||
func AskForStaticValidatedValue(s string, validator func(s string) bool) string {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
for {
|
||||
response := getStaticValue(reader, s)
|
||||
|
||||
// Can't have zero length
|
||||
if len(response) == 0 {
|
||||
out.Err("--Error, please enter a value:")
|
||||
continue
|
||||
}
|
||||
if !validator(response) {
|
||||
out.Err("--Invalid input, please enter a value:")
|
||||
continue
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,8 @@ const (
|
|||
autoUpdate = "auto-update-drivers"
|
||||
hostOnlyNicType = "host-only-nic-type"
|
||||
natNicType = "nat-nic-type"
|
||||
loadBalancerStartIP = "load-balancer-start-ip"
|
||||
loadBalancerEndIP = "load-balancer-end-ip"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -185,6 +187,8 @@ func initKubernetesFlags() {
|
|||
startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
||||
startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
||||
startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
|
||||
startCmd.Flags().String(loadBalancerStartIP, "", "The first Load Balancer IP within a range. This can be used if you want to set up Load Balancer (MetalLB)")
|
||||
startCmd.Flags().String(loadBalancerEndIP, "", "The last Load Balancer IP within a range. This can be used if you want to set up Load Balancer (MetalLB)")
|
||||
}
|
||||
|
||||
// initDriverFlags inits the commandline flags for vm drivers
|
||||
|
@ -824,6 +828,8 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string)
|
|||
ExtraOptions: node.ExtraOptions,
|
||||
ShouldLoadCachedImages: viper.GetBool(cacheImages),
|
||||
EnableDefaultCNI: selectedEnableDefaultCNI,
|
||||
LoadBalancerStartIP: viper.GetString(loadBalancerStartIP),
|
||||
LoadBalancerEndIP: viper.GetString(loadBalancerEndIP),
|
||||
},
|
||||
Nodes: []config.Node{cp},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue