Skip to content

Commit

Permalink
fix: missing upstream name in gateway-api routes (#1754)
Browse files Browse the repository at this point in the history
* fix: missing upstream name in gateway-api routes

Signed-off-by: Ling Samuel <lingsamuelgrace@gmail.com>

* fmt imports

Signed-off-by: Ling Samuel <lingsamuelgrace@gmail.com>

---------

Signed-off-by: Ling Samuel <lingsamuelgrace@gmail.com>
  • Loading branch information
lingsamuel committed Mar 31, 2023
1 parent db20b67 commit ea48465
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 119 deletions.
9 changes: 7 additions & 2 deletions pkg/providers/gateway/translation/gateway_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,20 @@ func (t *translator) TranslateGatewayHTTPRouteV1beta1(httpRoute *gatewayv1beta1.
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to translate Rules[%v].BackendRefs[%v]", i, j))
}
name := apisixv1.ComposeUpstreamName(ns, string(backend.Name), "", int32(*backend.Port), types.ResolveGranularity.Endpoint)
ups.Name = apisixv1.ComposeUpstreamName(ns, string(backend.Name), "", int32(*backend.Port), types.ResolveGranularity.Endpoint)

// APISIX limits max length of label value
// https://github.com/apache/apisix/blob/5b95b85faea3094d5e466ee2d39a52f1f805abbb/apisix/schema_def.lua#L85
ups.Labels["meta_namespace"] = utils.TruncateString(ns, 64)
ups.Labels["meta_backend"] = utils.TruncateString(string(backend.Name), 64)
ups.Labels["meta_port"] = fmt.Sprintf("%v", int32(*backend.Port))

ups.ID = id.GenID(name)
ups.ID = id.GenID(ups.Name)
log.Debugw("translated HTTPRoute upstream",
zap.Int("backendRefs_index", j),
zap.String("backendRefs_name", string(backend.Name)),
zap.String("name", ups.Name),
)
ctx.AddUpstream(ups)
ruleUpstreams = append(ruleUpstreams, ups)

Expand Down
Loading

0 comments on commit ea48465

Please sign in to comment.