Skip to content

Commit

Permalink
feat(MeshTimeout): allow top level targetRef.kind MeshGateway (#7137)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont authored Jun 30, 2023
1 parent ccc17f1 commit 6d3475f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/plugins/policies/meshtimeout/api/v1alpha1/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func validateTop(targetRef common_api.TargetRef) validators.ValidationError {
SupportedKinds: []common_api.TargetRefKind{
common_api.Mesh,
common_api.MeshSubset,
common_api.MeshGateway,
common_api.MeshService,
common_api.MeshServiceSubset,
common_api.MeshHTTPRoute,
Expand All @@ -36,7 +37,7 @@ func validateFrom(from []From, topLevelKind common_api.TargetRefKind) validators
fromPath := validators.RootedAt("from")

switch topLevelKind {
case common_api.MeshHTTPRoute:
case common_api.MeshHTTPRoute, common_api.MeshGateway:
if len(from) != 0 {
verr.AddViolationAt(fromPath, validators.MustNotBeDefined)
}
Expand Down Expand Up @@ -64,7 +65,7 @@ func validateTo(to []To, topLevelKind common_api.TargetRefKind) validators.Valid

var supportedKinds []common_api.TargetRefKind
switch topLevelKind {
case common_api.MeshHTTPRoute:
case common_api.MeshHTTPRoute, common_api.MeshGateway:
supportedKinds = []common_api.TargetRefKind{
common_api.Mesh,
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/plugins/policies/meshtimeout/api/v1alpha1/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,35 @@ violations:
- field: spec.to[0].default.http.maxConnectionDuration
message: can't be specified when top-level TargetRef is referencing MeshHTTPRoute`,
}),
Entry("top-level targetRef is referencing MeshGateway", testCase{
inputYaml: `
targetRef:
kind: MeshGateway
name: gateway-1
to:
- targetRef:
kind: MeshService
name: web-backend
default:
connectionTimeout: 10s
idleTimeout: 1h
http:
requestTimeout: 1s
streamIdleTimeout: 1h
maxStreamDuration: 1h
maxConnectionDuration: 1h
from:
- targetRef:
kind: Mesh
default:
connectionTimeout: 11s`,
expected: `
violations:
- field: spec.from
message: must not be defined
- field: spec.to[0].targetRef.kind
message: value is not supported`,
}),
)
})
})

0 comments on commit 6d3475f

Please sign in to comment.