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 issue where initial outbound policy did not contain producer routes #12619

Merged
merged 2 commits into from
May 23, 2024
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
2 changes: 1 addition & 1 deletion policy-controller/k8s/index/src/outbound/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ impl ServiceRoutes {
.unwrap_or_default();
self.watches_by_ns.entry(namespace).or_insert_with(|| {
let (sender, _) = watch::channel(OutboundPolicy {
http_routes: Default::default(),
http_routes: routes.clone(),
authority: self.authority.clone(),
name: self.name.to_string(),
namespace: self.namespace.to_string(),
Expand Down
48 changes: 48 additions & 0 deletions policy-test/tests/outbound_api_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,54 @@ async fn producer_route() {
.await;
}

#[tokio::test(flavor = "current_thread")]
async fn pre_existing_producer_route() {
// We test the scenario where outbound policy watches are initiated after
// a produce route already exists.
with_temp_ns(|client, ns| async move {
// Create a service
let svc = create_service(&client, &ns, "my-svc", 4191).await;

// A route created in the same namespace as its parent service is called
// a producer route. It should be returned in outbound policy requests
// for that service from ALL namespaces.
let _route = create(
&client,
mk_http_route(&ns, "foo-route", &svc, Some(4191)).build(),
)
.await;

let mut producer_rx = retry_watch_outbound_policy(&client, &ns, &svc, 4191).await;
let producer_config = producer_rx
.next()
.await
.expect("watch must not fail")
.expect("watch must return an initial config");
tracing::trace!(?producer_config);

let mut consumer_rx = retry_watch_outbound_policy(&client, "consumer_ns", &svc, 4191).await;
let consumer_config = consumer_rx
.next()
.await
.expect("watch must not fail")
.expect("watch must return an initial config");
tracing::trace!(?consumer_config);

// The route should be returned in queries from the producer namespace.
detect_http_routes(&producer_config, |routes| {
let route = assert_singleton(routes);
assert_route_name_eq(route, "foo-route");
});

// The route should be returned in queries from a consumer namespace.
detect_http_routes(&consumer_config, |routes| {
let route = assert_singleton(routes);
assert_route_name_eq(route, "foo-route");
});
})
.await;
}

#[tokio::test(flavor = "current_thread")]
async fn consumer_route() {
with_temp_ns(|client, ns| async move {
Expand Down
48 changes: 48 additions & 0 deletions policy-test/tests/outbound_api_linkerd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,54 @@ async fn producer_route() {
.await;
}

#[tokio::test(flavor = "current_thread")]
async fn pre_existing_producer_route() {
// We test the scenario where outbound policy watches are initiated after
// a produce route already exists.
with_temp_ns(|client, ns| async move {
// Create a service
let svc = create_service(&client, &ns, "my-svc", 4191).await;

// A route created in the same namespace as its parent service is called
// a producer route. It should be returned in outbound policy requests
// for that service from ALL namespaces.
let _route = create(
&client,
mk_http_route(&ns, "foo-route", &svc, Some(4191)).build(),
)
.await;

let mut producer_rx = retry_watch_outbound_policy(&client, &ns, &svc, 4191).await;
let producer_config = producer_rx
.next()
.await
.expect("watch must not fail")
.expect("watch must return an initial config");
tracing::trace!(?producer_config);

let mut consumer_rx = retry_watch_outbound_policy(&client, "consumer_ns", &svc, 4191).await;
let consumer_config = consumer_rx
.next()
.await
.expect("watch must not fail")
.expect("watch must return an initial config");
tracing::trace!(?consumer_config);

// The route should be returned in queries from the producer namespace.
detect_http_routes(&producer_config, |routes| {
let route = assert_singleton(routes);
assert_route_name_eq(route, "foo-route");
});

// The route should be returned in queries from a consumer namespace.
detect_http_routes(&consumer_config, |routes| {
let route = assert_singleton(routes);
assert_route_name_eq(route, "foo-route");
});
})
.await;
}

#[tokio::test(flavor = "current_thread")]
async fn consumer_route() {
with_temp_ns(|client, ns| async move {
Expand Down