@@ -44,6 +44,10 @@ func (t *Translator) TranslateGateway(tctx *provider.TranslateContext, obj *gate
4444 result .SSL = append (result .SSL , ssl ... )
4545 }
4646 }
47+ log .Debugw ("translate gateway result.SSL" , zap .Any ("result.SSL" , len (result .SSL )))
48+ result .SSL = mergeSSLWithSameID (result .SSL )
49+ log .Debugw ("after merging SSL with same ID" , zap .Any ("result.SSL" , len (result .SSL )))
50+
4751 rk := provider.ResourceKind {
4852 Kind : obj .Kind ,
4953 Namespace : obj .Namespace ,
@@ -233,3 +237,44 @@ func (t *Translator) fillPluginMetadataFromGatewayProxy(pluginMetadata adctypes.
233237 pluginMetadata [pluginName ] = pluginConfig
234238 }
235239}
240+
241+ // mergeSSLWithSameID merge ssl with same id
242+ func mergeSSLWithSameID (sslList []* adctypes.SSL ) []* adctypes.SSL {
243+ if len (sslList ) <= 1 {
244+ return sslList
245+ }
246+
247+ // create a map to store ssl with same id
248+ sslMap := make (map [string ]* adctypes.SSL )
249+ for _ , ssl := range sslList {
250+ if existing , exists := sslMap [ssl .ID ]; exists {
251+ // if ssl with same id exists, merge their snis
252+ // use map to deduplicate
253+ sniMap := make (map [string ]struct {})
254+ // add existing snis
255+ for _ , sni := range existing .Snis {
256+ sniMap [sni ] = struct {}{}
257+ }
258+ // add new snis
259+ for _ , sni := range ssl .Snis {
260+ sniMap [sni ] = struct {}{}
261+ }
262+ // rebuild deduplicated snis list
263+ newSnis := make ([]string , 0 , len (sniMap ))
264+ for sni := range sniMap {
265+ newSnis = append (newSnis , sni )
266+ }
267+ // update existing ssl object
268+ existing .Snis = newSnis
269+ } else {
270+ // if new ssl id, add to map
271+ sslMap [ssl .ID ] = ssl
272+ }
273+ }
274+
275+ mergedSSL := make ([]* adctypes.SSL , 0 , len (sslMap ))
276+ for _ , ssl := range sslMap {
277+ mergedSSL = append (mergedSSL , ssl )
278+ }
279+ return mergedSSL
280+ }
0 commit comments