Skip to content

Commit

Permalink
Merge pull request #5258 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…5219-to-release-1.28

[release-1.28] Truncate lengthy PIP name
  • Loading branch information
k8s-ci-robot committed Jan 10, 2024
2 parents 3afd510 + 2dfcfbb commit f66c5df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
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 @@ -338,7 +338,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

0 comments on commit f66c5df

Please sign in to comment.