What happened:
For a single-stack IPv4 service with a PIP name annotation, getServicePIPNames returns ["my-pip", "my-pip"], the same IPv4 PIP name twice.
This is because it iterates over both IPv4 and IPv6, and getServicePIPName(svc, true) falls through to return the IPv4 annotation value for a single-stack IPv4 service.
|
func getServicePIPName(service *v1.Service, isIPv6 bool) string { |
|
if service == nil { |
|
return "" |
|
} |
|
|
|
if !isServiceDualStack(service) { |
|
v4Enabled, v6Enabled := getIPFamiliesEnabled(service) |
|
if isIPv6 && v6Enabled && !v4Enabled { |
|
if name := service.Annotations[consts.ServiceAnnotationPIPNameDualStack[true]]; name != "" { |
|
return name |
|
} |
|
} |
|
return service.Annotations[consts.ServiceAnnotationPIPNameDualStack[false]] |
|
} |
|
|
|
return service.Annotations[consts.ServiceAnnotationPIPNameDualStack[isIPv6]] |
|
} |
|
|
|
func getServicePIPNames(service *v1.Service) []string { |
|
var ips []string |
|
for _, ipVersion := range []bool{IPVersionIPv4, IPVersionIPv6} { |
|
ips = append(ips, getServicePIPName(service, ipVersion)) |
|
} |
|
return ips |
|
} |
The duplicate causes redundant PIP lookups
|
pipNames = getServicePIPNames(service) |
|
for _, pipName := range pipNames { |
|
if pipName != "" { |
|
pip, err := az.findMatchedPIP(ctx, "", pipName, pipResourceGroup) |
|
if err != nil { |
|
klog.Warningf("serviceOwnsFrontendIP: unexpected error when finding match public IP of the service %s with name %s: %v", service.Name, pipName, err) |
|
return false, isPrimaryService, nil |
|
} |
|
if publicIPOwnsFrontendIP(service, fip, pip) { |
|
return true, isPrimaryService, pip.Properties.PublicIPAddressVersion |
|
} |
|
} |
|
} |
What you expected to happen:
getServicePIPNames should not return duplicates for a single-stack IPv4 service.
What happened:
For a single-stack IPv4 service with a PIP name annotation,
getServicePIPNamesreturns["my-pip", "my-pip"], the same IPv4 PIP name twice.This is because it iterates over both IPv4 and IPv6, and
getServicePIPName(svc, true)falls through to return the IPv4 annotation value for a single-stack IPv4 service.cloud-provider-azure/pkg/provider/azure_utils.go
Lines 379 to 403 in c3c63a9
The duplicate causes redundant PIP lookups
cloud-provider-azure/pkg/provider/azure_loadbalancer.go
Lines 4379 to 4391 in c3c63a9
What you expected to happen:
getServicePIPNamesshould not return duplicates for a single-stack IPv4 service.