Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update MeshRetry API with mergeable slice #5808

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -2271,6 +2274,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -2271,6 +2274,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -2468,6 +2471,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -2291,6 +2294,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -3442,6 +3445,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3519,6 +3519,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -3594,6 +3597,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
6 changes: 6 additions & 0 deletions deployments/charts/kuma/crds/kuma.io_meshretries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -213,6 +216,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugins/policies/meshretry/api/v1alpha1/meshretry.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ type RateLimitedBackOff struct {
// ResetHeaders specifies the list of headers (like Retry-After or X-RateLimit-Reset) to match against the response.
// Headers are tried in order, and matched case-insensitive. The first header to be parsed successfully is used.
// If no headers match the default exponential BackOff is used instead.
ResetHeaders []ResetHeader `json:"resetHeaders,omitempty"`
ResetHeaders *[]ResetHeader `json:"resetHeaders,omitempty"`
// MaxInterval is a maximal amount of time which will be taken between retries.
// Default is 300 seconds.
MaxInterval *k8s.Duration `json:"maxInterval,omitempty"`
Expand All @@ -242,9 +242,9 @@ var RateLimitFormatEnumToEnvoyValue = map[RateLimitFormat]envoy_route.RetryPolic

type ResetHeader struct {
// The Name of the reset header.
Name common_api.HeaderName `json:"name,omitempty"`
Name common_api.HeaderName `json:"name"`
// The format of the reset header, either Seconds or UnixTimestamp.
Format RateLimitFormat `json:"format,omitempty"`
Format RateLimitFormat `json:"format"`
}

type HeaderMatchType string
Expand Down
6 changes: 6 additions & 0 deletions pkg/plugins/policies/meshretry/api/v1alpha1/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ properties:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -138,6 +141,9 @@ properties:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
12 changes: 6 additions & 6 deletions pkg/plugins/policies/meshretry/api/v1alpha1/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ func validateRateLimitedBackOff(rateLimitedBackOff *RateLimitedBackOff) validato
verr.Add(validators.ValidateDurationGreaterThanZero(path.Field("maxInterval"), *rateLimitedBackOff.MaxInterval))
}

if len(rateLimitedBackOff.ResetHeaders) == 0 {
if rateLimitedBackOff.ResetHeaders == nil {
verr.AddViolationAt(path.Field("resetHeaders"), validators.MustBeDefined)
}

for i, header := range rateLimitedBackOff.ResetHeaders {
index := path.Field("resetHeaders").Index(i)
verr.Add(validators.ValidateStringDefined(index.Field("name"), string(header.Name)))
} else {
for i, header := range *rateLimitedBackOff.ResetHeaders {
index := path.Field("resetHeaders").Index(i)
verr.Add(validators.ValidateStringDefined(index.Field("name"), string(header.Name)))
}
}

return verr
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down Expand Up @@ -213,6 +216,9 @@ spec:
minLength: 1
pattern: ^[a-z0-9!#$%&'*+\-.^_\x60|~]+$
type: string
required:
- format
- name
type: object
type: array
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Describe("MeshRetry", func() {
},
RateLimitedBackOff: &api.RateLimitedBackOff{
MaxInterval: test.ParseDuration("5s"),
ResetHeaders: []api.ResetHeader{
ResetHeaders: &[]api.ResetHeader{
{
Name: "retry-after-http",
Format: "Seconds",
Expand Down Expand Up @@ -184,7 +184,7 @@ var _ = Describe("MeshRetry", func() {
},
RateLimitedBackOff: &api.RateLimitedBackOff{
MaxInterval: test.ParseDuration("15s"),
ResetHeaders: []api.ResetHeader{
ResetHeaders: &[]api.ResetHeader{
{
Name: "retry-after-grpc",
Format: "Seconds",
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugins/policies/meshretry/plugin/xds/configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
api "github.com/kumahq/kuma/pkg/plugins/policies/meshretry/api/v1alpha1"
"github.com/kumahq/kuma/pkg/util/pointer"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
v3 "github.com/kumahq/kuma/pkg/xds/envoy/listeners/v3"
)
Expand Down Expand Up @@ -149,7 +150,7 @@ func configureRateLimitedRetryBackOff(rateLimitedBackOff *api.RateLimitedBackOff
rateLimitedRetryBackoff := &envoy_route.RetryPolicy_RateLimitedRetryBackOff{
ResetHeaders: []*envoy_route.RetryPolicy_ResetHeader{},
}
for _, resetHeader := range rateLimitedBackOff.ResetHeaders {
for _, resetHeader := range pointer.Deref(rateLimitedBackOff.ResetHeaders) {
rateLimitedRetryBackoff.ResetHeaders = append(rateLimitedRetryBackoff.ResetHeaders, &envoy_route.RetryPolicy_ResetHeader{
Name: string(resetHeader.Name),
Format: api.RateLimitFormatEnumToEnvoyValue[resetHeader.Format],
Expand Down