@@ -105,12 +105,7 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw
105105
106106 // get the EndpointSlice of the backend service
107107 backendService := path .Backend .Service
108- var endpointSlices []discoveryv1.EndpointSlice
109108 if backendService != nil {
110- endpointSlices = tctx .EndpointSlices [types.NamespacedName {
111- Namespace : obj .Namespace ,
112- Name : backendService .Name ,
113- }]
114109 backendRef := convertBackendRef (obj .Namespace , backendService .Name , "Service" )
115110 t .AttachBackendTrafficPolicyToUpstream (backendRef , tctx .BackendTrafficPolicies , upstream )
116111 }
@@ -131,28 +126,35 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw
131126 if getService == nil {
132127 continue
133128 }
134-
135- var getServicePort * corev1. ServicePort
136- for _ , port := range getService . Spec . Ports {
137- port := port
138- if servicePort > 0 && port . Port == servicePort {
139- getServicePort = & port
140- break
129+ if getService . Spec . Type == corev1 . ServiceTypeExternalName {
130+ upstream . Nodes = adctypes. UpstreamNodes {
131+ {
132+ Host : getService . Spec . ExternalName ,
133+ Port : int ( servicePort ),
134+ Weight : 1 ,
135+ },
141136 }
142- if servicePortName != "" && port .Name == servicePortName {
143- getServicePort = & port
144- break
137+ } else {
138+ var getServicePort * corev1.ServicePort
139+ for _ , port := range getService .Spec .Ports {
140+ port := port
141+ if servicePort > 0 && port .Port == servicePort {
142+ getServicePort = & port
143+ break
144+ }
145+ if servicePortName != "" && port .Name == servicePortName {
146+ getServicePort = & port
147+ break
148+ }
149+ }
150+ endpointSlices := tctx .EndpointSlices [types.NamespacedName {
151+ Namespace : obj .Namespace ,
152+ Name : backendService .Name ,
153+ }]
154+ // convert the EndpointSlice to upstream nodes
155+ if len (endpointSlices ) > 0 {
156+ upstream .Nodes = t .translateEndpointSliceForIngress (1 , endpointSlices , getServicePort )
145157 }
146- }
147-
148- // convert the EndpointSlice to upstream nodes
149- if len (endpointSlices ) > 0 {
150- upstream .Nodes = t .translateEndpointSliceForIngress (1 , endpointSlices , getServicePort )
151- }
152-
153- // if there is no upstream node, create a placeholder node
154- if len (upstream .Nodes ) == 0 {
155- upstream .Nodes = adctypes.UpstreamNodes {}
156158 }
157159
158160 service .Upstream = upstream
0 commit comments