@@ -998,30 +998,35 @@ func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember(ctx context.Contex
998
998
999
999
internalIP := m .GetMachineInternalIP ()
1000
1000
1001
- // TODO:SHILPA- handle multiple lbs as well
1002
- // Update each LoadBalancer pool
1003
- loadBalancerListeners := map [string ]infrav1beta2.AdditionalListenerSpec {}
1001
+ // lbAdditionalListeners is a mapping of additionalListener's port-protocol to the additionalListener as defined in the specification
1002
+ // It will be used later to get the default pool associated with the listener
1003
+ lbAdditionalListeners := map [string ]infrav1beta2.AdditionalListenerSpec {}
1004
1004
for _ , additionalListener := range lb .AdditionalListeners {
1005
- // TODO:SHILPA- protocol is added irrespective of whats provided in the additionalListener protocol, need to handle this
1006
1005
if additionalListener .Protocol == nil {
1007
1006
additionalListener .Protocol = & infrav1beta2 .VPCLoadBalancerListenerProtocolTCP
1008
1007
}
1009
- loadBalancerListeners [fmt .Sprintf ("%d-%s" , additionalListener .Port , * additionalListener .Protocol )] = additionalListener
1008
+ lbAdditionalListeners [fmt .Sprintf ("%d-%s" , additionalListener .Port , * additionalListener .Protocol )] = additionalListener
1010
1009
}
1010
+
1011
+ // loadBalancerListeners is a mapping of the loadBalancer listener's defaultPoolName to the additionalListener
1012
+ // as the default pool name might be empty in spec and should be fetched from the cloud's listener
1013
+ loadBalancerListeners := map [string ]infrav1beta2.AdditionalListenerSpec {}
1011
1014
for _ , listener := range loadBalancer .Listeners {
1012
1015
listenerOptions := & vpcv1.GetLoadBalancerListenerOptions {}
1013
1016
listenerOptions .SetLoadBalancerID (* loadBalancer .ID )
1014
1017
listenerOptions .SetID (* listener .ID )
1015
1018
loadBalancerListener , _ , err := m .IBMVPCClient .GetLoadBalancerListener (listenerOptions )
1016
1019
if err != nil {
1017
- return nil , fmt .Errorf ("failed to list %s load balancer listener: %v " , * listener .ID , err )
1020
+ return nil , fmt .Errorf ("failed to list %s load balancer listener: %w " , * listener .ID , err )
1018
1021
}
1019
- if additionalListener , ok := loadBalancerListeners [fmt .Sprintf ("%d-%s" , * loadBalancerListener .Port , * loadBalancerListener .Protocol )]; ok {
1022
+ if additionalListener , ok := lbAdditionalListeners [fmt .Sprintf ("%d-%s" , * loadBalancerListener .Port , * loadBalancerListener .Protocol )]; ok {
1020
1023
if loadBalancerListener .DefaultPool != nil {
1021
1024
loadBalancerListeners [* loadBalancerListener .DefaultPool .Name ] = additionalListener
1022
1025
}
1023
1026
}
1024
1027
}
1028
+ // Update each LoadBalancer pool
1029
+ // For each pool, get the additionalListener associated with the pool from the loadBalancerListeners map.
1025
1030
for _ , pool := range loadBalancer .Pools {
1026
1031
log .V (3 ).Info ("Updating LoadBalancer pool member" , "pool" , * pool .Name , "loadBalancerName" , * loadBalancer .Name , "IP" , internalIP )
1027
1032
listOptions := & vpcv1.ListLoadBalancerPoolMembersOptions {}
@@ -1032,13 +1037,14 @@ func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember(ctx context.Contex
1032
1037
return nil , fmt .Errorf ("failed to list %s VPC load balancer pool: %w" , * pool .Name , err )
1033
1038
}
1034
1039
var targetPort int64
1035
- var alreadyRegistered , skipListener bool
1040
+ var alreadyRegistered bool
1036
1041
1037
1042
if loadBalancerListener , ok := loadBalancerListeners [* pool .Name ]; ok {
1038
1043
targetPort = loadBalancerListener .Port
1044
+ log .V (3 ).Info ("Label selector for configuring additional listener is %+v" , loadBalancerListener .Selector )
1039
1045
selector , err := metav1 .LabelSelectorAsSelector (& loadBalancerListener .Selector )
1040
1046
if err != nil {
1041
- log .V (5 ).Info ( "Skipping listener addition, failed to get label selector from spec selector" )
1047
+ log .V (5 ).Error ( err , "Skipping listener addition, failed to get label selector from spec selector" )
1042
1048
continue
1043
1049
}
1044
1050
@@ -1047,13 +1053,10 @@ func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember(ctx context.Contex
1047
1053
}
1048
1054
// Skip adding the listener if the selector does not match
1049
1055
if ! selector .Empty () && ! selector .Matches (labels .Set (m .IBMPowerVSMachine .Labels )) {
1050
- skipListener = true
1056
+ log .V (3 ).Info ("Skip adding listener, machine label doesn't match with the listener label selector" , "pool" , * pool .Name , "IP" , internalIP )
1057
+ continue
1051
1058
}
1052
1059
}
1053
- if skipListener {
1054
- log .V (3 ).Info ("Skip adding listener, machine label doesn't match with the listener label selector" , "pool" , * pool .Name , "targetip" , internalIP , "machine" , m .IBMPowerVSMachine .Name , "clusterName" , m .IBMPowerVSCluster .Name )
1055
- continue
1056
- }
1057
1060
1058
1061
for _ , member := range listLoadBalancerPoolMembers .Members {
1059
1062
if target , ok := member .Target .(* vpcv1.LoadBalancerPoolMemberTarget ); ok {
0 commit comments