Skip to content

Commit

Permalink
feat : add load balancer listener tag using service annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
yorubad-dev committed Oct 18, 2023
1 parent 1b8f119 commit 97a664a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/openstack/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
ServiceAnnotationLoadBalancerXForwardedFor = "loadbalancer.openstack.org/x-forwarded-for"
ServiceAnnotationLoadBalancerFlavorID = "loadbalancer.openstack.org/flavor-id"
ServiceAnnotationLoadBalancerAvailabilityZone = "loadbalancer.openstack.org/availability-zone"
ServiceAnnotationLoadBalancerListenerTags = "loadbalancer.openstack.org/listener-Tags"
// ServiceAnnotationLoadBalancerEnableHealthMonitor defines whether to create health monitor for the load balancer
// pool, if not specified, use 'create-monitor' config. The health monitor can be created or deleted dynamically.
ServiceAnnotationLoadBalancerEnableHealthMonitor = "loadbalancer.openstack.org/enable-health-monitor"
Expand Down Expand Up @@ -605,6 +606,32 @@ func (lbaas *LbaasV2) getLoadBalancerLegacyName(_ context.Context, _ string, ser
return cloudprovider.DefaultLoadBalancerName(service)
}

// this function gets the listeners tags from the service annotation and
func (lbaas *LbaasV2) customLoadBalanceListenerTag(service *corev1.Service) ([]string, error) {
var listener listeners.Listener
annotationVal := getStringFromServiceAnnotation(service, ServiceAnnotationLoadBalancerListenerTags, "")

listOfTags := strings.Split(annotationVal, "=")

if annotationVal == "" {
return listener.Tags, fmt.Errorf("annotation is missing or empty for %q", service.Name)
}

if annotationVal != "" {
for _, tags := range listOfTags {
tag := strings.Split(strings.TrimSpace(tags), "=")

if len(tag) == 2 {
listener.Tags = append(listener.Tags, tags)
} else {
return listener.Tags, fmt.Errorf("invalid tag format: %s", tags)
}
}
}

return listener.Tags, nil
}

// The LB needs to be configured with instance addresses on the same
// subnet as the LB (aka opts.SubnetID). Currently, we're just
// guessing that the node's InternalIP is the right address.
Expand Down

0 comments on commit 97a664a

Please sign in to comment.