@@ -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,39 @@ 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+ defaultServicePort := 80
131+ if servicePort > 0 {
132+ defaultServicePort = int (servicePort )
141133 }
142- if servicePortName != "" && port .Name == servicePortName {
143- getServicePort = & port
144- break
134+ upstream .Nodes = adctypes.UpstreamNodes {
135+ {
136+ Host : getService .Spec .ExternalName ,
137+ Port : defaultServicePort ,
138+ Weight : 1 ,
139+ },
140+ }
141+ } else {
142+ var getServicePort * corev1.ServicePort
143+ for _ , port := range getService .Spec .Ports {
144+ port := port
145+ if servicePort > 0 && port .Port == servicePort {
146+ getServicePort = & port
147+ break
148+ }
149+ if servicePortName != "" && port .Name == servicePortName {
150+ getServicePort = & port
151+ break
152+ }
153+ }
154+ endpointSlices := tctx .EndpointSlices [types.NamespacedName {
155+ Namespace : obj .Namespace ,
156+ Name : backendService .Name ,
157+ }]
158+ // convert the EndpointSlice to upstream nodes
159+ if len (endpointSlices ) > 0 {
160+ upstream .Nodes = t .translateEndpointSliceForIngress (1 , endpointSlices , getServicePort )
145161 }
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 {}
156162 }
157163
158164 service .Upstream = upstream
0 commit comments