Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.28] Truncate lengthy PIP name #5258

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ const (
FrontendIPConfigNameMaxLength = 80
// LoadBalancerRuleNameMaxLength is the max length of the load balancing rule
LoadBalancerRuleNameMaxLength = 80
// PIPPrefixNameMaxLength is the max length of the PIP prefix name
PIPPrefixNameMaxLength = 80
// IPFamilySuffixLength is the length of suffix length of IP family ("-IPv4", "-IPv6")
IPFamilySuffixLength = 5

Expand Down
9 changes: 8 additions & 1 deletion pkg/provider/azure_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,14 @@ func (az *Cloud) getPublicIPName(clusterName string, service *v1.Service, isIPv6
pipName = fmt.Sprintf("%s-%s", pipName, id)
}
}
return getResourceByIPFamily(pipName, isDualStack, isIPv6), nil

pipNameSegment := pipName
maxLength := consts.PIPPrefixNameMaxLength - consts.IPFamilySuffixLength
if len(pipName) > maxLength {
pipNameSegment = pipNameSegment[:maxLength]
klog.V(6).Infof("original PIP name is lengthy %q, truncate it to %q", pipName, pipNameSegment)
}
return getResourceByIPFamily(pipNameSegment, isDualStack, isIPv6), nil
}

func publicIPOwnsFrontendIP(service *v1.Service, fip *network.FrontendIPConfiguration, pip *network.PublicIPAddress) bool {
Expand Down
6 changes: 3 additions & 3 deletions pkg/provider/azure_standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2103,21 +2103,21 @@ func TestGetPublicIPName(t *testing.T) {
expectedPIPName: "azure-auid-prefix-id",
},
{
desc: "Service PIP prefix id dualstack IPv6",
desc: "Service PIP prefix id dualstack lengthy IPv6",
svc: &v1.Service{
ObjectMeta: meta.ObjectMeta{
UID: types.UID("uid"),
Annotations: map[string]string{
consts.ServiceAnnotationPIPPrefixIDDualStack[false]: "prefix-id",
consts.ServiceAnnotationPIPPrefixIDDualStack[true]: "prefix-id-ipv6",
consts.ServiceAnnotationPIPPrefixIDDualStack[true]: "prefix-id-ipv6-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
},
Spec: v1.ServiceSpec{
IPFamilies: []v1.IPFamily{v1.IPv4Protocol, v1.IPv6Protocol},
},
},
isIPv6: true,
expectedPIPName: "azure-auid-prefix-id-ipv6-IPv6",
expectedPIPName: "azure-auid-prefix-id-ipv6-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-IPv6",
},
{
desc: "Service PIP IPv6 only with existing PIP",
Expand Down