Skip to content

Commit

Permalink
Merge pull request #227 from chengxiangdong/feat_class
Browse files Browse the repository at this point in the history
feat: add class support
  • Loading branch information
k8s-ci-robot authored Oct 19, 2023
2 parents 98ae47d + 0980b6c commit 4658721
Show file tree
Hide file tree
Showing 16 changed files with 1,832 additions and 72 deletions.
4 changes: 4 additions & 0 deletions docs/huawei-cloud-controller-manager-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ data:
"type": "SOURCE_IP",
"persistence_timeout": 15
},
"disable-create-security-group": false,
"health-check-flag": "on",
"health-check-option": {
"delay": 5,
Expand Down Expand Up @@ -219,3 +220,6 @@ The following arguments are supported:

* `l7-flavor-id` Optional. Specifies the ID of a flavor at Layer 7.
Only dedicated load balancer service will use this annotation.

* `disable-create-security-group` Optional. Disable automatic creation of security groups for ELB health checks.
Valid values are `'true'` and `'false'`. The default is `'false'`.
1 change: 0 additions & 1 deletion docs/usage-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,4 @@ $ curl 192.168.0.113
<html>
<head>
<title>Welcome to nginx!</title>
...
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/mitchellh/mapstructure v1.4.1
github.com/onsi/ginkgo/v2 v2.6.1
github.com/onsi/gomega v1.24.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/spf13/pflag v1.0.5
google.golang.org/grpc v1.49.0
gopkg.in/gcfg.v1 v1.2.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ github.com/onsi/ginkgo/v2 v2.6.1 h1:1xQPCjcqYw/J5LchOcp4/2q/jzJFjiAOc25chhnDw+Q=
github.com/onsi/ginkgo/v2 v2.6.1/go.mod h1:yjiuMwPokqY1XauOgju45q3sJt6VzQ/Fict1LFVcsAo=
github.com/onsi/gomega v1.24.1 h1:KORJXNNTzJXzu4ScJWssJfJMnJ+2QJqhoQSRwNlze9E=
github.com/onsi/gomega v1.24.1/go.mod h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
41 changes: 26 additions & 15 deletions pkg/cloudprovider/huaweicloud/dedicatedloadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
cloudprovider "k8s.io/cloud-provider"
"strings"

elbmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
Expand Down Expand Up @@ -107,8 +108,11 @@ func (d *DedicatedLoadBalancer) GetLoadBalancerName(_ context.Context, clusterNa
}

func (d *DedicatedLoadBalancer) EnsureLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
klog.Infof("EnsureLoadBalancer: called with service %s/%s, node: %d",
service.Namespace, service.Name, len(nodes))
if !d.isSupportedSvc(service) {
return nil, cloudprovider.ImplementedElsewhere
}

klog.Infof("EnsureLoadBalancer: called with service %s/%s, node: %d", service.Namespace, service.Name, len(nodes))

if err := ensureLoadBalancerValidation(service, nodes); err != nil {
return nil, err
Expand Down Expand Up @@ -491,7 +495,7 @@ func (d *DedicatedLoadBalancer) deletePool(pool *elbmodel.Pool) []error {
}

func (d *DedicatedLoadBalancer) addOrRemoveMembers(loadbalancer *elbmodel.LoadBalancer, service *v1.Service,
pool *elbmodel.Pool, port v1.ServicePort, nodes []*v1.Node) error {
pool *elbmodel.Pool, svcPort v1.ServicePort, nodes []*v1.Node) error {

members, err := d.dedicatedELBClient.ListMembers(&elbmodel.ListMembersRequest{PoolId: pool.Id})
if err != nil {
Expand Down Expand Up @@ -530,7 +534,7 @@ func (d *DedicatedLoadBalancer) addOrRemoveMembers(loadbalancer *elbmodel.LoadBa
pod.Namespace, pod.Spec.NodeName)
}

address, err := getNodeAddress(node)
address, portNum, err := getMemberIP(service, node, pod, svcPort)
if err != nil {
if common.IsNotFound(err) {
// Node failure, do not create member
Expand All @@ -541,18 +545,18 @@ func (d *DedicatedLoadBalancer) addOrRemoveMembers(loadbalancer *elbmodel.LoadBa
}
}

key := fmt.Sprintf("%s:%d", address, port.NodePort)
key := fmt.Sprintf("%s:%d", address, svcPort.NodePort)
if existsMember[key] {
klog.Infof("[addOrRemoveMembers] node already exists, skip adding, name: %s, address: %s, port: %d",
node.Name, address, port.NodePort)
members = d.popMember(members, address, port.NodePort)
node.Name, address, portNum)
members = d.popMember(members, address, portNum)
continue
}

klog.Infof("[addOrRemoveMembers] add node to pool, name: %s, address: %s, port: %d",
node.Name, address, port.NodePort)
node.Name, address, portNum)
// Add a member to the pool.
if err = d.addMember(loadbalancer, pool, port, node); err != nil {
if err = d.addMember(service, loadbalancer, pool, pod, svcPort, node); err != nil {
return err
}
existsMember[key] = true
Expand All @@ -571,22 +575,25 @@ func (d *DedicatedLoadBalancer) addOrRemoveMembers(loadbalancer *elbmodel.LoadBa
return nil
}

func (d *DedicatedLoadBalancer) addMember(loadbalancer *elbmodel.LoadBalancer, pool *elbmodel.Pool, port v1.ServicePort,
node *v1.Node) error {
func (d *DedicatedLoadBalancer) addMember(service *v1.Service, loadbalancer *elbmodel.LoadBalancer, pool *elbmodel.Pool, pod v1.Pod, svcPort v1.ServicePort, node *v1.Node) error {
klog.Infof("Add a member(%s) to pool %s", node.Name, pool.Id)
address, err := getNodeAddress(node)
address, port, err := getMemberIP(service, node, pod, svcPort)
if err != nil {
return err
}

name := utils.CutString(fmt.Sprintf("member_%s_%s", pool.Name, node.Name), defaultMaxNameLength)
opt := &elbmodel.CreateMemberOption{
Name: &name,
ProtocolPort: port.NodePort,
ProtocolPort: port,
Address: address,
}
if !loadbalancer.IpTargetEnable {
opt.SubnetCidrId = &loadbalancer.VipSubnetCidrId
subnetID, err := d.getSubnetID(service, node)
if err != nil {
return err
}
opt.SubnetCidrId = &subnetID
}

if _, err = d.dedicatedELBClient.AddMember(pool.Id, opt); err != nil {
Expand Down Expand Up @@ -744,6 +751,10 @@ func (d *DedicatedLoadBalancer) createHealthMonitor(loadbalancerID, poolID, prot

func (d *DedicatedLoadBalancer) UpdateLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) error {
klog.Infof("UpdateLoadBalancer: called with service %s/%s, node: %d", service.Namespace, service.Name, len(nodes))
if !d.isSupportedSvc(service) {
return cloudprovider.ImplementedElsewhere
}

// get exits or create a new ELB instance
loadbalancer, err := d.getLoadBalancerInstance(ctx, clusterName, service)
if err != nil {
Expand Down Expand Up @@ -875,7 +886,7 @@ func (d *DedicatedLoadBalancer) deleteELBInstance(loadBalancer *elbmodel.LoadBal

klog.Infof("deleting unbind EIP: %v", eipID)
if err := d.eipClient.Delete(eipID); err != nil {
klog.Errorf("failed to delete EIP: %s", loadBalancer.Eips[0].EipAddress)
klog.Errorf("failed to delete EIP: %s", eipID)
}

return nil
Expand Down
Loading

0 comments on commit 4658721

Please sign in to comment.