Skip to content

Commit e3589c1

Browse files
committed
refactor(hrq): Replace maxRQNameLength constant with validation.DNS1123SubdomainMaxLength for improved name length handling
1 parent 5a04c69 commit e3589c1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

internal/hrq/utils/scopedhrq.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
v1 "k8s.io/api/core/v1"
1010
"k8s.io/apimachinery/pkg/types"
11+
"k8s.io/apimachinery/pkg/util/validation"
1112
api "sigs.k8s.io/hierarchical-namespaces/api/v1alpha2"
1213
"sigs.k8s.io/hierarchical-namespaces/internal/metadata"
1314
)
@@ -17,10 +18,6 @@ const (
1718
hrqNamespaceLabel = "hnc.x-k8s.io/hrq-namespace"
1819
)
1920

20-
const (
21-
maxRQNameLength = 253
22-
)
23-
2421
func IsSingletonRQ(rq *v1.ResourceQuota) bool {
2522
return rq.Name == api.ResourceQuotaSingletonName
2623
}
@@ -75,7 +72,10 @@ func ScopedRQName(hrqNamespace string, hrqName string) (string, error) {
7572
hash := md5.Sum([]byte(fmt.Sprintf("%s/%s", hrqNamespace, hrqName)))
7673
hashStr := hex.EncodeToString(hash[:])
7774

78-
namespaceAndName := truncate(fmt.Sprintf("%s-%s", hrqNamespace, hrqName), maxRQNameLength-len(hashStr)-len(api.ResourceQuotaSingletonName)-2)
75+
namespaceAndName := truncate(
76+
fmt.Sprintf("%s-%s", hrqNamespace, hrqName),
77+
validation.DNS1123SubdomainMaxLength-len(hashStr)-len(api.ResourceQuotaSingletonName)-2,
78+
)
7979

8080
return fmt.Sprintf("%s-%s-%s", api.ResourceQuotaSingletonName, namespaceAndName, hashStr), nil
8181
}

0 commit comments

Comments
 (0)