mirror of https://github.com/kubernetes/kops.git
add router subnet specify option
This commit is contained in:
parent
ded99c8ab1
commit
ae3ad36a28
|
@ -151,6 +151,7 @@ type CreateClusterOptions struct {
|
||||||
|
|
||||||
// OpenstackExternalNet is the name of the external network for the openstack router
|
// OpenstackExternalNet is the name of the external network for the openstack router
|
||||||
OpenstackExternalNet string
|
OpenstackExternalNet string
|
||||||
|
OpenstackExternalSubnet string
|
||||||
OpenstackStorageIgnoreAZ bool
|
OpenstackStorageIgnoreAZ bool
|
||||||
OpenstackDNSServers string
|
OpenstackDNSServers string
|
||||||
OpenstackLbSubnet string
|
OpenstackLbSubnet string
|
||||||
|
@ -384,6 +385,7 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
||||||
if cloudup.AlphaAllowOpenstack.Enabled() {
|
if cloudup.AlphaAllowOpenstack.Enabled() {
|
||||||
// Openstack flags
|
// 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.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().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.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")
|
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 != "" {
|
if c.OpenstackDNSServers != "" {
|
||||||
cluster.Spec.CloudConfig.Openstack.Router.DNSServers = fi.String(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 != "" {
|
if c.OpenstackLbSubnet != "" {
|
||||||
cluster.Spec.CloudConfig.Openstack.Loadbalancer.FloatingSubnet = fi.String(c.OpenstackLbSubnet)
|
cluster.Spec.CloudConfig.Openstack.Loadbalancer.FloatingSubnet = fi.String(c.OpenstackLbSubnet)
|
||||||
}
|
}
|
||||||
|
|
|
@ -530,6 +530,7 @@ type OpenstackMonitor struct {
|
||||||
type OpenstackRouter struct {
|
type OpenstackRouter struct {
|
||||||
ExternalNetwork *string `json:"externalNetwork,omitempty"`
|
ExternalNetwork *string `json:"externalNetwork,omitempty"`
|
||||||
DNSServers *string `json:"dnsServers,omitempty"`
|
DNSServers *string `json:"dnsServers,omitempty"`
|
||||||
|
ExternalSubnet *string `json:"externalSubnet,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider
|
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider
|
||||||
|
|
|
@ -530,6 +530,7 @@ type OpenstackMonitor struct {
|
||||||
type OpenstackRouter struct {
|
type OpenstackRouter struct {
|
||||||
ExternalNetwork *string `json:"externalNetwork,omitempty"`
|
ExternalNetwork *string `json:"externalNetwork,omitempty"`
|
||||||
DNSServers *string `json:"dnsServers,omitempty"`
|
DNSServers *string `json:"dnsServers,omitempty"`
|
||||||
|
ExternalSubnet *string `json:"externalSubnet,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider
|
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider
|
||||||
|
|
|
@ -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 {
|
func autoConvert_v1alpha1_OpenstackRouter_To_kops_OpenstackRouter(in *OpenstackRouter, out *kops.OpenstackRouter, s conversion.Scope) error {
|
||||||
out.ExternalNetwork = in.ExternalNetwork
|
out.ExternalNetwork = in.ExternalNetwork
|
||||||
out.DNSServers = in.DNSServers
|
out.DNSServers = in.DNSServers
|
||||||
|
out.ExternalSubnet = in.ExternalSubnet
|
||||||
return nil
|
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 {
|
func autoConvert_kops_OpenstackRouter_To_v1alpha1_OpenstackRouter(in *kops.OpenstackRouter, out *OpenstackRouter, s conversion.Scope) error {
|
||||||
out.ExternalNetwork = in.ExternalNetwork
|
out.ExternalNetwork = in.ExternalNetwork
|
||||||
out.DNSServers = in.DNSServers
|
out.DNSServers = in.DNSServers
|
||||||
|
out.ExternalSubnet = in.ExternalSubnet
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2716,6 +2716,11 @@ func (in *OpenstackRouter) DeepCopyInto(out *OpenstackRouter) {
|
||||||
*out = new(string)
|
*out = new(string)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
|
if in.ExternalSubnet != nil {
|
||||||
|
in, out := &in.ExternalSubnet, &out.ExternalSubnet
|
||||||
|
*out = new(string)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -530,6 +530,7 @@ type OpenstackMonitor struct {
|
||||||
type OpenstackRouter struct {
|
type OpenstackRouter struct {
|
||||||
ExternalNetwork *string `json:"externalNetwork,omitempty"`
|
ExternalNetwork *string `json:"externalNetwork,omitempty"`
|
||||||
DNSServers *string `json:"dnsServers,omitempty"`
|
DNSServers *string `json:"dnsServers,omitempty"`
|
||||||
|
ExternalSubnet *string `json:"externalSubnet,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider
|
// OpenstackConfiguration defines cloud config elements for the openstack cloud provider
|
||||||
|
|
|
@ -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 {
|
func autoConvert_v1alpha2_OpenstackRouter_To_kops_OpenstackRouter(in *OpenstackRouter, out *kops.OpenstackRouter, s conversion.Scope) error {
|
||||||
out.ExternalNetwork = in.ExternalNetwork
|
out.ExternalNetwork = in.ExternalNetwork
|
||||||
out.DNSServers = in.DNSServers
|
out.DNSServers = in.DNSServers
|
||||||
|
out.ExternalSubnet = in.ExternalSubnet
|
||||||
return nil
|
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 {
|
func autoConvert_kops_OpenstackRouter_To_v1alpha2_OpenstackRouter(in *kops.OpenstackRouter, out *OpenstackRouter, s conversion.Scope) error {
|
||||||
out.ExternalNetwork = in.ExternalNetwork
|
out.ExternalNetwork = in.ExternalNetwork
|
||||||
out.DNSServers = in.DNSServers
|
out.DNSServers = in.DNSServers
|
||||||
|
out.ExternalSubnet = in.ExternalSubnet
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2787,6 +2787,11 @@ func (in *OpenstackRouter) DeepCopyInto(out *OpenstackRouter) {
|
||||||
*out = new(string)
|
*out = new(string)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
|
if in.ExternalSubnet != nil {
|
||||||
|
in, out := &in.ExternalSubnet, &out.ExternalSubnet
|
||||||
|
*out = new(string)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3001,6 +3001,11 @@ func (in *OpenstackRouter) DeepCopyInto(out *OpenstackRouter) {
|
||||||
*out = new(string)
|
*out = new(string)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
|
if in.ExternalSubnet != nil {
|
||||||
|
in, out := &in.ExternalSubnet, &out.ExternalSubnet
|
||||||
|
*out = new(string)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,9 @@ type OpenstackCloud interface {
|
||||||
//ListExternalNetworks will return the Neutron networks with the router:external property
|
//ListExternalNetworks will return the Neutron networks with the router:external property
|
||||||
GetExternalNetwork() (*networks.Network, error)
|
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 will return the subnet for floatingip which is used in lb
|
||||||
GetLBFloatingSubnet() (*subnets.Subnet, error)
|
GetLBFloatingSubnet() (*subnets.Subnet, error)
|
||||||
|
|
||||||
|
@ -273,6 +276,7 @@ type openstackCloud struct {
|
||||||
dnsClient *gophercloud.ServiceClient
|
dnsClient *gophercloud.ServiceClient
|
||||||
lbClient *gophercloud.ServiceClient
|
lbClient *gophercloud.ServiceClient
|
||||||
extNetworkName *string
|
extNetworkName *string
|
||||||
|
extSubnetName *string
|
||||||
floatingSubnet *string
|
floatingSubnet *string
|
||||||
tags map[string]string
|
tags map[string]string
|
||||||
region string
|
region string
|
||||||
|
@ -376,6 +380,9 @@ func NewOpenstackCloud(tags map[string]string, spec *kops.ClusterSpec) (Openstac
|
||||||
|
|
||||||
c.extNetworkName = spec.CloudConfig.Openstack.Router.ExternalNetwork
|
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 &&
|
if spec.CloudConfig.Openstack.Loadbalancer != nil &&
|
||||||
spec.CloudConfig.Openstack.Loadbalancer.FloatingNetworkID == nil &&
|
spec.CloudConfig.Openstack.Loadbalancer.FloatingNetworkID == nil &&
|
||||||
spec.CloudConfig.Openstack.Loadbalancer.FloatingNetwork != nil {
|
spec.CloudConfig.Openstack.Loadbalancer.FloatingNetwork != nil {
|
||||||
|
|
|
@ -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) {
|
func (c *openstackCloud) GetLBFloatingSubnet() (subnet *subnets.Subnet, err error) {
|
||||||
if c.floatingSubnet == nil {
|
if c.floatingSubnet == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -102,6 +102,18 @@ func (_ *Router) RenderOpenstack(t *openstack.OpenstackAPITarget, a, e, changes
|
||||||
NetworkID: floatingNet.ID,
|
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)
|
v, err := t.Cloud.CreateRouter(opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating router: %v", err)
|
return fmt.Errorf("Error creating router: %v", err)
|
||||||
|
|
Loading…
Reference in New Issue