Skip to content

Commit

Permalink
adds fields to the types and apisix_upstream file
Browse files Browse the repository at this point in the history
  • Loading branch information
slayer321 committed Oct 16, 2024
1 parent 78354fd commit 80e4d8e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/kube/apisix/apis/config/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions pkg/providers/translation/apisix_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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{
Expand Down
15 changes: 15 additions & 0 deletions pkg/types/apisix/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand All @@ -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,
Expand All @@ -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"`
Expand All @@ -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,
Expand Down

0 comments on commit 80e4d8e

Please sign in to comment.