-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
263 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
108 changes: 108 additions & 0 deletions
108
policy-controller/k8s/index/src/inbound/tests/ratelimit_policy.rs
This file contains 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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use super::*; | ||
use linkerd_policy_controller_core::inbound::{Limit, Override, RateLimit}; | ||
|
||
#[test] | ||
fn ratelimit_policy_with_server() { | ||
let test = TestConfig::default(); | ||
|
||
let mut pod = mk_pod("ns-0", "pod-0", Some(("container-0", None))); | ||
pod.labels_mut() | ||
.insert("app".to_string(), "app-0".to_string()); | ||
test.index.write().apply(pod); | ||
|
||
let mut rx = test | ||
.index | ||
.write() | ||
.pod_server_rx("ns-0", "pod-0", 8080.try_into().unwrap()) | ||
.expect("pod-0.ns-0 should exist"); | ||
assert_eq!(*rx.borrow_and_update(), test.default_server()); | ||
|
||
test.index.write().apply(mk_server( | ||
"ns-0", | ||
"srv-8080", | ||
Port::Number(8080.try_into().unwrap()), | ||
None, | ||
Some(("app", "app-0")), | ||
Some(k8s::policy::server::ProxyProtocol::Http1), | ||
)); | ||
assert!(rx.has_changed().unwrap()); | ||
assert_eq!( | ||
*rx.borrow_and_update(), | ||
InboundServer { | ||
reference: ServerRef::Server("srv-8080".to_string()), | ||
authorizations: Default::default(), | ||
ratelimit: None, | ||
protocol: ProxyProtocol::Http1, | ||
http_routes: mk_default_http_routes(), | ||
grpc_routes: mk_default_grpc_routes(), | ||
}, | ||
); | ||
|
||
let ratelimit = RateLimit { | ||
total: Some(Limit { | ||
requests_per_second: 1000, | ||
}), | ||
identity: None, | ||
overrides: vec![Override { | ||
requests_per_second: 500, | ||
client_identities: vec![ | ||
"client-0.ns-0.serviceaccount.identity.linkerd.cluster.example.com".to_string(), | ||
], | ||
}], | ||
}; | ||
test.index.write().apply(mk_ratelimit( | ||
"ns-0", | ||
"ratelimit-0", | ||
Some(k8s::policy::Limit { | ||
requests_per_second: 1000, | ||
}), | ||
vec![k8s::policy::Override { | ||
requests_per_second: 500, | ||
client_refs: vec![NamespacedTargetRef { | ||
group: None, | ||
kind: "ServiceAccount".to_string(), | ||
name: "client-0".to_string(), | ||
namespace: None, | ||
}], | ||
}], | ||
"srv-8080", | ||
)); | ||
assert!(rx.has_changed().unwrap()); | ||
assert_eq!( | ||
*rx.borrow_and_update(), | ||
InboundServer { | ||
reference: ServerRef::Server("srv-8080".to_string()), | ||
authorizations: Default::default(), | ||
ratelimit: Some(ratelimit), | ||
protocol: ProxyProtocol::Http1, | ||
http_routes: mk_default_http_routes(), | ||
grpc_routes: mk_default_grpc_routes(), | ||
}, | ||
); | ||
} | ||
|
||
fn mk_ratelimit( | ||
ns: impl ToString, | ||
name: impl ToString, | ||
total: Option<k8s::policy::Limit>, | ||
overrides: Vec<k8s::policy::Override>, | ||
server_name: impl ToString, | ||
) -> k8s::policy::HTTPLocalRateLimitPolicy { | ||
k8s::policy::HTTPLocalRateLimitPolicy { | ||
metadata: k8s::ObjectMeta { | ||
namespace: Some(ns.to_string()), | ||
name: Some(name.to_string()), | ||
..Default::default() | ||
}, | ||
spec: k8s::policy::RateLimitPolicySpec { | ||
target_ref: LocalTargetRef { | ||
group: Some("policy.linkerd.io".to_string()), | ||
kind: "Server".to_string(), | ||
name: server_name.to_string(), | ||
}, | ||
total, | ||
identity: None, | ||
overrides, | ||
}, | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.