-
Notifications
You must be signed in to change notification settings - Fork 1.3k
test(policy): Reduce duplication in outbound policy API tests #13543
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ee11a78
WIP
adleong 0f3a9fd
WIP; I need help with Send futures
adleong 4c041a7
checkpoint. tests pass so far
adleong 6116a5a
checkpoint, more tests
adleong 0fccc9f
checkpoint; more tests
adleong dd90c9a
checkpoint. more tests
adleong 41a2d8e
finished porting tests
adleong ea87f3a
make logging consistent
adleong 1da9620
Remove unused helpers
adleong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
use crate::{assert_resource_meta, grpc, Resource}; | ||
use crate::{grpc, test_route::TestRoute, Resource}; | ||
use k8s_gateway_api::ParentReference; | ||
use kube::ResourceExt; | ||
use std::time::Duration; | ||
use tokio::time; | ||
|
||
pub async fn retry_watch_outbound_policy( | ||
client: &kube::Client, | ||
ns: &str, | ||
resource: &Resource, | ||
ip: &str, | ||
port: u16, | ||
) -> tonic::Streaming<grpc::outbound::OutboundPolicy> { | ||
// Port-forward to the control plane and start watching the service's | ||
// outbound policy. | ||
let mut policy_api = grpc::OutboundPolicyClient::port_forwarded(client).await; | ||
loop { | ||
match policy_api.watch_ip(ns, &resource.ip(), port).await { | ||
match policy_api.watch_ip(ns, ip, port).await { | ||
Ok(rx) => return rx, | ||
Err(error) => { | ||
tracing::error!( | ||
?error, | ||
ns, | ||
resource = resource.name(), | ||
"failed to watch outbound policy for port 4191" | ||
); | ||
tracing::error!(?error, ns, ip, port, "failed to watch outbound policy"); | ||
time::sleep(Duration::from_secs(1)).await; | ||
} | ||
} | ||
|
@@ -291,26 +287,23 @@ pub fn assert_backend_has_failure_filter( | |
} | ||
|
||
#[track_caller] | ||
pub fn assert_route_is_default(route: &grpc::outbound::HttpRoute, parent: &Resource, port: u16) { | ||
let kind = route.metadata.as_ref().unwrap().kind.as_ref().unwrap(); | ||
match kind { | ||
pub fn assert_route_is_default<R: TestRoute>( | ||
route: &R::Route, | ||
parent: &ParentReference, | ||
port: u16, | ||
) { | ||
let rules = &R::rules_first_available(route); | ||
let backends = assert_singleton(rules); | ||
let backend = R::backend(*assert_singleton(backends)); | ||
assert_backend_matches_reference(backend, parent, port); | ||
|
||
let route_meta = R::extract_meta(route); | ||
match route_meta.kind.as_ref().unwrap() { | ||
grpc::meta::metadata::Kind::Default(_) => {} | ||
grpc::meta::metadata::Kind::Resource(r) => { | ||
panic!("route expected to be default but got resource {r:?}") | ||
} | ||
} | ||
|
||
let backends = route_backends_first_available(route); | ||
let backend = assert_singleton(backends); | ||
assert_backend_matches_parent(backend, parent, port); | ||
|
||
let rule = assert_singleton(&route.rules); | ||
let route_match = assert_singleton(&rule.matches); | ||
let path_match = route_match.path.as_ref().unwrap().kind.as_ref().unwrap(); | ||
assert_eq!( | ||
*path_match, | ||
grpc::http_route::path_match::Kind::Prefix("/".to_string()) | ||
); | ||
} | ||
|
||
#[track_caller] | ||
|
@@ -330,49 +323,27 @@ pub fn assert_tls_route_is_default(route: &grpc::outbound::TlsRoute, parent: &Re | |
} | ||
|
||
#[track_caller] | ||
pub fn assert_backend_matches_parent( | ||
backend: &grpc::outbound::http_route::RouteBackend, | ||
parent: &Resource, | ||
pub fn assert_backend_matches_reference( | ||
backend: &grpc::outbound::Backend, | ||
obj_ref: &ParentReference, | ||
port: u16, | ||
) { | ||
let backend = backend.backend.as_ref().unwrap(); | ||
|
||
match parent { | ||
Resource::Service(svc) => { | ||
let dst = match backend.kind.as_ref().unwrap() { | ||
grpc::outbound::backend::Kind::Balancer(balance) => { | ||
let kind = balance.discovery.as_ref().unwrap().kind.as_ref().unwrap(); | ||
match kind { | ||
grpc::outbound::backend::endpoint_discovery::Kind::Dst(dst) => &dst.path, | ||
} | ||
} | ||
grpc::outbound::backend::Kind::Forward(_) => { | ||
panic!("service default route backend must be Balancer") | ||
} | ||
}; | ||
assert_eq!( | ||
*dst, | ||
format!( | ||
"{}.{}.svc.{}:{}", | ||
svc.name_unchecked(), | ||
svc.namespace().unwrap(), | ||
"cluster.local", | ||
port | ||
) | ||
); | ||
let mut group = obj_ref.group.as_deref(); | ||
if group == Some("") { | ||
group = Some("core"); | ||
} | ||
match backend.metadata.as_ref().unwrap().kind.as_ref().unwrap() { | ||
grpc::meta::metadata::Kind::Resource(resource) => { | ||
assert_eq!(resource.name, obj_ref.name); | ||
assert_eq!(Some(&resource.namespace), obj_ref.namespace.as_ref()); | ||
assert_eq!(Some(resource.group.as_str()), group); | ||
assert_eq!(Some(&resource.kind), obj_ref.kind.as_ref()); | ||
assert_eq!(resource.port, u32::from(port)); | ||
} | ||
|
||
Resource::EgressNetwork(_) => { | ||
match backend.kind.as_ref().unwrap() { | ||
grpc::outbound::backend::Kind::Forward(_) => {} | ||
grpc::outbound::backend::Kind::Balancer(_) => { | ||
panic!("egress net default route backend must be Forward") | ||
} | ||
}; | ||
grpc::meta::metadata::Kind::Default(_) => { | ||
panic!("backend expected to be resource but got default") | ||
} | ||
} | ||
|
||
assert_resource_meta(&backend.metadata, parent, port) | ||
} | ||
|
||
#[track_caller] | ||
|
@@ -418,7 +389,7 @@ pub fn assert_tls_backend_matches_parent( | |
} | ||
} | ||
|
||
assert_resource_meta(&backend.metadata, parent, port) | ||
//assert_resource_meta(&backend.metadata, parent, port) | ||
} | ||
|
||
#[track_caller] | ||
|
@@ -464,7 +435,7 @@ pub fn assert_tcp_backend_matches_parent( | |
} | ||
} | ||
|
||
assert_resource_meta(&backend.metadata, parent, port) | ||
//assert_resource_meta(&backend.metadata, parent, port) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same goes here |
||
|
||
#[track_caller] | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be reverted?