add router subnet specify option

This commit is contained in:
Jesse Haka 2019-02-18 11:40:10 +02:00
parent ded99c8ab1
commit ae3ad36a28
12 changed files with 64 additions and 0 deletions

View File

@ -151,6 +151,7 @@ type CreateClusterOptions struct {
// OpenstackExternalNet is the name of the external network for the openstack router
OpenstackExternalNet string
OpenstackExternalSubnet string
OpenstackStorageIgnoreAZ bool
OpenstackDNSServers string
OpenstackLbSubnet string
@ -384,6 +385,7 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
if cloudup.AlphaAllowOpenstack.Enabled() {
// Openstack flags
cmd.Flags().StringVar(&options.OpenstackExternalNet, "os-ext-net", options.OpenstackExternalNet, "The name of the external network to use with the openstack router")
cmd.Flags().StringVar(&options.OpenstackExternalSubnet, "os-ext-subnet", options.OpenstackExternalSubnet, "The name of the external floating subnet to use with the openstack router")
cmd.Flags().StringVar(&options.OpenstackLbSubnet, "os-lb-floating-subnet", options.OpenstackLbSubnet, "The name of the external subnet to use with the kubernetes api")
cmd.Flags().BoolVar(&options.OpenstackStorageIgnoreAZ, "os-kubelet-ignore-az", options.OpenstackStorageIgnoreAZ, "If true kubernetes may attach volumes across availability zones")
cmd.Flags().BoolVar(&options.OpenstackLBOctavia, "os-octavia", options.OpenstackLBOctavia, "If true octavia loadbalancer api will be used")
@ -937,6 +939,9 @@ func RunCreateCluster(f *util.Factory, out io.Writer, c *CreateClusterOptions) e
if c.OpenstackDNSServers != "" {
cluster.Spec.CloudConfig.Openstack.Router.DNSServers = fi.String(c.OpenstackDNSServers)
}
if c.OpenstackExternalSubnet != "" {
cluster.Spec.CloudConfig.Openstack.Router.ExternalSubnet = fi.String(c.OpenstackExternalSubnet)
}
if c.OpenstackLbSubnet != "" {
cluster.Spec.CloudConfig.Openstack.Loadbalancer.FloatingSubnet = fi.String(c.OpenstackLbSubnet)
}

View File

@ -530,6 +530,7 @@ type OpenstackMonitor struct {
type OpenstackRouter struct {
ExternalNetwork *string `json:"externalNetwork,omitempty"`
DNSServers *string `json:"dnsServers,omitempty"`
ExternalSubnet *string `json:"externalSubnet,omitempty"`
}
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider

View File

@ -530,6 +530,7 @@ type OpenstackMonitor struct {
type OpenstackRouter struct {
ExternalNetwork *string `json:"externalNetwork,omitempty"`
DNSServers *string `json:"dnsServers,omitempty"`
ExternalSubnet *string `json:"externalSubnet,omitempty"`
}
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider

View File

@ -4103,6 +4103,7 @@ func Convert_kops_OpenstackMonitor_To_v1alpha1_OpenstackMonitor(in *kops.Opensta
func autoConvert_v1alpha1_OpenstackRouter_To_kops_OpenstackRouter(in *OpenstackRouter, out *kops.OpenstackRouter, s conversion.Scope) error {
out.ExternalNetwork = in.ExternalNetwork
out.DNSServers = in.DNSServers
out.ExternalSubnet = in.ExternalSubnet
return nil
}
@ -4114,6 +4115,7 @@ func Convert_v1alpha1_OpenstackRouter_To_kops_OpenstackRouter(in *OpenstackRoute
func autoConvert_kops_OpenstackRouter_To_v1alpha1_OpenstackRouter(in *kops.OpenstackRouter, out *OpenstackRouter, s conversion.Scope) error {
out.ExternalNetwork = in.ExternalNetwork
out.DNSServers = in.DNSServers
out.ExternalSubnet = in.ExternalSubnet
return nil
}

View File

@ -2716,6 +2716,11 @@ func (in *OpenstackRouter) DeepCopyInto(out *OpenstackRouter) {
*out = new(string)
**out = **in
}
if in.ExternalSubnet != nil {
in, out := &in.ExternalSubnet, &out.ExternalSubnet
*out = new(string)
**out = **in
}
return
}

View File

@ -530,6 +530,7 @@ type OpenstackMonitor struct {
type OpenstackRouter struct {
ExternalNetwork *string `json:"externalNetwork,omitempty"`
DNSServers *string `json:"dnsServers,omitempty"`
ExternalSubnet *string `json:"externalSubnet,omitempty"`
}
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider

View File

@ -4373,6 +4373,7 @@ func Convert_kops_OpenstackMonitor_To_v1alpha2_OpenstackMonitor(in *kops.Opensta
func autoConvert_v1alpha2_OpenstackRouter_To_kops_OpenstackRouter(in *OpenstackRouter, out *kops.OpenstackRouter, s conversion.Scope) error {
out.ExternalNetwork = in.ExternalNetwork
out.DNSServers = in.DNSServers
out.ExternalSubnet = in.ExternalSubnet
return nil
}
@ -4384,6 +4385,7 @@ func Convert_v1alpha2_OpenstackRouter_To_kops_OpenstackRouter(in *OpenstackRoute
func autoConvert_kops_OpenstackRouter_To_v1alpha2_OpenstackRouter(in *kops.OpenstackRouter, out *OpenstackRouter, s conversion.Scope) error {
out.ExternalNetwork = in.ExternalNetwork
out.DNSServers = in.DNSServers
out.ExternalSubnet = in.ExternalSubnet
return nil
}

View File

@ -2787,6 +2787,11 @@ func (in *OpenstackRouter) DeepCopyInto(out *OpenstackRouter) {
*out = new(string)
**out = **in
}
if in.ExternalSubnet != nil {
in, out := &in.ExternalSubnet, &out.ExternalSubnet
*out = new(string)
**out = **in
}
return
}

View File

@ -3001,6 +3001,11 @@ func (in *OpenstackRouter) DeepCopyInto(out *OpenstackRouter) {
*out = new(string)
**out = **in
}
if in.ExternalSubnet != nil {
in, out := &in.ExternalSubnet, &out.ExternalSubnet
*out = new(string)
**out = **in
}
return
}

View File

@ -147,6 +147,9 @@ type OpenstackCloud interface {
//ListExternalNetworks will return the Neutron networks with the router:external property
GetExternalNetwork() (*networks.Network, error)
// GetExternalSubnet will return the subnet for floatingip which is used in external router
GetExternalSubnet() (*subnets.Subnet, error)
// GetLBFloatingSubnet will return the subnet for floatingip which is used in lb
GetLBFloatingSubnet() (*subnets.Subnet, error)
@ -273,6 +276,7 @@ type openstackCloud struct {
dnsClient *gophercloud.ServiceClient
lbClient *gophercloud.ServiceClient
extNetworkName *string
extSubnetName *string
floatingSubnet *string
tags map[string]string
region string
@ -376,6 +380,9 @@ func NewOpenstackCloud(tags map[string]string, spec *kops.ClusterSpec) (Openstac
c.extNetworkName = spec.CloudConfig.Openstack.Router.ExternalNetwork
if spec.CloudConfig.Openstack.Router.ExternalSubnet != nil {
c.extSubnetName = spec.CloudConfig.Openstack.Router.ExternalSubnet
}
if spec.CloudConfig.Openstack.Loadbalancer != nil &&
spec.CloudConfig.Openstack.Loadbalancer.FloatingNetworkID == nil &&
spec.CloudConfig.Openstack.Loadbalancer.FloatingNetwork != nil {

View File

@ -87,6 +87,24 @@ func (c *openstackCloud) DeleteSubnet(subnetID string) error {
}
}
func (c *openstackCloud) GetExternalSubnet() (subnet *subnets.Subnet, err error) {
if c.extSubnetName == nil {
return nil, nil
}
subnets, err := c.ListSubnets(subnets.ListOpts{
Name: fi.StringValue(c.extSubnetName),
})
if err != nil {
return nil, err
}
if len(subnets) == 1 {
return &subnets[0], nil
}
return nil, fmt.Errorf("did not find floatingsubnet for external router")
}
func (c *openstackCloud) GetLBFloatingSubnet() (subnet *subnets.Subnet, err error) {
if c.floatingSubnet == nil {
return nil, nil

View File

@ -102,6 +102,18 @@ func (_ *Router) RenderOpenstack(t *openstack.OpenstackAPITarget, a, e, changes
NetworkID: floatingNet.ID,
}
routerFloatingSubnet, err := t.Cloud.GetExternalSubnet()
if err != nil {
return fmt.Errorf("Failed to find floatingip subnet: %v", err)
}
if routerFloatingSubnet != nil {
opt.GatewayInfo.ExternalFixedIPs = []routers.ExternalFixedIP{
{
SubnetID: routerFloatingSubnet.ID,
},
}
}
v, err := t.Cloud.CreateRouter(opt)
if err != nil {
return fmt.Errorf("Error creating router: %v", err)