Skip to content

Commit 1d99fad

Browse files
authored
backport: part 2 (#241)
1 parent 1726af5 commit 1d99fad

File tree

4 files changed

+561
-5
lines changed

4 files changed

+561
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/go-logr/zapr v1.3.0
1313
github.com/google/go-cmp v0.6.0
1414
github.com/google/uuid v1.6.0
15+
github.com/gorilla/websocket v1.5.1
1516
github.com/gruntwork-io/terratest v0.47.0
1617
github.com/hashicorp/go-memdb v1.3.4
1718
github.com/hashicorp/go-multierror v1.1.1
@@ -106,7 +107,6 @@ require (
106107
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
107108
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
108109
github.com/gorilla/mux v1.8.0 // indirect
109-
github.com/gorilla/websocket v1.5.1 // indirect
110110
github.com/gosuri/uitable v0.0.4 // indirect
111111
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
112112
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect

internal/adc/translator/apisixroute.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (t *Translator) buildRoute(ar *apiv2.ApisixRoute, service *adc.Service, rul
177177
route.ID = id.GenID(route.Name)
178178
route.Desc = "Created by apisix-ingress-controller, DO NOT modify it manually"
179179
route.Labels = label.GenLabel(ar)
180-
route.EnableWebsocket = ptr.To(true)
180+
route.EnableWebsocket = ptr.To(rule.Websocket)
181181
route.FilterFunc = rule.Match.FilterFunc
182182
route.Hosts = rule.Match.Hosts
183183
route.Methods = rule.Match.Methods
@@ -198,10 +198,10 @@ func (t *Translator) buildUpstream(tctx *provider.TranslateContext, service *adc
198198
var (
199199
upstreams = make([]*adc.Upstream, 0)
200200
weightedUpstreams = make([]adc.TrafficSplitConfigRuleWeightedUpstream, 0)
201-
backendErr error
202201
)
203202

204203
for _, backend := range rule.Backends {
204+
var backendErr error
205205
upstream := adc.NewDefaultUpstream()
206206
// try to get the apisixupstream with the same name as the backend service to be upstream config.
207207
// err is ignored because it does not care about the externalNodes of the apisixupstream.
@@ -223,7 +223,9 @@ func (t *Translator) buildUpstream(tctx *provider.TranslateContext, service *adc
223223
continue
224224
}
225225
}
226-
226+
if backend.Weight != nil {
227+
upstream.Labels["meta_weight"] = strconv.FormatInt(int64(*backend.Weight), 10)
228+
}
227229
upstreams = append(upstreams, upstream)
228230
}
229231

@@ -250,7 +252,7 @@ func (t *Translator) buildUpstream(tctx *provider.TranslateContext, service *adc
250252
}
251253

252254
// no valid upstream
253-
if backendErr != nil || len(upstreams) == 0 || len(upstreams[0].Nodes) == 0 {
255+
if len(upstreams) == 0 || len(upstreams[0].Nodes) == 0 {
254256
return
255257
}
256258

0 commit comments

Comments
 (0)