From 97a664a539ff6cfc9414068da04464f540c9c7a0 Mon Sep 17 00:00:00 2001 From: KingDaemonX Date: Wed, 18 Oct 2023 15:38:28 +0100 Subject: [PATCH] feat : add load balancer listener tag using service annotation --- pkg/openstack/loadbalancer.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/openstack/loadbalancer.go b/pkg/openstack/loadbalancer.go index 736d05fc3f..79c603e12c 100644 --- a/pkg/openstack/loadbalancer.go +++ b/pkg/openstack/loadbalancer.go @@ -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" @@ -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.