Skip to content

Commit 826bcaf

Browse files
feat(circuit-breaker): add the circuit breaker feature
1 parent 2491c0f commit 826bcaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2725
-178
lines changed

admin/api/v1/zone_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type GatewayAdminConfig struct {
4444
type GatewayConfig struct {
4545
Admin GatewayAdminConfig `json:"admin"`
4646
Url string `json:"url"`
47+
// CircuitBreaker flag that controls if circuit breaker should be enabled on this zone. the config of the CB itself comes from hardcoded values, not configurable
48+
CircuitBreaker bool `json:"circuitBreaker"`
4749
}
4850

4951
type ApiConfig struct {

admin/config/crd/bases/admin.cp.ei.telekom.de_zones.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ spec:
5555
required:
5656
- clientSecret
5757
type: object
58+
circuitBreaker:
59+
description: CircuitBreaker flag that controls if circuit breaker
60+
should be enabled on this zone. the config of the CB itself
61+
comes from hardcoded values, not configurable
62+
type: boolean
5863
url:
5964
type: string
6065
required:
6166
- admin
67+
- circuitBreaker
6268
- url
6369
type: object
6470
identityProvider:

admin/internal/handler/zone/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ func createGateway(ctx context.Context, handlingContext HandlingContext) (*gatew
322322
EnableTLS: handlingContext.Zone.Spec.Redis.EnableTLS,
323323
},
324324
}
325+
325326
return nil
326327
}
327328
_, err := scopedClient.CreateOrUpdate(ctx, gateway, mutator)

api/api/v1/apiexposure_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ func (a *ApiExposure) HasOverriddenSubscriberRateLimit() bool {
9898
return len(a.Spec.Traffic.RateLimit.SubscriberRateLimit.Overrides) > 0
9999
}
100100

101+
func (a *ApiExposure) HasCircuitBreaker() bool {
102+
return a.Spec.Traffic.CircuitBreaker != nil
103+
}
104+
101105
func (a *ApiExposure) GetOverriddenSubscriberRateLimit(subscriber string) (Limits, bool) {
102106
if !a.HasOverriddenSubscriberRateLimit() {
103107
return Limits{}, false

api/api/v1/traffic_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ type Traffic struct {
1717
// RateLimit defines request rate limiting for this API
1818
// +kubebuilder:validation:Optional
1919
RateLimit *RateLimit `json:"rateLimit,omitempty"`
20+
// CircuitBreaker defines the Kong circuit breaker configuration
21+
// +kubebuilder:validation:Optional
22+
CircuitBreaker *CircuitBreaker `json:"circuitBreaker,omitempty"`
23+
}
24+
25+
type CircuitBreaker struct {
26+
// CircuitBreaker flags if the Kong circuit breaker feature should be used
27+
// kubebuilder:default=false
28+
Enabled bool `json:"enabled,omitempty"`
2029
}
2130

2231
type SubscriberTraffic struct {

api/api/v1/zz_generated.deepcopy.go

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

api/config/crd/bases/api.cp.ei.telekom.de_apiexposures.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ spec:
190190
type: object
191191
traffic:
192192
properties:
193+
circuitBreaker:
194+
description: CircuitBreaker defines the Kong circuit breaker configuration
195+
properties:
196+
enabled:
197+
description: |-
198+
CircuitBreaker flags if the Kong circuit breaker feature should be used
199+
kubebuilder:default=false
200+
type: boolean
201+
type: object
193202
failover:
194203
description: Failover defines the failover configuration for the
195204
API exposure.

api/internal/handler/util/route_util.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ func CreateRealRoute(ctx context.Context, downstreamZoneRef types.ObjectRef, api
375375
route.Spec.Traffic.RateLimit = mapProviderRateLimitToGatewayRateLimit(apiExposure.Spec.Traffic.RateLimit.Provider)
376376
}
377377

378+
// switch from pointer to non-pointer (
379+
if apiExposure.HasCircuitBreaker() {
380+
route.Spec.Traffic.CircuitBreaker = mapCircuitBreaker(apiExposure.Spec.Traffic.CircuitBreaker)
381+
}
382+
378383
return nil
379384
}
380385

@@ -529,6 +534,16 @@ func mapProviderRateLimitToGatewayRateLimit(apiRateLimitConfig *apiapi.RateLimit
529534
}
530535
}
531536

537+
func mapCircuitBreaker(cb *apiapi.CircuitBreaker) *gatewayapi.CircuitBreaker {
538+
circuitBreaker := &gatewayapi.CircuitBreaker{}
539+
if cb == nil {
540+
circuitBreaker.Enabled = false
541+
} else {
542+
circuitBreaker.Enabled = cb.Enabled
543+
}
544+
return circuitBreaker
545+
}
546+
532547
func mapLimitsToGatewayLimits(apiLimits apiapi.Limits) gatewayapi.Limits {
533548
return gatewayapi.Limits{
534549
Second: apiLimits.Second,

gateway/api/v1/features.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const (
1212
FeatureTypeAccessControl FeatureType = "AccessControl"
1313
FeatureTypeRateLimit FeatureType = "RateLimit"
1414
FeatureTypeHeaderTransformation FeatureType = "HeaderTransformation"
15-
FeatureTypeBasicAuth FeatureType = "BasicAuth"
16-
FeatureTypeIpRestriction FeatureType = "IpRestriction"
15+
FeatureTypeBasicAuth FeatureType = "BasicAuth"
16+
FeatureTypeIpRestriction FeatureType = "IpRestriction"
17+
FeatureTypeCircuitBreaker FeatureType = "CircuitBreaker"
1718
)
1819

1920
// Dependent Features

gateway/api/v1/route_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ func (g *Route) SetServiceId(id string) {
171171
g.SetProperty("serviceId", id)
172172
}
173173

174+
func (g *Route) SetUpstreamId(id string) {
175+
g.SetProperty("upstreamId", id)
176+
}
177+
178+
func (g *Route) SetTargetsId(id string) {
179+
g.SetProperty("targetsId", id)
180+
}
181+
182+
func (g *Route) GetUpstreamId() string {
183+
return g.GetProperty("upstreamId")
184+
}
185+
186+
func (g *Route) GetTargetsId() string {
187+
return g.GetProperty("targetsId")
188+
}
189+
174190
func (g *Route) SetProperty(key, val string) {
175191
if g.Status.Properties == nil {
176192
g.Status.Properties = make(map[string]string)

0 commit comments

Comments
 (0)