Merge pull request #8014 from bittopaz/ali-patch-2

Alicloud: support internal api loadbalancer
This commit is contained in:
Kubernetes Prow Robot 2019-11-28 06:19:03 -08:00 committed by GitHub
commit 2e572edf82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 9 deletions

View File

@ -73,8 +73,12 @@ func (b *APILoadBalancerModelBuilder) Build(c *fi.ModelBuilderContext) error {
switch lbSpec.Type {
case kops.LoadBalancerTypeInternal:
return errors.New("internal LoadBalancers are not yet supported by kops on ALI")
//loadbalancer.AddressType = s("intranet")
utilitySubnets := b.GetUtilitySubnets()
if len(utilitySubnets) == 0 {
return errors.New("internal loadbalancer requires at least 1 utility subnet")
}
loadbalancer.AddressType = s("intranet")
loadbalancer.VSwitchId = fi.String(utilitySubnets[0].ProviderID)
case kops.LoadBalancerTypePublic:
loadbalancer.AddressType = s("internet")
default:

View File

@ -76,6 +76,17 @@ func (c *ALIModelContext) GetNameForVSwitchSNAT(subnetName string) string {
return subnetName + "." + c.ClusterName()
}
func (c *ALIModelContext) GetUtilitySubnets() []*kops.ClusterSubnetSpec {
var subnets []*kops.ClusterSubnetSpec
for i := range c.Cluster.Spec.Subnets {
subnet := &c.Cluster.Spec.Subnets[i]
if subnet.Type == kops.SubnetTypeUtility {
subnets = append(subnets, subnet)
}
}
return subnets
}
// LinkLoadBalancer returns the LoadBalancer object the cluster is located in
func (c *ALIModelContext) LinkLoadBalancer() *alitasks.LoadBalancer {
return &alitasks.LoadBalancer{Name: s(c.GetNameForLoadBalancer())}

View File

@ -36,6 +36,7 @@ type LoadBalancer struct {
Name *string
LoadbalancerId *string
AddressType *string
VSwitchId *string
LoadBalancerAddress *string
Lifecycle *fi.Lifecycle
Tags map[string]string
@ -63,21 +64,25 @@ func (l *LoadBalancer) Find(c *fi.Context) (*LoadBalancer, error) {
return nil, fmt.Errorf("error finding LoadBalancers: %v", err)
}
// Don't exist loadbalancer with specified ClusterTags or Name.
// There's no loadbalancer with specified ClusterTags or Name.
if len(responseLoadBalancers) == 0 {
klog.V(4).Infof("can't find loadbalancer with name: %q", *l.Name)
return nil, nil
}
if len(responseLoadBalancers) > 1 {
klog.V(4).Infof("The number of specified loadbalancer with the same name exceeds 1, loadbalancerName:%q", *l.Name)
return nil, fmt.Errorf("more than 1 loadbalancer is found with name: %q", *l.Name)
}
klog.V(2).Infof("found matching LoadBalancer: %q", *l.Name)
lb := responseLoadBalancers[0]
actual := &LoadBalancer{}
actual.Name = fi.String(responseLoadBalancers[0].LoadBalancerName)
actual.AddressType = fi.String(string(responseLoadBalancers[0].AddressType))
actual.LoadbalancerId = fi.String(responseLoadBalancers[0].LoadBalancerId)
actual.LoadBalancerAddress = fi.String(responseLoadBalancers[0].Address)
actual := &LoadBalancer{
Name: fi.String(lb.LoadBalancerName),
AddressType: fi.String(string(lb.AddressType)),
LoadbalancerId: fi.String(lb.LoadBalancerId),
LoadBalancerAddress: fi.String(lb.Address),
VSwitchId: fi.String(lb.VSwitchId),
}
describeTagsArgs := &slb.DescribeTagsArgs{
RegionId: common.Region(cloud.Region()),
@ -165,6 +170,7 @@ func (_ *LoadBalancer) RenderALI(t *aliup.ALIAPITarget, a, e, changes *LoadBalan
RegionId: common.Region(t.Cloud.Region()),
LoadBalancerName: fi.StringValue(e.Name),
AddressType: slb.AddressType(fi.StringValue(e.AddressType)),
VSwitchId: fi.StringValue(e.VSwitchId),
}
response, err := t.Cloud.SlbClient().CreateLoadBalancer(createLoadBalancerArgs)
if err != nil {