Skip to content

Commit

Permalink
args for vsphere template cluster (#1164)
Browse files Browse the repository at this point in the history
Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
  • Loading branch information
jkremser authored Oct 31, 2023
1 parent a5059fa commit 3afe5d4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
14 changes: 8 additions & 6 deletions cmd/template/cluster/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
flagVSphereControlPlaneIP = "vsphere-control-plane-ip"
flagVSphereServiceLoadBalancerCIDR = "vsphere-service-load-balancer-cidr"
flagVSphereNetworkName = "vsphere-network-name"
flagVSphereSvcLbIpPool = "vsphere-service-lb-pool"
flagVSphereControlPlaneDiskGiB = "vsphere-control-plane-disk-gib"
flagVSphereControlPlaneIpPool = "vsphere-control-plane-ip-pool"
flagVSphereControlPlaneMemoryMiB = "vsphere-control-plane-memory-mib"
Expand Down Expand Up @@ -239,10 +240,11 @@ func (f *flag) Init(cmd *cobra.Command) {
cmd.Flags().IntVar(&f.OpenStack.WorkerReplicas, flagOpenStackWorkerReplicas, 0, "Default worker node pool replicas (OpenStack only).")

// VSphere only
cmd.Flags().StringVar(&f.VSphere.ControlPlane.IP, flagVSphereControlPlaneIP, "", "Control plane IP, leave empty for auto allocation.")
cmd.Flags().StringVar(&f.VSphere.ControlPlane.Ip, flagVSphereControlPlaneIP, "", "Control plane IP, leave empty for auto allocation.")
cmd.Flags().StringVar(&f.VSphere.ServiceLoadBalancerCIDR, flagVSphereServiceLoadBalancerCIDR, "", "CIDR for Service LB for new cluster")
cmd.Flags().StringVar(&f.VSphere.NetworkName, flagVSphereNetworkName, "", "Network name in vcenter that should be used for the new VMs")
cmd.Flags().StringVar(&f.VSphere.ControlPlane.IPPoolName, flagVSphereControlPlaneIpPool, "wc-cp-ips", "Name of `GlobalInClusterIpPool` CR from which the IP for CP is taken")
cmd.Flags().StringVar(&f.VSphere.SvcLbIpPoolName, flagVSphereSvcLbIpPool, "svc-lb-ips", "Name of `GlobalInClusterIpPool` CR from which the IP for Service LB (kubevip) is taken")
cmd.Flags().StringVar(&f.VSphere.ControlPlane.IpPoolName, flagVSphereControlPlaneIpPool, "wc-cp-ips", "Name of `GlobalInClusterIpPool` CR from which the IP for CP is taken")
cmd.Flags().IntVar(&f.VSphere.ControlPlane.DiskGiB, flagVSphereControlPlaneDiskGiB, 50, "Disk size in GiB for control individual plane nodes")
cmd.Flags().IntVar(&f.VSphere.ControlPlane.MemoryMiB, flagVSphereControlPlaneMemoryMiB, 8096, "Memory size in MiB for individual control plane nodes")
cmd.Flags().IntVar(&f.VSphere.ControlPlane.NumCPUs, flagVSphereControlPlaneNumCPUs, 4, "Number of CPUs for individual control plane nodes")
Expand Down Expand Up @@ -430,16 +432,16 @@ func (f *flag) Validate(cmd *cobra.Command) error {
return microerror.Maskf(invalidFlagError, "--%s supports one availability zone only", flagControlPlaneAZ)
}
case key.ProviderVSphere:
if f.VSphere.ServiceLoadBalancerCIDR == "" {
return microerror.Maskf(invalidFlagError, "CIDR range from which the public IPs for Services of type LoadBalancer are taken (required) (--%s)", flagVSphereServiceLoadBalancerCIDR)
if f.VSphere.NetworkName == "" {
return microerror.Maskf(invalidFlagError, "Provide the network name in vcenter (required) (--%s)", flagVSphereNetworkName)
}
if !validateCIDR(f.VSphere.ServiceLoadBalancerCIDR) {
if f.VSphere.ServiceLoadBalancerCIDR != "" && !validateCIDR(f.VSphere.ServiceLoadBalancerCIDR) {
return microerror.Maskf(invalidFlagError, "--%s must be a valid CIDR", flagVSphereServiceLoadBalancerCIDR)
}
if !cmd.Flags().Changed(flagKubernetesVersion) {
f.KubernetesVersion = defaultVSphereKubernetesVersion
}
// todo: add validation for flagVSphereImageTemplate

placeholders := strings.Count(f.VSphere.ImageTemplate, "%s")
if placeholders > 1 {
return microerror.Maskf(invalidFlagError, "--%s must contain at most one occurrence of '%%s' where k8s version will be injected", flagVSphereImageTemplate)
Expand Down
14 changes: 8 additions & 6 deletions cmd/template/cluster/provider/capv.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func templateClusterVSphere(ctx context.Context, k8sClient k8sclient.Interface,

func BuildCapvClusterConfig(config ClusterConfig) capv.ClusterConfig {
const className = "default"
return capv.ClusterConfig{
cfg := capv.ClusterConfig{
BaseDomain: "test.gigantic.io",
ClusterDescription: config.Description,
Organization: config.Organization,
Expand All @@ -126,14 +126,12 @@ func BuildCapvClusterConfig(config ClusterConfig) capv.ClusterConfig {
Network: &capv.Network{
AllowAllEgress: true,
ControlPlaneEndpoint: &capv.ControlPlaneEndpoint{
Host: config.VSphere.ControlPlane.IP,
IpPoolName: config.VSphere.ControlPlane.IPPoolName,
Host: config.VSphere.ControlPlane.Ip,
IpPoolName: config.VSphere.ControlPlane.IpPoolName,
Port: 6443,
},
LoadBalancers: &capv.LoadBalancers{
CidrBlocks: []string{
config.VSphere.ServiceLoadBalancerCIDR,
},
IpPoolName: config.VSphere.SvcLbIpPoolName,
},
},
},
Expand Down Expand Up @@ -165,6 +163,10 @@ func BuildCapvClusterConfig(config ClusterConfig) capv.ClusterConfig {
},
},
}
if config.VSphere.ServiceLoadBalancerCIDR != "" {
cfg.Connectivity.Network.LoadBalancers.CidrBlocks = []string{config.VSphere.ServiceLoadBalancerCIDR}
}
return cfg
}

func getMachineTemplate(machineTemplate *VSphereMachineTemplate, clusterConfig *ClusterConfig) *capv.MachineTemplate {
Expand Down
5 changes: 3 additions & 2 deletions cmd/template/cluster/provider/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type VSphereConfig struct {
Worker VSphereMachineTemplate
ResourcePool string
ServiceLoadBalancerCIDR string
SvcLbIpPoolName string
}

type VSphereMachineTemplate struct {
Expand All @@ -80,8 +81,8 @@ type VSphereMachineTemplate struct {
}

type VSphereControlPlane struct {
IP string
IPPoolName string
Ip string
IpPoolName string
VSphereMachineTemplate
}

Expand Down
1 change: 1 addition & 0 deletions cmd/template/cluster/provider/templates/capv/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ControlPlaneEndpoint struct {

type LoadBalancers struct {
CidrBlocks []string `json:"cidrBlocks,omitempty"`
IpPoolName string `json:"ipPoolName,omitempty"`
}

type ControlPlane struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/template/cluster/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func Test_run(t *testing.T) {
ServiceLoadBalancerCIDR: "1.2.3.4/32",
ResourcePool: "foopool",
NetworkName: "foonet",
SvcLbIpPoolName: "svc-foo-pool",
CredentialsSecretName: "foosecret",
ImageTemplate: "foobar",
ControlPlane: provider.VSphereControlPlane{
Expand All @@ -228,7 +229,7 @@ func Test_run(t *testing.T) {
NumCPUs: 6,
Replicas: 5,
},
IPPoolName: "foo-pool",
IpPoolName: "foo-pool",
},
Worker: provider.VSphereMachineTemplate{
DiskGiB: 43,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data:
loadBalancers:
cidrBlocks:
- 1.2.3.4/32
ipPoolName: svc-foo-pool
controlPlane:
image:
repository: registry.k8s.io
Expand Down

0 comments on commit 3afe5d4

Please sign in to comment.