mirror of https://github.com/kubernetes/kops.git
Cleanups to make kops update apply cleanly for private topologies
Remove a few spurious changes
This commit is contained in:
parent
376fe2034b
commit
86622dad09
|
|
@ -96,6 +96,23 @@ func (e *DNSName) Find(c *fi.Context) (*DNSName, error) {
|
|||
actual.Name = e.Name
|
||||
actual.ResourceType = e.ResourceType
|
||||
|
||||
if found.AliasTarget != nil {
|
||||
dnsName := aws.StringValue(found.AliasTarget.DNSName)
|
||||
glog.Infof("AliasTarget for %q is %q", aws.StringValue(found.Name), dnsName)
|
||||
if dnsName != "" {
|
||||
// TODO: check "looks like" an ELB?
|
||||
lb, err := findLoadBalancerByAlias(cloud, found.AliasTarget)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error mapping DNSName %q to LoadBalancer: %v", dnsName, err)
|
||||
}
|
||||
if lb == nil {
|
||||
glog.Warningf("Unable to find load balancer with DNS name: %q", dnsName)
|
||||
} else {
|
||||
actual.TargetLoadBalancer = &LoadBalancer{ID: lb.LoadBalancerName}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return actual, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -125,9 +125,11 @@ func (e *ElasticIP) find(cloud awsup.AWSCloud) (*ElasticIP, error) {
|
|||
ID: a.AllocationId,
|
||||
PublicIP: a.PublicIp,
|
||||
}
|
||||
|
||||
actual.Subnet = e.Subnet
|
||||
|
||||
// ElasticIP don't have a Name (no tags), so we set the name to avoid spurious changes
|
||||
actual.Name = e.Name
|
||||
|
||||
e.ID = actual.ID
|
||||
|
||||
return actual, nil
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/elb"
|
||||
"github.com/aws/aws-sdk-go/service/route53"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:generate fitask -type=LoadBalancer
|
||||
|
|
@ -73,21 +75,17 @@ func (e *LoadBalancerListener) GetDependencies(tasks map[string]fi.Task) []fi.Ta
|
|||
return nil
|
||||
}
|
||||
|
||||
func findELB(cloud awsup.AWSCloud, name string) (*elb.LoadBalancerDescription, error) {
|
||||
func findLoadBalancer(cloud awsup.AWSCloud, name string) (*elb.LoadBalancerDescription, error) {
|
||||
request := &elb.DescribeLoadBalancersInput{
|
||||
LoadBalancerNames: []*string{&name},
|
||||
}
|
||||
var found []*elb.LoadBalancerDescription
|
||||
err := cloud.ELB().DescribeLoadBalancersPages(request, func(p *elb.DescribeLoadBalancersOutput, lastPage bool) (shouldContinue bool) {
|
||||
for _, lb := range p.LoadBalancerDescriptions {
|
||||
if aws.StringValue(lb.LoadBalancerName) == name {
|
||||
found = append(found, lb)
|
||||
} else {
|
||||
glog.Warningf("Got ELB with unexpected name")
|
||||
}
|
||||
found, err := describeLoadBalancers(cloud, request, func(lb *elb.LoadBalancerDescription) bool {
|
||||
if aws.StringValue(lb.LoadBalancerName) == name {
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
glog.Warningf("Got ELB with unexpected name: %q", lb.LoadBalancerName)
|
||||
return false
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -111,6 +109,62 @@ func findELB(cloud awsup.AWSCloud, name string) (*elb.LoadBalancerDescription, e
|
|||
return found[0], nil
|
||||
}
|
||||
|
||||
func findLoadBalancerByAlias(cloud awsup.AWSCloud, alias *route53.AliasTarget) (*elb.LoadBalancerDescription, error) {
|
||||
// TODO: Any way to avoid listing all ELBs?
|
||||
request := &elb.DescribeLoadBalancersInput{}
|
||||
|
||||
dnsName := aws.StringValue(alias.DNSName)
|
||||
matchDnsName := strings.TrimSuffix(dnsName, ".")
|
||||
if matchDnsName == "" {
|
||||
return nil, fmt.Errorf("DNSName not set on AliasTarget")
|
||||
}
|
||||
|
||||
matchHostedZoneId := aws.StringValue(alias.HostedZoneId)
|
||||
|
||||
found, err := describeLoadBalancers(cloud, request, func(lb *elb.LoadBalancerDescription) bool {
|
||||
if matchHostedZoneId != aws.StringValue(lb.CanonicalHostedZoneNameID) {
|
||||
return false
|
||||
}
|
||||
|
||||
lbDnsName := aws.StringValue(lb.DNSName)
|
||||
lbDnsName = strings.TrimSuffix(lbDnsName, ".")
|
||||
return lbDnsName == matchDnsName || "dualstack."+lbDnsName == matchDnsName
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error listing ELBs: %v", err)
|
||||
}
|
||||
|
||||
if len(found) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if len(found) != 1 {
|
||||
return nil, fmt.Errorf("Found multiple ELBs with DNSName %q", dnsName)
|
||||
}
|
||||
|
||||
return found[0], nil
|
||||
}
|
||||
|
||||
func describeLoadBalancers(cloud awsup.AWSCloud, request *elb.DescribeLoadBalancersInput, filter func(*elb.LoadBalancerDescription) bool) ([]*elb.LoadBalancerDescription, error) {
|
||||
var found []*elb.LoadBalancerDescription
|
||||
err := cloud.ELB().DescribeLoadBalancersPages(request, func(p *elb.DescribeLoadBalancersOutput, lastPage bool) (shouldContinue bool) {
|
||||
for _, lb := range p.LoadBalancerDescriptions {
|
||||
if filter(lb) {
|
||||
found = append(found, lb)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error listing ELBs: %v", err)
|
||||
}
|
||||
|
||||
return found, nil
|
||||
}
|
||||
|
||||
func (e *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
|
||||
cloud := c.Cloud.(awsup.AWSCloud)
|
||||
|
||||
|
|
@ -119,7 +173,7 @@ func (e *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
|
|||
elbName = fi.StringValue(e.Name)
|
||||
}
|
||||
|
||||
lb, err := findELB(cloud, elbName)
|
||||
lb, err := findLoadBalancer(cloud, elbName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -230,7 +284,7 @@ func (_ *LoadBalancer) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *LoadBalan
|
|||
e.DNSName = response.DNSName
|
||||
e.ID = elbName
|
||||
|
||||
lb, err := findELB(t.Cloud, *e.ID)
|
||||
lb, err := findLoadBalancer(t.Cloud, *e.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ func (e *LoadBalancerAttributes) Find(c *fi.Context) (*LoadBalancerAttributes, e
|
|||
|
||||
elbName := fi.StringValue(e.LoadBalancer.ID)
|
||||
|
||||
lb, err := findELB(cloud, elbName)
|
||||
lb, err := findLoadBalancer(cloud, elbName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func (e *LoadBalancerConnectionSettings) Find(c *fi.Context) (*LoadBalancerConne
|
|||
cloud := c.Cloud.(awsup.AWSCloud)
|
||||
elbName := fi.StringValue(e.LoadBalancer.ID)
|
||||
|
||||
lb, err := findELB(cloud, elbName)
|
||||
lb, err := findLoadBalancer(cloud, elbName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func (e *LoadBalancerHealthChecks) Find(c *fi.Context) (*LoadBalancerHealthCheck
|
|||
|
||||
elbName := fi.StringValue(e.LoadBalancer.ID)
|
||||
|
||||
lb, err := findELB(cloud, elbName)
|
||||
lb, err := findLoadBalancer(cloud, elbName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ limitations under the License.
|
|||
package awstasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||
"fmt"
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
)
|
||||
|
||||
//go:generate fitask -type=NatGateway
|
||||
|
|
@ -75,7 +75,6 @@ func (e *NatGateway) Find(c *fi.Context) (*NatGateway, error) {
|
|||
glog.V(2).Infof("Found nat gateway via tag: %v", *id)
|
||||
}
|
||||
|
||||
|
||||
if id != nil {
|
||||
request := &ec2.DescribeNatGatewaysInput{}
|
||||
request.NatGatewayIds = []*string{id}
|
||||
|
|
@ -105,6 +104,9 @@ func (e *NatGateway) Find(c *fi.Context) (*NatGateway, error) {
|
|||
return nil, fmt.Errorf("found multiple elastic IPs attached to NatGateway %q", aws.StringValue(a.NatGatewayId))
|
||||
}
|
||||
|
||||
// NATGateways don't have a Name (no tags), so we set the name to avoid spurious changes
|
||||
actual.Name = e.Name
|
||||
|
||||
e.ID = actual.ID
|
||||
return actual, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,12 @@ func (e *SecurityGroupRule) matches(rule *ec2.IpPermission) bool {
|
|||
if e.SourceGroup == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if e.SourceGroup.ID == nil {
|
||||
glog.Warningf("SourceGroup had nil ID: %v", e.SourceGroup)
|
||||
continue
|
||||
}
|
||||
|
||||
if aws.StringValue(spec.GroupId) == *e.SourceGroup.ID {
|
||||
match = true
|
||||
break
|
||||
|
|
|
|||
Loading…
Reference in New Issue