Skip to content

getServicePIPNames returns duplicated PIP name for single-stack IPv4 services #10169

@Liunardy

Description

@Liunardy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions