@@ -23,7 +23,8 @@ func shortStableHash(value string) string {
2323 return hex .EncodeToString (sum [:6 ])
2424}
2525
26- func boundedBaseWithHash (base , hash string , maxLen int ) string {
26+ // truncate base to fit maxLen and append hash, hash is included in maxLen
27+ func truncateAndAppendHash (base , hash string , maxLen int ) string {
2728 base = strings .Trim (base , "-" )
2829 name := fmt .Sprintf ("%s-%s" , base , hash )
2930 if len (name ) <= maxLen {
@@ -43,46 +44,43 @@ func boundedBaseWithHash(base, hash string, maxLen int) string {
4344 return fmt .Sprintf ("%s-%s" , trimmedBase , hash )
4445}
4546
47+ // example: gateway-ns1-c6d39be275c7
4648func FilterConfigBundleIndexSecretName (gwName , gwNamespace string ) string {
4749 rawIdentity := fmt .Sprintf ("%s/%s" , gwNamespace , gwName )
48- return boundedBaseWithHash ( LegacyFilterConfigSecretName (gwName , gwNamespace ), shortStableHash (rawIdentity ), k8sObjectNameMaxLen )
50+ return truncateAndAppendHash ( legacyFilterConfigSecretName (gwName , gwNamespace ), shortStableHash (rawIdentity ), k8sObjectNameMaxLen )
4951}
5052
51- func filterConfigBundlePartSecretName (baseSecretName string , idx int ) string {
53+ // example: gateway-ns1-c6d39be275c7-part-000
54+ func filterConfigBundlePartSecretName (gwName , gwNamespace string , idx int ) string {
55+ rawIdentity := fmt .Sprintf ("%s/%s" , gwNamespace , gwName )
56+ hash := shortStableHash (rawIdentity )
57+ base := fmt .Sprintf ("%s-%s" , gwName , gwNamespace )
5258 suffix := fmt .Sprintf ("-part-%03d" , idx )
53- maxNameLen := k8sObjectNameMaxLen - len (suffix )
54-
55- // Preserve full identity hash (the trailing "-<12hex>") when deriving part names.
56- lastDash := strings .LastIndex (baseSecretName , "-" )
57- if lastDash > 0 {
58- hash := baseSecretName [lastDash + 1 :]
59- if len (hash ) == 12 {
60- prefix := baseSecretName [:lastDash ]
61- return boundedBaseWithHash (prefix , hash , maxNameLen ) + suffix
62- }
63- }
59+ maxNameLen := k8sObjectNameMaxLen - len (hash ) - len (suffix ) - 1
6460
65- // Fallback for unexpected base names that do not carry a hash suffix.
66- if len (baseSecretName ) > maxNameLen {
67- baseSecretName = strings .TrimRight (baseSecretName [:maxNameLen ], "-" )
61+ if len (base ) > maxNameLen {
62+ base = strings .TrimRight (base [:maxNameLen ], "-" )
6863 }
69- return baseSecretName + suffix
64+ return base + "-" + hash + suffix
7065}
7166
72- func LegacyFilterConfigSecretName (gwName , gwNamespace string ) string {
73- return fmt .Sprintf ("%s-%s" , gwName , gwNamespace )
67+ // example: ai-gateway-gateway-ns1-c6d39be275c7-bundle
68+ func filterConfigBundleVolumeName (gwName , gwNamespace string ) string {
69+ const suffix = "-bundle"
70+ rawIdentity := fmt .Sprintf ("%s/%s" , gwNamespace , gwName )
71+ volumeBase := fmt .Sprintf ("%s%s-%s" , mutationNamePrefix , gwName , gwNamespace )
72+ base := truncateAndAppendHash (volumeBase , shortStableHash (rawIdentity ), k8sVolumeNameMaxLen - len (suffix ))
73+ return base + suffix
7474}
7575
76- func filterConfigVolumeName (gwName , gwNamespace string ) string {
77- rawIdentity := fmt .Sprintf ("%s/%s" , gwNamespace , gwName )
78- legacyVolumeBase := mutationNamePrefix + LegacyFilterConfigSecretName (gwName , gwNamespace )
79- return boundedBaseWithHash (legacyVolumeBase , shortStableHash (rawIdentity ), k8sVolumeNameMaxLen )
76+ // example: gateway-ns1
77+ func legacyFilterConfigSecretName (gwName , gwNamespace string ) string {
78+ return fmt .Sprintf ("%s-%s" , gwName , gwNamespace )
8079}
8180
82- func filterConfigBundleVolumeName ( gwName , gwNamespace string ) string {
83- const suffix = "-bundle"
81+ // example: ai-gateway-gw-default-3d45476e8d68
82+ func legacyFilterConfigVolumeName ( gwName , gwNamespace string ) string {
8483 rawIdentity := fmt .Sprintf ("%s/%s" , gwNamespace , gwName )
85- legacyVolumeBase := mutationNamePrefix + LegacyFilterConfigSecretName (gwName , gwNamespace )
86- base := boundedBaseWithHash (legacyVolumeBase , shortStableHash (rawIdentity ), k8sVolumeNameMaxLen - len (suffix ))
87- return base + suffix
84+ volumeBase := fmt .Sprintf ("%s%s-%s" , mutationNamePrefix , gwName , gwNamespace )
85+ return truncateAndAppendHash (volumeBase , shortStableHash (rawIdentity ), k8sVolumeNameMaxLen )
8886}
0 commit comments