@@ -543,6 +543,24 @@ func (t *Translator) TranslateHTTPRoute(tctx *provider.TranslateContext, httpRou
543543
544544 t .AttachBackendTrafficPolicyToUpstream (backend .BackendRef , tctx .BackendTrafficPolicies , upstream )
545545 upstream .Nodes = upNodes
546+
547+ var (
548+ kind string
549+ port int32
550+ )
551+ if backend .Kind == nil {
552+ kind = "Service"
553+ } else {
554+ kind = string (* backend .Kind )
555+ }
556+ if backend .Port != nil {
557+ port = int32 (* backend .Port )
558+ }
559+ namespace := string (* backend .Namespace )
560+ name := string (backend .Name )
561+ upstreamName := adctypes .ComposeUpstreamNameForBackendRef (kind , namespace , name , port )
562+ upstream .Name = upstreamName
563+ upstream .ID = id .GenID (upstreamName )
546564 upstreams = append (upstreams , upstream )
547565 }
548566
@@ -554,11 +572,22 @@ func (t *Translator) TranslateHTTPRoute(tctx *provider.TranslateContext, httpRou
554572 } else if len (upstreams ) == 1 {
555573 // Single backend - use directly as service upstream
556574 service .Upstream = upstreams [0 ]
575+ // remove the id and name of the service.upstream, adc schema does not need id and name for it
576+ service .Upstream .ID = ""
577+ service .Upstream .Name = ""
557578 } else {
558579 // Multiple backends - use traffic-split plugin
559580 service .Upstream = upstreams [0 ]
581+ // remove the id and name of the service.upstream, adc schema does not need id and name for it
582+ service .Upstream .ID = ""
583+ service .Upstream .Name = ""
584+
560585 upstreams = upstreams [1 :]
561586
587+ if len (upstreams ) > 0 {
588+ service .Upstreams = upstreams
589+ }
590+
562591 // Set weight in traffic-split for the default upstream
563592 weight := apiv2 .DefaultWeight
564593 if rule .BackendRefs [0 ].Weight != nil {
@@ -568,16 +597,16 @@ func (t *Translator) TranslateHTTPRoute(tctx *provider.TranslateContext, httpRou
568597 Weight : weight ,
569598 })
570599
571- // Set other upstreams in traffic-split
600+ // Set other upstreams in traffic-split using upstream_id
572601 for i , upstream := range upstreams {
573602 weight := apiv2 .DefaultWeight
574603 // get weight from the backend refs starting from the second backend
575604 if i + 1 < len (rule .BackendRefs ) && rule .BackendRefs [i + 1 ].Weight != nil {
576605 weight = int (* rule .BackendRefs [i + 1 ].Weight )
577606 }
578607 weightedUpstreams = append (weightedUpstreams , adctypes.TrafficSplitConfigRuleWeightedUpstream {
579- Upstream : upstream ,
580- Weight : weight ,
608+ UpstreamID : upstream . ID ,
609+ Weight : weight ,
581610 })
582611 }
583612
0 commit comments