mirror of https://github.com/kubernetes/kops.git
Merge pull request #61 from justinsb/upup_elb_healthchecks
cloudup: Add support for ELB health checks
This commit is contained in:
commit
833bfa40f8
|
|
@ -204,7 +204,6 @@ func (c *CreateClusterCmd) Run() error {
|
||||||
c.Config.NodeUpTags = append(c.Config.NodeUpTags, "_aws")
|
c.Config.NodeUpTags = append(c.Config.NodeUpTags, "_aws")
|
||||||
|
|
||||||
l.AddTypes(map[string]interface{}{
|
l.AddTypes(map[string]interface{}{
|
||||||
"autoscalingGroup": &awstasks.AutoscalingGroup{},
|
|
||||||
"dhcpOptions": &awstasks.DHCPOptions{},
|
"dhcpOptions": &awstasks.DHCPOptions{},
|
||||||
"elasticIP": &awstasks.ElasticIP{},
|
"elasticIP": &awstasks.ElasticIP{},
|
||||||
"iamInstanceProfile": &awstasks.IAMInstanceProfile{},
|
"iamInstanceProfile": &awstasks.IAMInstanceProfile{},
|
||||||
|
|
@ -226,6 +225,18 @@ func (c *CreateClusterCmd) Run() error {
|
||||||
"subnet": &awstasks.Subnet{},
|
"subnet": &awstasks.Subnet{},
|
||||||
"vpc": &awstasks.VPC{},
|
"vpc": &awstasks.VPC{},
|
||||||
"vpcDHDCPOptionsAssociation": &awstasks.VPCDHCPOptionsAssociation{},
|
"vpcDHDCPOptionsAssociation": &awstasks.VPCDHCPOptionsAssociation{},
|
||||||
|
|
||||||
|
// ELB
|
||||||
|
"loadBalancer": &awstasks.LoadBalancer{},
|
||||||
|
"loadBalancerAttachment": &awstasks.LoadBalancerAttachment{},
|
||||||
|
"loadBalancerHealthChecks": &awstasks.LoadBalancerHealthChecks{},
|
||||||
|
|
||||||
|
// Autoscaling
|
||||||
|
"autoscalingGroup": &awstasks.AutoscalingGroup{},
|
||||||
|
|
||||||
|
// Route53
|
||||||
|
"dnsName": &awstasks.DNSName{},
|
||||||
|
"dnsZone": &awstasks.DNSZone{},
|
||||||
})
|
})
|
||||||
|
|
||||||
// For now a zone to be specified...
|
// For now a zone to be specified...
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ import (
|
||||||
type LoadBalancer struct {
|
type LoadBalancer struct {
|
||||||
Name *string
|
Name *string
|
||||||
|
|
||||||
|
// ID is the name in ELB, possibly different from our name
|
||||||
|
// (ELB is restricted as to names, so we have limited choices!)
|
||||||
ID *string
|
ID *string
|
||||||
|
|
||||||
DNSName *string
|
DNSName *string
|
||||||
|
|
@ -27,6 +29,12 @@ type LoadBalancer struct {
|
||||||
Listeners map[string]*LoadBalancerListener
|
Listeners map[string]*LoadBalancerListener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ fi.CompareWithID = &LoadBalancer{}
|
||||||
|
|
||||||
|
func (e *LoadBalancer) CompareWithID() *string {
|
||||||
|
return e.ID
|
||||||
|
}
|
||||||
|
|
||||||
type LoadBalancerListener struct {
|
type LoadBalancerListener struct {
|
||||||
InstancePort int
|
InstancePort int
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +98,12 @@ func findELB(cloud *awsup.AWSCloud, name string) (*elb.LoadBalancerDescription,
|
||||||
func (e *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
|
func (e *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
|
||||||
cloud := c.Cloud.(*awsup.AWSCloud)
|
cloud := c.Cloud.(*awsup.AWSCloud)
|
||||||
|
|
||||||
lb, err := findELB(cloud, fi.StringValue(e.Name))
|
elbName := fi.StringValue(e.ID)
|
||||||
|
if elbName == "" {
|
||||||
|
elbName = fi.StringValue(e.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
lb, err := findELB(cloud, elbName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +113,7 @@ func (e *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
|
||||||
|
|
||||||
actual := &LoadBalancer{}
|
actual := &LoadBalancer{}
|
||||||
actual.Name = e.Name
|
actual.Name = e.Name
|
||||||
actual.ID = e.DNSName
|
actual.ID = lb.LoadBalancerName
|
||||||
actual.DNSName = lb.DNSName
|
actual.DNSName = lb.DNSName
|
||||||
actual.HostedZoneId = lb.CanonicalHostedZoneNameID
|
actual.HostedZoneId = lb.CanonicalHostedZoneNameID
|
||||||
for _, subnet := range lb.Subnets {
|
for _, subnet := range lb.Subnets {
|
||||||
|
|
@ -126,13 +139,15 @@ func (e *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
|
||||||
if subnetSlicesEqualIgnoreOrder(actual.Subnets, e.Subnets) {
|
if subnetSlicesEqualIgnoreOrder(actual.Subnets, e.Subnets) {
|
||||||
actual.Subnets = e.Subnets
|
actual.Subnets = e.Subnets
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.DNSName == nil {
|
if e.DNSName == nil {
|
||||||
e.DNSName = actual.DNSName
|
e.DNSName = actual.DNSName
|
||||||
}
|
}
|
||||||
if e.HostedZoneId == nil {
|
if e.HostedZoneId == nil {
|
||||||
e.HostedZoneId = actual.HostedZoneId
|
e.HostedZoneId = actual.HostedZoneId
|
||||||
}
|
}
|
||||||
|
if e.ID == nil {
|
||||||
|
e.ID = actual.ID
|
||||||
|
}
|
||||||
|
|
||||||
return actual, nil
|
return actual, nil
|
||||||
}
|
}
|
||||||
|
|
@ -157,9 +172,18 @@ func (s *LoadBalancer) CheckChanges(a, e, changes *LoadBalancer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalancer) error {
|
func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalancer) error {
|
||||||
|
elbName := e.ID
|
||||||
|
if elbName == nil {
|
||||||
|
elbName = e.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
if elbName == nil {
|
||||||
|
return fi.RequiredField("ID")
|
||||||
|
}
|
||||||
|
|
||||||
if a == nil {
|
if a == nil {
|
||||||
request := &elb.CreateLoadBalancerInput{}
|
request := &elb.CreateLoadBalancerInput{}
|
||||||
request.LoadBalancerName = e.Name
|
request.LoadBalancerName = elbName
|
||||||
|
|
||||||
for _, subnet := range e.Subnets {
|
for _, subnet := range e.Subnets {
|
||||||
request.Subnets = append(request.Subnets, subnet.ID)
|
request.Subnets = append(request.Subnets, subnet.ID)
|
||||||
|
|
@ -180,7 +204,7 @@ func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalan
|
||||||
request.Listeners = append(request.Listeners, awsListener)
|
request.Listeners = append(request.Listeners, awsListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(2).Infof("Creating ELB with Name:%q", *e.Name)
|
glog.V(2).Infof("Creating ELB with Name:%q", *e.ID)
|
||||||
|
|
||||||
response, err := t.Cloud.ELB.CreateLoadBalancer(request)
|
response, err := t.Cloud.ELB.CreateLoadBalancer(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -188,9 +212,9 @@ func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalan
|
||||||
}
|
}
|
||||||
|
|
||||||
e.DNSName = response.DNSName
|
e.DNSName = response.DNSName
|
||||||
e.ID = response.DNSName
|
e.ID = elbName
|
||||||
|
|
||||||
lb, err := findELB(t.Cloud, *e.Name)
|
lb, err := findELB(t.Cloud, *e.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -207,7 +231,7 @@ func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalan
|
||||||
|
|
||||||
if changes.Listeners != nil {
|
if changes.Listeners != nil {
|
||||||
request := &elb.CreateLoadBalancerListenersInput{}
|
request := &elb.CreateLoadBalancerListenersInput{}
|
||||||
request.LoadBalancerName = e.Name
|
request.LoadBalancerName = elbName
|
||||||
|
|
||||||
for loadBalancerPort, listener := range changes.Listeners {
|
for loadBalancerPort, listener := range changes.Listeners {
|
||||||
loadBalancerPortInt, err := strconv.ParseInt(loadBalancerPort, 10, 64)
|
loadBalancerPortInt, err := strconv.ParseInt(loadBalancerPort, 10, 64)
|
||||||
|
|
@ -227,5 +251,5 @@ func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.AddAWSTags(*e.ID, t.Cloud.BuildTags(e.Name, nil))
|
return t.AddELBTags(*e.ID, t.Cloud.BuildTags(e.Name, nil))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func (e *LoadBalancerAttachment) Find(c *fi.Context) (*LoadBalancerAttachment, e
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range g.LoadBalancerNames {
|
for _, name := range g.LoadBalancerNames {
|
||||||
if aws.StringValue(name) != *e.AutoscalingGroup.Name {
|
if aws.StringValue(name) != *e.LoadBalancer.ID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ func (s *LoadBalancerAttachment) CheckChanges(a, e, changes *LoadBalancerAttachm
|
||||||
func (_ *LoadBalancerAttachment) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalancerAttachment) error {
|
func (_ *LoadBalancerAttachment) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalancerAttachment) error {
|
||||||
request := &autoscaling.AttachLoadBalancersInput{}
|
request := &autoscaling.AttachLoadBalancersInput{}
|
||||||
request.AutoScalingGroupName = e.AutoscalingGroup.Name
|
request.AutoScalingGroupName = e.AutoscalingGroup.Name
|
||||||
request.LoadBalancerNames = []*string{e.LoadBalancer.Name}
|
request.LoadBalancerNames = []*string{e.LoadBalancer.ID}
|
||||||
|
|
||||||
glog.V(2).Infof("Attaching autoscaling group %q to ELB %q", *e.AutoscalingGroup.Name, *e.LoadBalancer.Name)
|
glog.V(2).Infof("Attaching autoscaling group %q to ELB %q", *e.AutoscalingGroup.Name, *e.LoadBalancer.Name)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
package awstasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/aws/aws-sdk-go/service/elb"
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"k8s.io/kube-deploy/upup/pkg/fi"
|
||||||
|
"k8s.io/kube-deploy/upup/pkg/fi/cloudup/awsup"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoadBalancerHealthChecks struct {
|
||||||
|
LoadBalancer *LoadBalancer
|
||||||
|
|
||||||
|
Target *string
|
||||||
|
|
||||||
|
HealthyThreshold *int64
|
||||||
|
UnhealthyThreshold *int64
|
||||||
|
|
||||||
|
Interval *int64
|
||||||
|
Timeout *int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *LoadBalancerHealthChecks) String() string {
|
||||||
|
return fi.TaskAsString(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *LoadBalancerHealthChecks) Find(c *fi.Context) (*LoadBalancerHealthChecks, error) {
|
||||||
|
cloud := c.Cloud.(*awsup.AWSCloud)
|
||||||
|
|
||||||
|
elbName := fi.StringValue(e.LoadBalancer.ID)
|
||||||
|
|
||||||
|
lb, err := findELB(cloud, elbName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if lb == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := &LoadBalancerHealthChecks{}
|
||||||
|
actual.LoadBalancer = e.LoadBalancer
|
||||||
|
|
||||||
|
if lb.HealthCheck != nil {
|
||||||
|
actual.Target = lb.HealthCheck.Target
|
||||||
|
actual.HealthyThreshold = lb.HealthCheck.HealthyThreshold
|
||||||
|
actual.UnhealthyThreshold = lb.HealthCheck.UnhealthyThreshold
|
||||||
|
actual.Interval = lb.HealthCheck.Interval
|
||||||
|
actual.Timeout = lb.HealthCheck.Timeout
|
||||||
|
}
|
||||||
|
return actual, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *LoadBalancerHealthChecks) Run(c *fi.Context) error {
|
||||||
|
return fi.DefaultDeltaRunMethod(e, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *LoadBalancerHealthChecks) CheckChanges(a, e, changes *LoadBalancerHealthChecks) error {
|
||||||
|
if a == nil {
|
||||||
|
if e.LoadBalancer == nil {
|
||||||
|
return fi.RequiredField("LoadBalancer")
|
||||||
|
}
|
||||||
|
if e.Target == nil {
|
||||||
|
return fi.RequiredField("Target")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_ *LoadBalancerHealthChecks) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalancerHealthChecks) error {
|
||||||
|
request := &elb.ConfigureHealthCheckInput{}
|
||||||
|
request.LoadBalancerName = e.LoadBalancer.ID
|
||||||
|
request.HealthCheck = &elb.HealthCheck{
|
||||||
|
Target: e.Target,
|
||||||
|
HealthyThreshold: e.HealthyThreshold,
|
||||||
|
UnhealthyThreshold: e.UnhealthyThreshold,
|
||||||
|
Interval: e.Interval,
|
||||||
|
Timeout: e.Timeout,
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.V(2).Infof("Configuring health checks on ELB %q", *e.LoadBalancer.ID)
|
||||||
|
|
||||||
|
_, err := t.Cloud.ELB.ConfigureHealthCheck(request)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error attaching autoscaling group to ELB: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue