This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
/
circuit_breaker.go
67 lines (54 loc) · 2.26 KB
/
circuit_breaker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package v1alpha1
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// CircuitBreaker creates a breaking point at which it will deliver a static
// response rather than continue sending traffic to a backend.
type CircuitBreaker struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec defines the circuit breaker spec for a destination's traffic
Spec CircuitBreakerSpec `json:"spec"`
}
// CircuitBreakerSpec defines the circuit breaker spec that restricts connections
// to the destination.
type CircuitBreakerSpec struct {
// Destination defines which destination to include in the circuit breaker
Destination v1.ObjectReference `json:"destination"`
// Defines a fallback service that should be routed to in the event that
// the circuit breaker trips, rather than returning an error.
// +optional
Fallback FallbackSpec `json:"fallback,omitempty"`
// Errors sets the number of errors before the circuit breaker trips
Errors int `json:"errors"`
// TimeoutSeconds sets the timeout the errors must fall within to trip the circuit
// breaker. Also defines how long the circuit breaker will be tripped before
// allowing connections to the destination again.
TimeoutSeconds int `json:"timeoutSeconds"`
}
// FallbackSpec defines the fallback service spec to redirect traffic to when
// a circuit trips.
type FallbackSpec struct {
// Service is the name of the Kubernetes Service to send traffic to.
// Should be of the form <namespace>/<name>. If namespace is not specified,
// defaults to the 'default' namespace.
// +optional
Service string `json:"service,omitempty"`
// Port is the port on the Service to send traffic to. Defaults to 80.
// +optional
Port int `json:"port,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// CircuitBreakerList satisfies K8s code gen requirements.
type CircuitBreakerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []CircuitBreaker `json:"items"`
}