mirror of https://github.com/kubernetes/kops.git
Use without external router
This commit is contained in:
parent
082eda37f0
commit
c0759525fc
|
@ -63,7 +63,7 @@ func (b *NetworkModelBuilder) Build(c *fi.ModelBuilderContext) error {
|
|||
DNSServers: make([]*string, 0),
|
||||
Lifecycle: b.Lifecycle,
|
||||
}
|
||||
if b.Cluster.Spec.CloudConfig.Openstack.Router.DNSServers != nil {
|
||||
if b.Cluster.Spec.CloudConfig.Openstack.Router != nil && b.Cluster.Spec.CloudConfig.Openstack.Router.DNSServers != nil {
|
||||
dnsSplitted := strings.Split(fi.StringValue(b.Cluster.Spec.CloudConfig.Openstack.Router.DNSServers), ",")
|
||||
dnsNameSrv := make([]*string, len(dnsSplitted))
|
||||
for i, ns := range dnsSplitted {
|
||||
|
|
|
@ -136,33 +136,41 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
|
|||
}
|
||||
c.AddTask(instanceTask)
|
||||
|
||||
// Associate a floating IP to the master and bastion always, associate it to a node if bastion is not used
|
||||
switch ig.Spec.Role {
|
||||
case kops.InstanceGroupRoleBastion:
|
||||
t := &openstacktasks.FloatingIP{
|
||||
Name: fi.String(fmt.Sprintf("%s-%s", "fip", *instanceTask.Name)),
|
||||
Server: instanceTask,
|
||||
Lifecycle: b.Lifecycle,
|
||||
}
|
||||
c.AddTask(t)
|
||||
case kops.InstanceGroupRoleMaster:
|
||||
if b.Cluster.Spec.CloudConfig.Openstack.Loadbalancer == nil {
|
||||
// Associate a floating IP to the master and bastion always if we have external network in router
|
||||
// associate it to a node if bastion is not used
|
||||
if b.Cluster.Spec.CloudConfig.Openstack != nil && b.Cluster.Spec.CloudConfig.Openstack.Router != nil {
|
||||
switch ig.Spec.Role {
|
||||
case kops.InstanceGroupRoleBastion:
|
||||
t := &openstacktasks.FloatingIP{
|
||||
Name: fi.String(fmt.Sprintf("%s-%s", "fip", *instanceTask.Name)),
|
||||
Server: instanceTask,
|
||||
Lifecycle: b.Lifecycle,
|
||||
}
|
||||
c.AddTask(t)
|
||||
b.associateFIPToKeypair(c, t)
|
||||
}
|
||||
default:
|
||||
if !b.UsesSSHBastion() {
|
||||
t := &openstacktasks.FloatingIP{
|
||||
Name: fi.String(fmt.Sprintf("%s-%s", "fip", *instanceTask.Name)),
|
||||
Server: instanceTask,
|
||||
Lifecycle: b.Lifecycle,
|
||||
case kops.InstanceGroupRoleMaster:
|
||||
if b.Cluster.Spec.CloudConfig.Openstack.Loadbalancer == nil {
|
||||
t := &openstacktasks.FloatingIP{
|
||||
Name: fi.String(fmt.Sprintf("%s-%s", "fip", *instanceTask.Name)),
|
||||
Server: instanceTask,
|
||||
Lifecycle: b.Lifecycle,
|
||||
}
|
||||
c.AddTask(t)
|
||||
b.associateFIPToKeypair(c, t)
|
||||
}
|
||||
c.AddTask(t)
|
||||
default:
|
||||
if !b.UsesSSHBastion() {
|
||||
t := &openstacktasks.FloatingIP{
|
||||
Name: fi.String(fmt.Sprintf("%s-%s", "fip", *instanceTask.Name)),
|
||||
Server: instanceTask,
|
||||
Lifecycle: b.Lifecycle,
|
||||
}
|
||||
c.AddTask(t)
|
||||
}
|
||||
}
|
||||
} else if b.Cluster.Spec.CloudConfig.Openstack != nil && b.Cluster.Spec.CloudConfig.Openstack.Router == nil {
|
||||
// No external router, but we need to add master fixed ips to certificates
|
||||
if ig.Spec.Role == kops.InstanceGroupRoleMaster {
|
||||
b.associateFixedIPToKeypair(c, instanceTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +178,19 @@ func (b *ServerGroupModelBuilder) buildInstances(c *fi.ModelBuilderContext, sg *
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *ServerGroupModelBuilder) associateFixedIPToKeypair(c *fi.ModelBuilderContext, fipTask *openstacktasks.Instance) error {
|
||||
// Ensure the floating IP is included in the TLS certificate,
|
||||
// if we're not going to use an alias for it
|
||||
// TODO: I don't love this technique for finding the task by name & modifying it
|
||||
masterKeypairTask, found := c.Tasks["Keypair/master"]
|
||||
if !found {
|
||||
return fmt.Errorf("keypair/master task not found")
|
||||
}
|
||||
masterKeypair := masterKeypairTask.(*fitasks.Keypair)
|
||||
masterKeypair.AlternateNameTasks = append(masterKeypair.AlternateNameTasks, fipTask)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *ServerGroupModelBuilder) associateFIPToKeypair(c *fi.ModelBuilderContext, fipTask *openstacktasks.FloatingIP) error {
|
||||
// Ensure the floating IP is included in the TLS certificate,
|
||||
// if we're not going to use an alias for it
|
||||
|
|
|
@ -287,17 +287,18 @@ type OpenstackCloud interface {
|
|||
}
|
||||
|
||||
type openstackCloud struct {
|
||||
cinderClient *gophercloud.ServiceClient
|
||||
neutronClient *gophercloud.ServiceClient
|
||||
novaClient *gophercloud.ServiceClient
|
||||
dnsClient *gophercloud.ServiceClient
|
||||
lbClient *gophercloud.ServiceClient
|
||||
extNetworkName *string
|
||||
extSubnetName *string
|
||||
floatingSubnet *string
|
||||
tags map[string]string
|
||||
region string
|
||||
useOctavia bool
|
||||
cinderClient *gophercloud.ServiceClient
|
||||
neutronClient *gophercloud.ServiceClient
|
||||
novaClient *gophercloud.ServiceClient
|
||||
dnsClient *gophercloud.ServiceClient
|
||||
lbClient *gophercloud.ServiceClient
|
||||
floatingEnabled bool
|
||||
extNetworkName *string
|
||||
extSubnetName *string
|
||||
floatingSubnet *string
|
||||
tags map[string]string
|
||||
region string
|
||||
useOctavia bool
|
||||
}
|
||||
|
||||
var _ fi.Cloud = &openstackCloud{}
|
||||
|
@ -392,11 +393,13 @@ func NewOpenstackCloud(tags map[string]string, spec *kops.ClusterSpec) (Openstac
|
|||
}
|
||||
|
||||
octavia := false
|
||||
floatingEnabled := false
|
||||
if spec != nil &&
|
||||
spec.CloudConfig != nil &&
|
||||
spec.CloudConfig.Openstack != nil &&
|
||||
spec.CloudConfig.Openstack.Router != nil {
|
||||
|
||||
floatingEnabled = true
|
||||
c.extNetworkName = spec.CloudConfig.Openstack.Router.ExternalNetwork
|
||||
|
||||
if spec.CloudConfig.Openstack.Router.ExternalSubnet != nil {
|
||||
|
@ -423,6 +426,7 @@ func NewOpenstackCloud(tags map[string]string, spec *kops.ClusterSpec) (Openstac
|
|||
}
|
||||
}
|
||||
}
|
||||
c.floatingEnabled = floatingEnabled
|
||||
c.useOctavia = octavia
|
||||
var lbClient *gophercloud.ServiceClient
|
||||
if spec != nil && spec.CloudConfig != nil && spec.CloudConfig.Openstack != nil {
|
||||
|
@ -598,7 +602,6 @@ func (c *openstackCloud) GetApiIngressStatus(cluster *kops.Cluster) ([]kops.ApiI
|
|||
if err != nil {
|
||||
return ingresses, fmt.Errorf("GetApiIngressStatus: Failed to list master nodes: %v", err)
|
||||
}
|
||||
|
||||
for _, instance := range instances {
|
||||
val, ok := instance.Metadata["k8s"]
|
||||
val2, ok2 := instance.Metadata["KopsRole"]
|
||||
|
|
|
@ -78,7 +78,11 @@ func (c *openstackCloud) ListServerFloatingIPs(instanceID string) ([]*string, er
|
|||
|
||||
for _, addrList := range addresses {
|
||||
for _, props := range addrList {
|
||||
if props.IPType == "floating" {
|
||||
if c.floatingEnabled {
|
||||
if props.IPType == "floating" {
|
||||
result = append(result, fi.String(props.Addr))
|
||||
}
|
||||
} else {
|
||||
result = append(result, fi.String(props.Addr))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ type Instance struct {
|
|||
Lifecycle *fi.Lifecycle
|
||||
}
|
||||
|
||||
var _ fi.HasAddress = &Instance{}
|
||||
|
||||
// GetDependencies returns the dependencies of the Instance task
|
||||
func (e *Instance) GetDependencies(tasks map[string]fi.Task) []fi.Task {
|
||||
var deps []fi.Task
|
||||
|
@ -70,6 +72,24 @@ func (e *Instance) CompareWithID() *string {
|
|||
return e.ID
|
||||
}
|
||||
|
||||
func (e *Instance) FindIPAddress(context *fi.Context) (*string, error) {
|
||||
cloud := context.Cloud.(openstack.OpenstackCloud)
|
||||
if e.Port == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
ports, err := cloud.GetPort(fi.StringValue(e.Port.ID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, port := range ports.FixedIPs {
|
||||
return fi.String(port.IPAddress), nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (e *Instance) Find(c *fi.Context) (*Instance, error) {
|
||||
if e == nil || e.Name == nil {
|
||||
return nil, nil
|
||||
|
|
Loading…
Reference in New Issue