mirror of https://github.com/kubernetes/kops.git
Allow returning multiple addresses for API
This commit is contained in:
parent
6377b68811
commit
2f8154692f
|
|
@ -81,16 +81,18 @@ func (b *BootstrapScript) kubeEnv(ig *kops.InstanceGroup, c *fi.Context) (string
|
||||||
var alternateNames []string
|
var alternateNames []string
|
||||||
|
|
||||||
for _, hasAddress := range b.alternateNameTasks {
|
for _, hasAddress := range b.alternateNameTasks {
|
||||||
address, err := hasAddress.FindIPAddress(c)
|
addresses, err := hasAddress.FindAddresses(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error finding address for %v: %v", hasAddress, err)
|
return "", fmt.Errorf("error finding address for %v: %v", hasAddress, err)
|
||||||
}
|
}
|
||||||
if address == nil {
|
if len(addresses) == 0 {
|
||||||
klog.Warningf("Task did not have an address: %v", hasAddress)
|
klog.Warningf("Task did not have an address: %v", hasAddress)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
klog.V(8).Infof("Resolved alternateName %q for %q", *address, hasAddress)
|
for _, address := range addresses {
|
||||||
alternateNames = append(alternateNames, *address)
|
klog.V(8).Infof("Resolved alternateName %q for %q", address, hasAddress)
|
||||||
|
alternateNames = append(alternateNames, address)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(alternateNames)
|
sort.Strings(alternateNames)
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,7 @@ func (e *ClassicLoadBalancer) IsForAPIServer() bool {
|
||||||
return e.ForAPIServer
|
return e.ForAPIServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ClassicLoadBalancer) FindIPAddress(context *fi.Context) (*string, error) {
|
func (e *ClassicLoadBalancer) FindAddresses(context *fi.Context) ([]string, error) {
|
||||||
cloud := context.Cloud.(awsup.AWSCloud)
|
cloud := context.Cloud.(awsup.AWSCloud)
|
||||||
|
|
||||||
lb, err := cloud.FindELBByNameTag(fi.StringValue(e.Name))
|
lb, err := cloud.FindELBByNameTag(fi.StringValue(e.Name))
|
||||||
|
|
@ -361,7 +361,7 @@ func (e *ClassicLoadBalancer) FindIPAddress(context *fi.Context) (*string, error
|
||||||
if lbDnsName == "" {
|
if lbDnsName == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return &lbDnsName, nil
|
return []string{lbDnsName}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ClassicLoadBalancer) Run(c *fi.Context) error {
|
func (e *ClassicLoadBalancer) Run(c *fi.Context) error {
|
||||||
|
|
|
||||||
|
|
@ -430,7 +430,7 @@ func (e *NetworkLoadBalancer) IsForAPIServer() bool {
|
||||||
return e.ForAPIServer
|
return e.ForAPIServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NetworkLoadBalancer) FindIPAddress(context *fi.Context) (*string, error) {
|
func (e *NetworkLoadBalancer) FindAddresses(context *fi.Context) ([]string, error) {
|
||||||
cloud := context.Cloud.(awsup.AWSCloud)
|
cloud := context.Cloud.(awsup.AWSCloud)
|
||||||
|
|
||||||
lb, err := cloud.FindELBV2ByNameTag(e.Tags["Name"])
|
lb, err := cloud.FindELBV2ByNameTag(e.Tags["Name"])
|
||||||
|
|
@ -445,7 +445,7 @@ func (e *NetworkLoadBalancer) FindIPAddress(context *fi.Context) (*string, error
|
||||||
if lbDnsName == "" {
|
if lbDnsName == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return &lbDnsName, nil
|
return []string{lbDnsName}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NetworkLoadBalancer) Run(c *fi.Context) error {
|
func (e *NetworkLoadBalancer) Run(c *fi.Context) error {
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func (_ *LoadBalancer) RenderDO(t *do.DOAPITarget, a, e, changes *LoadBalancer)
|
||||||
if strings.Contains(loadbalancer.Name, fi.StringValue(e.Name)) {
|
if strings.Contains(loadbalancer.Name, fi.StringValue(e.Name)) {
|
||||||
// load balancer already exists.
|
// load balancer already exists.
|
||||||
e.ID = fi.String(loadbalancer.ID)
|
e.ID = fi.String(loadbalancer.ID)
|
||||||
e.IPAddress = fi.String(loadbalancer.IP) // This will be empty on create, but will be filled later on FindIPAddress invokation.
|
e.IPAddress = fi.String(loadbalancer.IP) // This will be empty on create, but will be filled later on FindAddresses invokation.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +183,7 @@ func (_ *LoadBalancer) RenderDO(t *do.DOAPITarget, a, e, changes *LoadBalancer)
|
||||||
}
|
}
|
||||||
|
|
||||||
e.ID = fi.String(loadbalancer.ID)
|
e.ID = fi.String(loadbalancer.ID)
|
||||||
e.IPAddress = fi.String(loadbalancer.IP) // This will be empty on create, but will be filled later on FindIPAddress invokation.
|
e.IPAddress = fi.String(loadbalancer.IP) // This will be empty on create, but will be filled later on FindAddresses invokation.
|
||||||
|
|
||||||
klog.V(2).Infof("load balancer for DO created with id: %s", loadbalancer.ID)
|
klog.V(2).Infof("load balancer for DO created with id: %s", loadbalancer.ID)
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -193,7 +193,7 @@ func (lb *LoadBalancer) IsForAPIServer() bool {
|
||||||
return lb.ForAPIServer
|
return lb.ForAPIServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lb *LoadBalancer) FindIPAddress(c *fi.Context) (*string, error) {
|
func (lb *LoadBalancer) FindAddresses(c *fi.Context) ([]string, error) {
|
||||||
cloud := c.Cloud.(do.DOCloud)
|
cloud := c.Cloud.(do.DOCloud)
|
||||||
loadBalancerService := cloud.LoadBalancersService()
|
loadBalancerService := cloud.LoadBalancersService()
|
||||||
address := ""
|
address := ""
|
||||||
|
|
@ -217,7 +217,7 @@ func (lb *LoadBalancer) FindIPAddress(c *fi.Context) (*string, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
if done {
|
if done {
|
||||||
return &address, nil
|
return []string{address}, nil
|
||||||
} else {
|
} else {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = wait.ErrWaitTimeout
|
err = wait.ErrWaitTimeout
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ func (e *Address) IsForAPIServer() bool {
|
||||||
return e.ForAPIServer
|
return e.ForAPIServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Address) FindIPAddress(context *fi.Context) (*string, error) {
|
func (e *Address) FindAddresses(context *fi.Context) ([]string, error) {
|
||||||
actual, err := e.find(context.Cloud.(gce.GCECloud))
|
actual, err := e.find(context.Cloud.(gce.GCECloud))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error querying for IP Address: %v", err)
|
return nil, fmt.Errorf("error querying for IP Address: %v", err)
|
||||||
|
|
@ -108,7 +108,7 @@ func (e *Address) FindIPAddress(context *fi.Context) (*string, error) {
|
||||||
if actual == nil {
|
if actual == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return actual.IPAddress, nil
|
return []string{fi.StringValue(actual.IPAddress)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Address) Run(c *fi.Context) error {
|
func (e *Address) Run(c *fi.Context) error {
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ func (e *FloatingIP) IsForAPIServer() bool {
|
||||||
return e.ForAPIServer
|
return e.ForAPIServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *FloatingIP) FindIPAddress(context *fi.Context) (*string, error) {
|
func (e *FloatingIP) FindAddresses(context *fi.Context) ([]string, error) {
|
||||||
if e.ID == nil {
|
if e.ID == nil {
|
||||||
if e.LB != nil && e.LB.ID == nil {
|
if e.LB != nil && e.LB.ID == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -94,7 +94,7 @@ func (e *FloatingIP) FindIPAddress(context *fi.Context) (*string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(fips) == 1 && fips[0].PortID == fi.StringValue(e.LB.PortID) {
|
if len(fips) == 1 && fips[0].PortID == fi.StringValue(e.LB.PortID) {
|
||||||
return &fips[0].FloatingIP, nil
|
return []string{fips[0].FloatingIP}, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("Could not find port floatingips port=%s", fi.StringValue(e.LB.PortID))
|
return nil, fmt.Errorf("Could not find port floatingips port=%s", fi.StringValue(e.LB.PortID))
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,7 @@ func (e *FloatingIP) FindIPAddress(context *fi.Context) (*string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &fip.FloatingIP, nil
|
return []string{fip.FloatingIP}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDependencies returns the dependencies of the Instance task
|
// GetDependencies returns the dependencies of the Instance task
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ func (e *Instance) IsForAPIServer() bool {
|
||||||
return e.ForAPIServer
|
return e.ForAPIServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Instance) FindIPAddress(context *fi.Context) (*string, error) {
|
func (e *Instance) FindAddresses(context *fi.Context) ([]string, error) {
|
||||||
cloud := context.Cloud.(openstack.OpenstackCloud)
|
cloud := context.Cloud.(openstack.OpenstackCloud)
|
||||||
if e.Port == nil {
|
if e.Port == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -110,7 +110,7 @@ func (e *Instance) FindIPAddress(context *fi.Context) (*string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, port := range ports.FixedIPs {
|
for _, port := range ports.FixedIPs {
|
||||||
return fi.String(port.IPAddress), nil
|
return []string{port.IPAddress}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,5 @@ type HasAddress interface {
|
||||||
// IsForAPIServer indicates whether the implementation provides an address that needs to be added to the api-server server certificate.
|
// IsForAPIServer indicates whether the implementation provides an address that needs to be added to the api-server server certificate.
|
||||||
IsForAPIServer() bool
|
IsForAPIServer() bool
|
||||||
// FindIPAddress returns the address associated with the implementor. If there is no address, returns (nil, nil).
|
// FindIPAddress returns the address associated with the implementor. If there is no address, returns (nil, nil).
|
||||||
FindIPAddress(context *Context) (*string, error)
|
FindAddresses(context *Context) ([]string, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue