diff --git a/pkg/kube/apisix/apis/config/v2/types.go b/pkg/kube/apisix/apis/config/v2/types.go index 9186d1d97e..f3730cb23e 100644 --- a/pkg/kube/apisix/apis/config/v2/types.go +++ b/pkg/kube/apisix/apis/config/v2/types.go @@ -619,11 +619,11 @@ type LoadBalancer struct { type KeepAlivePool struct { // Represents the maximum number of connections that the pool can hold - Size int `json:"size" yaml:"size"` + Size int `json:"size,omitempty" yaml:"size,omitempty"` // Specifies the duration for which a connection can remain idle (not in use) before it is closed - IdleTimeout time.Duration `json:"idle_timeout" yaml:"idle_timeout"` + IdleTimeout int `json:"idle_timeout,omitempty" yaml:"idle_timeout,omitempty"` // number of requests that can be handled - Request int `json:"request" yaml:"request"` + Request int `json:"requests,omitempty" yaml:"requests,omitempty"` } // HealthCheck describes the upstream health check parameters. diff --git a/pkg/providers/translation/apisix_upstream.go b/pkg/providers/translation/apisix_upstream.go index 44aca7ba9b..04a559cb63 100644 --- a/pkg/providers/translation/apisix_upstream.go +++ b/pkg/providers/translation/apisix_upstream.go @@ -34,6 +34,10 @@ func (t *translator) TranslateUpstreamConfigV2(au *configv2.ApisixUpstreamConfig if err := t.translateUpstreamLoadBalancerV2(au.LoadBalancer, ups); err != nil { return nil, err } + + if err := t.translateKeepAlivePool(au.KeepAlivePool, ups); err != nil { + return nil, err + } if err := t.translateUpstreamHealthCheckV2(au.HealthCheck, ups); err != nil { return nil, err } @@ -66,6 +70,40 @@ func (t *translator) translateUpstreamScheme(scheme string, ups *apisixv1.Upstre } } +func (t *translator) translateKeepAlivePool(keepAlive *configv2.KeepAlivePool, ups *apisixv1.Upstream) error { + + if keepAlive.Size < 1 { + return &TranslateError{ + Field: "size", + Reason: "invalid value, must be one or greater", + } + } else if keepAlive.Size >= 1 { + ups.Size = keepAlive.Size + + } + + if keepAlive.IdleTimeout < 0 { + return &TranslateError{ + Field: "idle_timeout", + Reason: "invalid value", + } + } else if keepAlive.IdleTimeout >= 0 { + ups.IdleTimeout = int(keepAlive.IdleTimeout) + } + + if keepAlive.Request < 1 { + return &TranslateError{ + Field: "request", + Reason: "invalid value, must be one or greater", + } + } else if keepAlive.Request >= 1 { + ups.Request = keepAlive.Request + } + + return nil + +} + func (t *translator) translateUpstreamRetriesAndTimeoutV2(retries *int, timeout *configv2.UpstreamTimeout, ups *apisixv1.Upstream) error { if retries != nil && *retries < 0 { return &TranslateError{ diff --git a/pkg/types/apisix/v1/types.go b/pkg/types/apisix/v1/types.go index a3695df66a..d799439fe1 100644 --- a/pkg/types/apisix/v1/types.go +++ b/pkg/types/apisix/v1/types.go @@ -214,6 +214,9 @@ type Upstream struct { TLS *ClientTLS `json:"tls,omitempty" yaml:"tls,omitempty"` PassHost string `json:"pass_host,omitempty" yaml:"pass_host,omitempty"` UpstreamHost string `json:"upstream_host,omitempty" yaml:"upstream_host,omitempty"` + Size int `json:"size,omitempty" yaml:"size,omitempty"` + IdleTimeout int `json:"idle_timeout,omitempty" yaml:"idle_timeout,omitempty"` + Request int `json:"request,omitempty" yaml:"request,omitempty"` // for Service Discovery ServiceName string `json:"service_name,omitempty" yaml:"service_name,omitempty"` @@ -286,6 +289,9 @@ func (up Upstream) MarshalJSON() ([]byte, error) { HostPass string `json:"pass_host,omitempty" yaml:"pass_host,omitempty"` UpstreamHost string `json:"upstream_host,omitempty" yaml:"upstream_host,omitempty"` TLS *ClientTLS `json:"tls,omitempty" yaml:"tls,omitempty"` + Size int `json:"size,omitempty" yaml:"size,omitempty"` + IdleTimeout int `json:"idle_timeout,omitempty" yaml:"idle_timeout,omitempty"` + Request int `json:"request,omitempty" yaml:"request,omitempty"` // for Service Discovery ServiceName string `json:"service_name,omitempty" yaml:"service_name,omitempty"` @@ -305,6 +311,9 @@ func (up Upstream) MarshalJSON() ([]byte, error) { HostPass: up.PassHost, UpstreamHost: up.UpstreamHost, TLS: up.TLS, + Size: up.Size, + IdleTimeout: up.IdleTimeout, + Request: up.Request, ServiceName: up.ServiceName, DiscoveryType: up.DiscoveryType, @@ -325,6 +334,9 @@ func (up Upstream) MarshalJSON() ([]byte, error) { HostPass string `json:"pass_host,omitempty" yaml:"pass_host,omitempty"` UpstreamHost string `json:"upstream_host,omitempty" yaml:"upstream_host,omitempty"` TLS *ClientTLS `json:"tls,omitempty" yaml:"tls,omitempty"` + Size int `json:"size,omitempty" yaml:"size,omitempty"` + IdleTimeout int `json:"idle_timeout,omitempty" yaml:"idle_timeout,omitempty"` + Request int `json:"request,omitempty" yaml:"request,omitempty"` // for Service Discovery //ServiceName string `json:"service_name,omitempty" yaml:"service_name,omitempty"` @@ -344,6 +356,9 @@ func (up Upstream) MarshalJSON() ([]byte, error) { HostPass: up.PassHost, UpstreamHost: up.UpstreamHost, TLS: up.TLS, + Size: up.Size, + IdleTimeout: up.IdleTimeout, + Request: up.Request, //ServiceName: up.ServiceName, //DiscoveryType: up.DiscoveryType,