Skip to content

Commit

Permalink
add in OutputCachePolicy for ingress controller annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
witskeeper committed Nov 15, 2023
1 parent c9dbe0b commit e9eee3f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions samples/KubernetesIngress.Sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ metadata:
annotations:
yarp.ingress.kubernetes.io/authorization-policy: authzpolicy
yarp.ingress.kubernetes.io/rate-limiter-policy: ratelimiterpolicy
yarp.ingress.kubernetes.io/output-cache-policy: outputcachepolicy
yarp.ingress.kubernetes.io/transforms: |
- PathRemovePrefix: "/apis"
yarp.ingress.kubernetes.io/route-headers: |
- Name: the-header-key
Values:
Values:
- the-header-value
Mode: Contains
IsCaseSensitive: false
- Name: another-header-key
Values:
Values:
- another-header-value
Mode: Contains
IsCaseSensitive: false
Expand All @@ -75,6 +76,7 @@ The table below lists the available annotations.
|---|---|
|yarp.ingress.kubernetes.io/authorization-policy|string|
|yarp.ingress.kubernetes.io/rate-limiter-policy|string|
|yarp.ingress.kubernetes.io/output-cache-policy|string|
|yarp.ingress.kubernetes.io/backend-protocol|string|
|yarp.ingress.kubernetes.io/cors-policy|string|
|yarp.ingress.kubernetes.io/health-check|[ActivateHealthCheckConfig](https://microsoft.github.io/reverse-proxy/api/Yarp.ReverseProxy.Configuration.ActiveHealthCheckConfig.html)|
Expand All @@ -98,6 +100,10 @@ See https://microsoft.github.io/reverse-proxy/articles/rate-limiting.html for a

`yarp.ingress.kubernetes.io/rate-limiter-policy: mypolicy`

#### Output Cache Policy

`yarp.ingress.kubernetes.io/output-cache-policy: mycachepolicy`

#### Backend Protocol

Specifies the protocol of the backend service. Defaults to http.
Expand Down Expand Up @@ -196,12 +202,12 @@ See https://microsoft.github.io/reverse-proxy/api/Yarp.ReverseProxy.Configuratio
```
yarp.ingress.kubernetes.io/route-headers: |
- Name: the-header-key
Values:
Values:
- the-header-value
Mode: Contains
IsCaseSensitive: false
- Name: another-header-key
Values:
Values:
- another-header-value
Mode: Contains
IsCaseSensitive: false
Expand Down
1 change: 1 addition & 0 deletions src/Kubernetes.Controller/Converters/YarpIngressOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal sealed class YarpIngressOptions
public string AuthorizationPolicy { get; set; }
#if NET7_0_OR_GREATER
public string RateLimiterPolicy { get; set; }
public string OutputCachePolicy { get; set; }
#endif
public SessionAffinityConfig SessionAffinity { get; set; }
public HttpClientConfig HttpClientConfig { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions src/Kubernetes.Controller/Converters/YarpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private static RouteConfig CreateRoute(YarpIngressContext ingressContext, V1HTTP
AuthorizationPolicy = ingressContext.Options.AuthorizationPolicy,
#if NET7_0_OR_GREATER
RateLimiterPolicy = ingressContext.Options.RateLimiterPolicy,
OutputCachePolicy = ingressContext.Options.OutputCachePolicy,
#endif
#if NET8_0_OR_GREATER
Timeout = ingressContext.Options.Timeout,
Expand Down Expand Up @@ -234,6 +235,10 @@ private static YarpIngressOptions HandleAnnotations(YarpIngressContext context,
{
options.RateLimiterPolicy = rateLimiterPolicy;
}
if (annotations.TryGetValue("yarp.ingress.kubernetes.io/output-cache-policy", out var outputCachePolicy))
{
options.OutputCachePolicy = outputCachePolicy;
}
#endif
if (annotations.TryGetValue("yarp.ingress.kubernetes.io/cors-policy", out var corsPolicy))
{
Expand Down

0 comments on commit e9eee3f

Please sign in to comment.