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(policy): use enum for format in mesh retry #5749

Merged
merged 8 commits into from
Jan 18, 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 @@ -1838,6 +1838,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -1907,6 +1910,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -1907,6 +1910,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -2039,6 +2042,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -1927,6 +1930,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3009,6 +3009,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -3078,6 +3081,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3141,6 +3141,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -3210,6 +3213,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
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 @@ -128,6 +128,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -197,6 +200,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down
4 changes: 0 additions & 4 deletions pkg/core/validators/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,3 @@ func MustHaveOnlyOne(entity string, allowedValues ...string) string {
func MustHaveAtLeastOne(allowedValues ...string) string {
return fmt.Sprintf(`must have at least one defined: %s`, strings.Join(allowedValues, ", "))
}

func MustBeOnlyOneOf(allowedValues []string) string {
return fmt.Sprintf(`must be only one of: %s`, strings.Join(allowedValues, ", "))
}
1 change: 1 addition & 0 deletions pkg/plugins/policies/meshretry/api/v1alpha1/meshretry.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ type RateLimitedBackOff struct {
MaxInterval *k8s.Duration `json:"maxInterval,omitempty"`
}

// +kubebuilder:validation:Enum=Seconds;UnixTimestamp
type RateLimitFormat string

var (
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 @@ -77,6 +77,9 @@ properties:
properties:
format:
description: The format of the reset header, either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -122,6 +125,9 @@ properties:
properties:
format:
description: The format of the reset header, either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down
3 changes: 0 additions & 3 deletions pkg/plugins/policies/meshretry/api/v1alpha1/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ func validateRateLimitedBackOff(rateLimitedBackOff *RateLimitedBackOff) validato
for i, header := range rateLimitedBackOff.ResetHeaders {
index := path.Field("resetHeaders").Index(i)
verr.Add(validators.ValidateStringDefined(index.Field("name"), header.Name))
if _, ok := RateLimitFormatEnumToEnvoyValue[header.Format]; !ok {
verr.AddViolationAt(index.Field("format"), validators.MustBeOnlyOneOf([]string{string(Seconds), string(UnixTimestamp)}))
}
}

return verr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,12 @@ to:
rateLimitedBackOff:
resetHeaders:
- name: ""
format: "UnixTimestamp"
`,
expected: `
violations:
- field: spec.to[0].default.conf.http.rateLimitedBackOff.resetHeaders[0].name
message: must be defined
- field: spec.to[0].default.conf.http.rateLimitedBackOff.resetHeaders[0].format
message: 'must be only one of: Seconds, UnixTimestamp'`,
message: must be defined`,
}),
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down Expand Up @@ -197,6 +200,9 @@ spec:
format:
description: The format of the reset header,
either Seconds or UnixTimestamp.
enum:
- Seconds
- UnixTimestamp
type: string
name:
description: The Name of the reset header.
Expand Down