Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Incorrect conversion between integer types #2397

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/xds/translator/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (t *Translator) createRateLimitServiceCluster(tCtx *types.ResourceVersionTa
ds := &ir.DestinationSetting{
Weight: ptr.To[uint32](1),
Protocol: ir.GRPC,
Endpoints: []*ir.DestinationEndpoint{ir.NewDestEndpoint(host, uint32(port))},
Endpoints: []*ir.DestinationEndpoint{ir.NewDestEndpoint(host, port)},
}

tSocket, err := buildRateLimitTLSocket()
Expand Down Expand Up @@ -498,14 +498,14 @@ func getRateLimitDomain(irListener *ir.HTTPListener) string {
return irListener.Name
}

func (t *Translator) getRateLimitServiceGrpcHostPort() (string, int) {
func (t *Translator) getRateLimitServiceGrpcHostPort() (string, uint32) {
u, err := url.Parse(t.GlobalRateLimit.ServiceURL)
if err != nil {
panic(err)
}
p, err := strconv.Atoi(u.Port())
p, err := strconv.ParseUint(u.Port(), 10, 32)
if err != nil {
panic(err)
}
return u.Hostname(), p
return u.Hostname(), uint32(p)
}
8 changes: 4 additions & 4 deletions internal/xds/translator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
)

const (
defaultHTTPSPort = 443
defaultHTTPPort = 80
defaultHTTPSPort uint64 = 443
defaultHTTPPort uint64 = 80
)

// urlCluster is a cluster that is created from a URL.
Expand All @@ -47,15 +47,15 @@ func url2Cluster(strURL string, secure bool) (*urlCluster, error) {
return nil, fmt.Errorf("unsupported URI scheme %s", u.Scheme)
}

var port int
var port uint64
if u.Scheme == "https" {
port = defaultHTTPSPort
} else {
port = defaultHTTPPort
}

if u.Port() != "" {
port, err = strconv.Atoi(u.Port())
port, err = strconv.ParseUint(u.Port(), 10, 32)
if err != nil {
return nil, err
}
Expand Down