Skip to content

Commit afc6cdc

Browse files
committed
feat: Add support for ApisixUpstream reconciliation and enhance upstream handling
- Remove legacy ApisixUpstream controller. - Update related CRDs and deepcopy functions. - Add new translator logic for ApisixUpstream. - Introduce indexing and mapping logic for ApisixUpstream in ApisixRoute reconciliation.
1 parent 6e87cc6 commit afc6cdc

File tree

11 files changed

+596
-143
lines changed

11 files changed

+596
-143
lines changed

api/adc/types.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,108 @@ type Upstream struct {
206206
Timeout *Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
207207
Type UpstreamType `json:"type,omitempty" yaml:"type,omitempty"`
208208
UpstreamHost string `json:"upstream_host,omitempty" yaml:"upstream_host,omitempty"`
209+
210+
Checks *UpstreamHealthCheck `json:"checks,omitempty" yaml:"checks,omitempty"`
211+
TLS *ClientTLS `json:"tls,omitempty" yaml:"tls,omitempty"`
212+
// for Service Discovery
213+
DiscoveryType string `json:"discovery_type,omitempty" yaml:"discovery_type,omitempty"`
214+
DiscoveryArgs map[string]string `json:"discovery_args,omitempty" yaml:"discovery_args,omitempty"`
215+
}
216+
217+
// UpstreamHealthCheck defines the active and/or passive health check for an Upstream,
218+
// with the upstream health check feature, pods can be kicked out or joined in quickly,
219+
// if the feedback of Kubernetes liveness/readiness probe is long.
220+
// +k8s:deepcopy-gen=true
221+
type UpstreamHealthCheck struct {
222+
Active *UpstreamActiveHealthCheck `json:"active" yaml:"active"`
223+
Passive *UpstreamPassiveHealthCheck `json:"passive,omitempty" yaml:"passive,omitempty"`
224+
}
225+
226+
// ClientTLS is tls cert and key use in mTLS
227+
// +k8s:deepcopy-gen=true
228+
type ClientTLS struct {
229+
Cert string `json:"client_cert,omitempty" yaml:"client_cert,omitempty"`
230+
Key string `json:"client_key,omitempty" yaml:"client_key,omitempty"`
231+
}
232+
233+
// UpstreamActiveHealthCheck defines the active kind of upstream health check.
234+
// +k8s:deepcopy-gen=true
235+
type UpstreamActiveHealthCheck struct {
236+
Type string `json:"type,omitempty" yaml:"type,omitempty"`
237+
Timeout int `json:"timeout,omitempty" yaml:"timeout,omitempty"`
238+
Concurrency int `json:"concurrency,omitempty" yaml:"concurrency,omitempty"`
239+
Host string `json:"host,omitempty" yaml:"host,omitempty"`
240+
Port int32 `json:"port,omitempty" yaml:"port,omitempty"`
241+
HTTPPath string `json:"http_path,omitempty" yaml:"http_path,omitempty"`
242+
HTTPSVerifyCert bool `json:"https_verify_certificate,omitempty" yaml:"https_verify_certificate,omitempty"`
243+
HTTPRequestHeaders []string `json:"req_headers,omitempty" yaml:"req_headers,omitempty"`
244+
Healthy UpstreamActiveHealthCheckHealthy `json:"healthy,omitempty" yaml:"healthy,omitempty"`
245+
Unhealthy UpstreamActiveHealthCheckUnhealthy `json:"unhealthy,omitempty" yaml:"unhealthy,omitempty"`
246+
}
247+
248+
// UpstreamPassiveHealthCheck defines the passive kind of upstream health check.
249+
// +k8s:deepcopy-gen=true
250+
type UpstreamPassiveHealthCheck struct {
251+
Type string `json:"type,omitempty" yaml:"type,omitempty"`
252+
Healthy UpstreamPassiveHealthCheckHealthy `json:"healthy,omitempty" yaml:"healthy,omitempty"`
253+
Unhealthy UpstreamPassiveHealthCheckUnhealthy `json:"unhealthy,omitempty" yaml:"unhealthy,omitempty"`
254+
}
255+
256+
// UpstreamActiveHealthCheckHealthy defines the conditions to judge whether
257+
// an upstream node is healthy with the active manner.
258+
// +k8s:deepcopy-gen=true
259+
type UpstreamActiveHealthCheckHealthy struct {
260+
UpstreamPassiveHealthCheckHealthy `json:",inline" yaml:",inline"`
261+
262+
Interval int `json:"interval,omitempty" yaml:"interval,omitempty"`
263+
}
264+
265+
// UpstreamPassiveHealthCheckHealthy defines the conditions to judge whether
266+
// an upstream node is healthy with the passive manner.
267+
// +k8s:deepcopy-gen=true
268+
type UpstreamPassiveHealthCheckHealthy struct {
269+
HTTPStatuses []int `json:"http_statuses,omitempty" yaml:"http_statuses,omitempty"`
270+
Successes int `json:"successes,omitempty" yaml:"successes,omitempty"`
271+
}
272+
273+
// UpstreamPassiveHealthCheckUnhealthy defines the conditions to judge whether
274+
// an upstream node is unhealthy with the passive manager.
275+
// +k8s:deepcopy-gen=true
276+
type UpstreamPassiveHealthCheckUnhealthy struct {
277+
HTTPStatuses []int `json:"http_statuses,omitempty" yaml:"http_statuses,omitempty"`
278+
HTTPFailures int `json:"http_failures,omitempty" yaml:"http_failures,omitempty"`
279+
TCPFailures int `json:"tcp_failures,omitempty" yaml:"tcp_failures,omitempty"`
280+
Timeouts int `json:"timeouts,omitempty" yaml:"timeouts,omitempty"`
281+
}
282+
283+
// UpstreamActiveHealthCheckUnhealthy defines the conditions to judge whether
284+
// an upstream node is unhealthy with the active manager.
285+
// +k8s:deepcopy-gen=true
286+
type UpstreamActiveHealthCheckUnhealthy struct {
287+
UpstreamPassiveHealthCheckUnhealthy `json:",inline" yaml:",inline"`
288+
289+
Interval int `json:"interval,omitempty" yaml:"interval,omitempty"`
290+
}
291+
292+
// TrafficSplitConfig is the config of traffic-split plugin.
293+
// +k8s:deepcopy-gen=true
294+
type TrafficSplitConfig struct {
295+
Rules []TrafficSplitConfigRule `json:"rules"`
296+
}
297+
298+
// TrafficSplitConfigRule is the rule config in traffic-split plugin config.
299+
// +k8s:deepcopy-gen=true
300+
type TrafficSplitConfigRule struct {
301+
WeightedUpstreams []TrafficSplitConfigRuleWeightedUpstream `json:"weighted_upstreams"`
302+
}
303+
304+
// TrafficSplitConfigRuleWeightedUpstream is the weighted upstream config in
305+
// the traffic split plugin rule.
306+
// +k8s:deepcopy-gen=true
307+
type TrafficSplitConfigRuleWeightedUpstream struct {
308+
UpstreamID string `json:"upstream_id,omitempty"`
309+
Upstream *Upstream `json:"upstream,omitempty"`
310+
Weight int `json:"weight"`
209311
}
210312

211313
// +k8s:deepcopy-gen=true

api/adc/zz_generated.deepcopy.go

Lines changed: 232 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/apisixupstream_types.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,14 @@ type ApisixUpstreamSpec struct {
3636
PortLevelSettings []PortLevelSettings `json:"portLevelSettings,omitempty" yaml:"portLevelSettings,omitempty"`
3737
}
3838

39-
// ApisixUpstreamStatus defines the observed state of ApisixUpstream.
40-
type ApisixUpstreamStatus = ApisixStatus
41-
4239
// +kubebuilder:object:root=true
43-
// +kubebuilder:subresource:status
4440

4541
// ApisixUpstream is the Schema for the apisixupstreams API.
4642
type ApisixUpstream struct {
4743
metav1.TypeMeta `json:",inline"`
4844
metav1.ObjectMeta `json:"metadata,omitempty"`
4945

50-
Spec ApisixUpstreamSpec `json:"spec,omitempty"`
51-
Status ApisixUpstreamStatus `json:"status,omitempty"`
46+
Spec ApisixUpstreamSpec `json:"spec,omitempty"`
5247
}
5348

5449
// +kubebuilder:object:root=true
@@ -86,7 +81,7 @@ type ApisixUpstreamConfig struct {
8681
// How many times that the proxy (Apache APISIX) should do when
8782
// errors occur (error, timeout or bad http status codes like 500, 502).
8883
// +kubebuilder:validation:Optional
89-
Retries *int `json:"retries,omitempty" yaml:"retries,omitempty"`
84+
Retries *int64 `json:"retries,omitempty" yaml:"retries,omitempty"`
9085

9186
// Timeout settings for the read, send and connect to the upstream.
9287
// +kubebuilder:validation:Optional

0 commit comments

Comments
 (0)