Skip to content

Commit

Permalink
chore: add CheckHTTPStatuses to LoadBalancerRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ikadix committed Nov 16, 2023
1 parent 05407be commit d648558
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 47 deletions.
68 changes: 39 additions & 29 deletions core/load_balancer_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,32 @@ const (
HTTPProtocol Protocol = "HTTP"
)

type HTTPStatuses string

const (
HTTPStatusesAll2xx HTTPStatuses = "2"
HTTPStatusesAll2xxAnd3xx HTTPStatuses = "23"
HTTPStatusesAll2xxAnd3xxAnd4xx HTTPStatuses = "234"
)

type LoadBalancerRule struct {
ID string `json:"id,omitempty"`
Algorithm LoadBalancerRuleAlgorithm `json:"algorithm,omitempty"`
DestinationPort int `json:"destination_port,omitempty"`
ListenPort int `json:"listen_port,omitempty"`
Protocol Protocol `json:"protocol,omitempty"`
ProxyProtocol bool `json:"proxy_protocol,omitempty"`
Certificates []Certificate `json:"certificates,omitempty"`
BackendSSL bool `json:"backend_ssl,omitempty"`
PassthroughSSL bool `json:"passthrough_ssl,omitempty"`
CheckEnabled bool `json:"check_enabled,omitempty"`
CheckFall int `json:"check_fall,omitempty"`
CheckInterval int `json:"check_interval,omitempty"`
CheckPath string `json:"check_path,omitempty"`
CheckProtocol Protocol `json:"check_protocol,omitempty"`
CheckRise int `json:"check_rise,omitempty"`
CheckTimeout int `json:"check_timeout,omitempty"`
ID string `json:"id,omitempty"`
Algorithm LoadBalancerRuleAlgorithm `json:"algorithm,omitempty"`
DestinationPort int `json:"destination_port,omitempty"`
ListenPort int `json:"listen_port,omitempty"`
Protocol Protocol `json:"protocol,omitempty"`
ProxyProtocol bool `json:"proxy_protocol,omitempty"`
Certificates []Certificate `json:"certificates,omitempty"`
BackendSSL bool `json:"backend_ssl,omitempty"`
PassthroughSSL bool `json:"passthrough_ssl,omitempty"`
CheckEnabled bool `json:"check_enabled,omitempty"`
CheckFall int `json:"check_fall,omitempty"`
CheckInterval int `json:"check_interval,omitempty"`
CheckPath string `json:"check_path,omitempty"`
CheckProtocol Protocol `json:"check_protocol,omitempty"`
CheckRise int `json:"check_rise,omitempty"`
CheckTimeout int `json:"check_timeout,omitempty"`
CheckHTTPStatuses HTTPStatuses `json:"check_http_statuses,omitempty"`
}

func (lbr *LoadBalancerRule) Ref() LoadBalancerRuleRef {
Expand All @@ -60,19 +69,20 @@ func (lbr LoadBalancerRuleRef) queryValues() *url.Values {
}

type LoadBalancerRuleArguments struct {
Algorithm LoadBalancerRuleAlgorithm `json:"algorithm,omitempty"`
DestinationPort int `json:"destination_port,omitempty"`
ListenPort int `json:"listen_port,omitempty"`
Protocol Protocol `json:"protocol,omitempty"`
ProxyProtocol *bool `json:"proxy_protocol,omitempty"`
Certificates *[]CertificateRef `json:"certificates,omitempty"`
CheckEnabled *bool `json:"check_enabled,omitempty"`
CheckFall int `json:"check_fall,omitempty"`
CheckInterval int `json:"check_interval,omitempty"`
CheckPath string `json:"check_path,omitempty"`
CheckProtocol Protocol `json:"check_protocol,omitempty"`
CheckRise int `json:"check_rise,omitempty"`
CheckTimeout int `json:"check_timeout,omitempty"`
Algorithm LoadBalancerRuleAlgorithm `json:"algorithm,omitempty"`
DestinationPort int `json:"destination_port,omitempty"`
ListenPort int `json:"listen_port,omitempty"`
Protocol Protocol `json:"protocol,omitempty"`
ProxyProtocol *bool `json:"proxy_protocol,omitempty"`
Certificates *[]CertificateRef `json:"certificates,omitempty"`
CheckEnabled *bool `json:"check_enabled,omitempty"`
CheckFall int `json:"check_fall,omitempty"`
CheckInterval int `json:"check_interval,omitempty"`
CheckPath string `json:"check_path,omitempty"`
CheckProtocol Protocol `json:"check_protocol,omitempty"`
CheckRise int `json:"check_rise,omitempty"`
CheckTimeout int `json:"check_timeout,omitempty"`
CheckHTTPStatuses HTTPStatuses `json:"check_http_statuses,omitempty"`
}

type loadBalancerRulesResponseBody struct {
Expand Down
34 changes: 18 additions & 16 deletions core/load_balancer_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ func TestLoadBalancerRule_JSONMarshalling(t *testing.T) {
Name: "cluster-42",
},
},
BackendSSL: true,
PassthroughSSL: true,
CheckEnabled: true,
CheckFall: 3,
CheckInterval: 50,
CheckPath: "/healthz",
CheckProtocol: HTTPProtocol,
CheckRise: 12,
CheckTimeout: 3,
BackendSSL: true,
PassthroughSSL: true,
CheckEnabled: true,
CheckFall: 3,
CheckInterval: 50,
CheckPath: "/healthz",
CheckProtocol: HTTPProtocol,
CheckRise: 12,
CheckTimeout: 3,
CheckHTTPStatuses: HTTPStatusesAll2xx,
},
},
}
Expand Down Expand Up @@ -107,13 +108,14 @@ func TestLoadBalancerRuleArguments_JSONMarshalling(t *testing.T) {
ID: "another abitrary string",
},
},
CheckEnabled: boolPtr(false),
CheckFall: 3,
CheckInterval: 50,
CheckPath: "/healthz",
CheckProtocol: HTTPProtocol,
CheckRise: 12,
CheckTimeout: 3,
CheckEnabled: boolPtr(false),
CheckFall: 3,
CheckInterval: 50,
CheckPath: "/healthz",
CheckProtocol: HTTPProtocol,
CheckRise: 12,
CheckTimeout: 3,
CheckHTTPStatuses: HTTPStatusesAll2xxAnd3xxAnd4xx,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"check_path": "/healthz",
"check_protocol": "HTTP",
"check_rise": 12,
"check_timeout": 3
"check_timeout": 3,
"check_http_statuses": "234"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"check_path": "/healthz",
"check_protocol": "HTTP",
"check_rise": 12,
"check_timeout": 3
"check_timeout": 3,
"check_http_statuses": "2"
}

0 comments on commit d648558

Please sign in to comment.