Skip to content

Commit ef67a45

Browse files
committed
Addressed review comments
1 parent 937f5b2 commit ef67a45

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

api/v1beta2/ibmvpccluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ type AdditionalListenerSpec struct {
128128
// +optional
129129
Protocol *VPCLoadBalancerListenerProtocol `json:"protocol,omitempty"`
130130

131-
// Selector is used to select the machines with same label to assign the listener
131+
// selector is used to select the machines with same label to assign the listener
132132
// +kubebuilder:validation:Optional
133133
Selector metav1.LabelSelector `json:"selector,omitempty"`
134134
}

cloud/scope/powervs_machine.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -998,30 +998,35 @@ func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember(ctx context.Contex
998998

999999
internalIP := m.GetMachineInternalIP()
10001000

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{}
10041004
for _, additionalListener := range lb.AdditionalListeners {
1005-
// TODO:SHILPA- protocol is added irrespective of whats provided in the additionalListener protocol, need to handle this
10061005
if additionalListener.Protocol == nil {
10071006
additionalListener.Protocol = &infrav1beta2.VPCLoadBalancerListenerProtocolTCP
10081007
}
1009-
loadBalancerListeners[fmt.Sprintf("%d-%s", additionalListener.Port, *additionalListener.Protocol)] = additionalListener
1008+
lbAdditionalListeners[fmt.Sprintf("%d-%s", additionalListener.Port, *additionalListener.Protocol)] = additionalListener
10101009
}
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{}
10111014
for _, listener := range loadBalancer.Listeners {
10121015
listenerOptions := &vpcv1.GetLoadBalancerListenerOptions{}
10131016
listenerOptions.SetLoadBalancerID(*loadBalancer.ID)
10141017
listenerOptions.SetID(*listener.ID)
10151018
loadBalancerListener, _, err := m.IBMVPCClient.GetLoadBalancerListener(listenerOptions)
10161019
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)
10181021
}
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 {
10201023
if loadBalancerListener.DefaultPool != nil {
10211024
loadBalancerListeners[*loadBalancerListener.DefaultPool.Name] = additionalListener
10221025
}
10231026
}
10241027
}
1028+
// Update each LoadBalancer pool
1029+
// For each pool, get the additionalListener associated with the pool from the loadBalancerListeners map.
10251030
for _, pool := range loadBalancer.Pools {
10261031
log.V(3).Info("Updating LoadBalancer pool member", "pool", *pool.Name, "loadBalancerName", *loadBalancer.Name, "IP", internalIP)
10271032
listOptions := &vpcv1.ListLoadBalancerPoolMembersOptions{}
@@ -1032,13 +1037,13 @@ func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember(ctx context.Contex
10321037
return nil, fmt.Errorf("failed to list %s VPC load balancer pool: %w", *pool.Name, err)
10331038
}
10341039
var targetPort int64
1035-
var alreadyRegistered, skipListener bool
1040+
var alreadyRegistered bool
10361041

10371042
if loadBalancerListener, ok := loadBalancerListeners[*pool.Name]; ok {
10381043
targetPort = loadBalancerListener.Port
10391044
selector, err := metav1.LabelSelectorAsSelector(&loadBalancerListener.Selector)
10401045
if err != nil {
1041-
log.V(5).Info("Skipping listener addition, failed to get label selector from spec selector")
1046+
log.V(5).Error(err, "Skipping listener addition, failed to get label selector from spec selector")
10421047
continue
10431048
}
10441049

@@ -1047,13 +1052,10 @@ func (m *PowerVSMachineScope) CreateVPCLoadBalancerPoolMember(ctx context.Contex
10471052
}
10481053
// Skip adding the listener if the selector does not match
10491054
if !selector.Empty() && !selector.Matches(labels.Set(m.IBMPowerVSMachine.Labels)) {
1050-
skipListener = true
1055+
log.V(3).Info("Skip adding listener, machine label doesn't match with the listener label selector", "pool", *pool.Name, "IP", internalIP)
1056+
continue
10511057
}
10521058
}
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-
}
10571059

10581060
for _, member := range listLoadBalancerPoolMembers.Members {
10591061
if target, ok := member.Target.(*vpcv1.LoadBalancerPoolMemberTarget); ok {

internal/webhooks/ibmpowervscluster.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ func validateAdditionalListenerSelector(newCluster, oldCluster *infrav1beta2.IBM
254254
newLoadBalancerListeners[fmt.Sprintf("%d-%s", additionalListener.Port, *additionalListener.Protocol)] = additionalListener.Selector
255255
}
256256
}
257-
fmt.Println(oldCluster.Spec.LoadBalancers)
258257
for _, loadbalancer := range oldCluster.Spec.LoadBalancers {
259258
for _, additionalListener := range loadbalancer.AdditionalListeners {
260259
if _, ok := newLoadBalancerListeners[fmt.Sprintf("%d-%s", additionalListener.Port, *additionalListener.Protocol)]; ok && !reflect.DeepEqual(newLoadBalancerListeners[fmt.Sprintf("%d-%s", additionalListener.Port, *additionalListener.Protocol)], additionalListener.Selector) {

0 commit comments

Comments
 (0)