Skip to content

Commit

Permalink
feat: route crd add timeout fields (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
Donghui0 authored Sep 1, 2021
1 parent a9960c2 commit d4a832c
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 14 deletions.
7 changes: 4 additions & 3 deletions pkg/kube/apisix/apis/config/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ type Http struct {

// Path defines an URI based route rule.
type Path struct {
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Backend Backend `json:"backend,omitempty" yaml:"backend,omitempty"`
Plugins []Plugin `json:"plugins,omitempty" yaml:"plugins,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Backend Backend `json:"backend,omitempty" yaml:"backend,omitempty"`
Timeout *UpstreamTimeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
Plugins []Plugin `json:"plugins,omitempty" yaml:"plugins,omitempty"`
}

// Backend defines an upstream, it should be an existing Kubernetes Service.
Expand Down
5 changes: 5 additions & 0 deletions pkg/kube/apisix/apis/config/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/kube/apisix/apis/config/v2alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type ApisixRouteHTTP struct {
// same URI path (for path matching), route with
// higher priority will take effect.
Priority int `json:"priority,omitempty" yaml:"priority,omitempty"`
Timeout *UpstreamTimeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
Match *ApisixRouteHTTPMatch `json:"match,omitempty" yaml:"match,omitempty"`
// Deprecated: Backend will be removed in the future, use Backends instead.
Backend *ApisixRouteHTTPBackend `json:"backend,omitempty" yaml:"backend,omitempty"`
Expand Down Expand Up @@ -195,6 +196,13 @@ type ApisixRouteHTTPPlugin struct {
// any plugins.
type ApisixRouteHTTPPluginConfig map[string]interface{}

// UpstreamTimeout is settings for the read, send and connect to the upstream.
type UpstreamTimeout struct {
Connect metav1.Duration `json:"connect,omitempty" yaml:"connect,omitempty"`
Send metav1.Duration `json:"send,omitempty" yaml:"send,omitempty"`
Read metav1.Duration `json:"read,omitempty" yaml:"read,omitempty"`
}

// ApisixRouteAuthentication is the authentication-related
// configuration in ApisixRoute.
type ApisixRouteAuthentication struct {
Expand Down
24 changes: 24 additions & 0 deletions pkg/kube/apisix/apis/config/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/kube/apisix/apis/config/v2beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ type ApisixRouteSpec struct {
Stream []ApisixRouteStream `json:"stream,omitempty" yaml:"stream,omitempty"`
}

// UpstreamTimeout is settings for the read, send and connect to the upstream.
type UpstreamTimeout struct {
Connect metav1.Duration `json:"connect,omitempty" yaml:"connect,omitempty"`
Send metav1.Duration `json:"send,omitempty" yaml:"send,omitempty"`
Read metav1.Duration `json:"read,omitempty" yaml:"read,omitempty"`
}

// ApisixRouteHTTP represents a single route in for HTTP traffic.
type ApisixRouteHTTP struct {
// The rule name, cannot be empty.
Expand All @@ -53,6 +60,7 @@ type ApisixRouteHTTP struct {
// same URI path (for path matching), route with
// higher priority will take effect.
Priority int `json:"priority,omitempty" yaml:"priority,omitempty"`
Timeout *UpstreamTimeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
Match ApisixRouteHTTPMatch `json:"match,omitempty" yaml:"match,omitempty"`
// Deprecated: Backend will be removed in the future, use Backends instead.
Backend v2alpha1.ApisixRouteHTTPBackend `json:"backend,omitempty" yaml:"backend,omitempty"`
Expand Down
24 changes: 24 additions & 0 deletions pkg/kube/apisix/apis/config/v2beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/kube/translation/apisix_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,22 @@ func (t *translator) translateHTTPRoute(ctx *TranslateContext, ar *configv2alpha
return err
}

timeout := &apisixv1.UpstreamTimeout{
Connect: apisixv1.DefaultUpstreamTimeout,
Read: apisixv1.DefaultUpstreamTimeout,
Send: apisixv1.DefaultUpstreamTimeout,
}
if part.Timeout != nil {
if part.Timeout.Connect.Duration > 0 {
timeout.Connect = int(part.Timeout.Connect.Seconds())
}
if part.Timeout.Read.Duration > 0 {
timeout.Read = int(part.Timeout.Read.Seconds())
}
if part.Timeout.Send.Duration > 0 {
timeout.Send = int(part.Timeout.Send.Seconds())
}
}
pluginMap := make(apisixv1.Plugins)
// 2.add route plugins
for _, plugin := range part.Plugins {
Expand Down Expand Up @@ -362,6 +378,7 @@ func (t *translator) translateHTTPRoute(ctx *TranslateContext, ar *configv2alpha
route.UpstreamId = id.GenID(upstreamName)
route.EnableWebsocket = part.Websocket
route.Plugins = pluginMap
route.Timeout = timeout

if len(backends) > 0 {
weight := _defaultWeight
Expand Down
23 changes: 12 additions & 11 deletions pkg/types/apisix/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@ type Metadata struct {
type Route struct {
Metadata `json:",inline" yaml:",inline"`

Host string `json:"host,omitempty" yaml:"host,omitempty"`
Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
Uri string `json:"uri,omitempty" yaml:"uri,omitempty"`
Priority int `json:"priority,omitempty" yaml:"priority,omitempty"`
Vars Vars `json:"vars,omitempty" yaml:"vars,omitempty"`
Uris []string `json:"uris,omitempty" yaml:"uris,omitempty"`
Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`
EnableWebsocket bool `json:"enable_websocket,omitempty" yaml:"enable_websocket,omitempty"`
RemoteAddrs []string `json:"remote_addrs,omitempty" yaml:"remote_addrs,omitempty"`
UpstreamId string `json:"upstream_id,omitempty" yaml:"upstream_id,omitempty"`
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
Host string `json:"host,omitempty" yaml:"host,omitempty"`
Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
Uri string `json:"uri,omitempty" yaml:"uri,omitempty"`
Priority int `json:"priority,omitempty" yaml:"priority,omitempty"`
Timeout *UpstreamTimeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
Vars Vars `json:"vars,omitempty" yaml:"vars,omitempty"`
Uris []string `json:"uris,omitempty" yaml:"uris,omitempty"`
Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`
EnableWebsocket bool `json:"enable_websocket,omitempty" yaml:"enable_websocket,omitempty"`
RemoteAddrs []string `json:"remote_addrs,omitempty" yaml:"remote_addrs,omitempty"`
UpstreamId string `json:"upstream_id,omitempty" yaml:"upstream_id,omitempty"`
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
}

// Vars represents the route match expressions of APISIX.
Expand Down
5 changes: 5 additions & 0 deletions pkg/types/apisix/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions samples/deploy/crd/v1beta1/ApisixRoute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ spec:
minLength: 1
priority:
type: integer
timeout:
type: object
properties:
connect:
type: string
send:
type: string
read:
type: string
match:
type: object
required:
Expand Down

0 comments on commit d4a832c

Please sign in to comment.