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.25] Truncate lengthy PIP name #5257

Merged
merged 1 commit into from
Jan 11, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -363,6 +363,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
10 changes: 9 additions & 1 deletion pkg/provider/azure_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ func (az *Cloud) getPublicIPName(clusterName string, service *v1.Service) string
}
pipName = fmt.Sprintf("%s-%s", pipName, prefixName)
}
return pipName

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 pipNameSegment
}

func (az *Cloud) serviceOwnsRule(service *v1.Service, rule string) bool {
Expand Down
64 changes: 64 additions & 0 deletions pkg/provider/azure_standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2301,3 +2301,67 @@ func TestGetSecurityRuleName(t *testing.T) {
})
}
}

func TestGetPublicIPName(t *testing.T) {
testcases := []struct {
desc string
svc *v1.Service
pips []network.PublicIPAddress
isIPv6 bool
expectedPIPName string
}{
{
desc: "common",
svc: &v1.Service{
ObjectMeta: meta.ObjectMeta{UID: types.UID("uid")},
Spec: v1.ServiceSpec{
IPFamilies: []v1.IPFamily{v1.IPv4Protocol},
},
},
isIPv6: false,
expectedPIPName: "azure-auid",
},
{
desc: "Service PIP prefix id",
svc: &v1.Service{
ObjectMeta: meta.ObjectMeta{
UID: types.UID("uid"),
Annotations: map[string]string{
consts.ServiceAnnotationPIPPrefixIDDualStack[false]: "prefix-id",
},
},
Spec: v1.ServiceSpec{
IPFamilies: []v1.IPFamily{v1.IPv4Protocol},
},
},
isIPv6: false,
expectedPIPName: "azure-auid-prefix-id",
},
{
desc: "Service PIP prefix id IPv6 lengthy",
svc: &v1.Service{
ObjectMeta: meta.ObjectMeta{
UID: types.UID("uid"),
Annotations: map[string]string{
consts.ServiceAnnotationPIPPrefixIDDualStack[false]: "prefix-id-ipv6-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
},
Spec: v1.ServiceSpec{
IPFamilies: []v1.IPFamily{v1.IPv6Protocol},
},
},
isIPv6: true,
expectedPIPName: "azure-auid-prefix-id-ipv6-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
}

ctrl := gomock.NewController(t)
defer ctrl.Finish()
for _, tc := range testcases {
t.Run(tc.desc, func(t *testing.T) {
az := GetTestCloud(ctrl)
name := az.getPublicIPName("azure", tc.svc)
assert.Equal(t, tc.expectedPIPName, name)
})
}
}
Loading