Skip to content

Commit

Permalink
more feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Zahari Dichev <[email protected]>
  • Loading branch information
zaharidichev committed Nov 20, 2024
1 parent a535967 commit 742c0ab
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
8 changes: 4 additions & 4 deletions policy-controller/k8s/index/src/outbound/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl kubert::index::IndexNamespacedResource<linkerd_k8s_api::EgressNetwork> for
.insert(egress_net_ref, egress_network_info);

self.reindex_resources();
self.reinitialize_egress_watches(ns.clone());
self.reinitialize_egress_watches(&ns);
self.reinitialize_fallback_watches()
}

Expand All @@ -399,7 +399,7 @@ impl kubert::index::IndexNamespacedResource<linkerd_k8s_api::EgressNetwork> for
self.egress_networks_by_ref.remove(&egress_net_ref);

self.reindex_resources();
self.reinitialize_egress_watches(Arc::new(egress_net_ref.namespace.clone()));
self.reinitialize_egress_watches(&egress_net_ref.namespace);
self.reinitialize_fallback_watches()
}
}
Expand Down Expand Up @@ -652,9 +652,9 @@ impl Index {
}
}

fn reinitialize_egress_watches(&mut self, namespace: Arc<String>) {
fn reinitialize_egress_watches(&mut self, namespace: &str) {
for ns in self.namespaces.by_ns.values_mut() {
if namespace == self.global_egress_network_namespace || namespace == ns.namespace {
if namespace == &*self.global_egress_network_namespace || namespace == &*ns.namespace {

Check failure on line 657 in policy-controller/k8s/index/src/outbound/index.rs

View workflow job for this annotation

GitHub Actions / clippy

error: taken reference of right operand --> policy-controller/k8s/index/src/outbound/index.rs:657:16 | 657 | if namespace == &*self.global_egress_network_namespace || namespace == &*ns.namespace { | ^^^^^^^^^^^^^-------------------------------------- | | | help: use the right value directly: `*self.global_egress_network_namespace` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref note: the lint level is defined here --> policy-controller/k8s/index/src/lib.rs:23:9 | 23 | #![deny(warnings, rust_2018_idioms)] | ^^^^^^^^ = note: `#[deny(clippy::op_ref)]` implied by `#[deny(warnings)]`

Check failure on line 657 in policy-controller/k8s/index/src/outbound/index.rs

View workflow job for this annotation

GitHub Actions / clippy

error: taken reference of right operand --> policy-controller/k8s/index/src/outbound/index.rs:657:71 | 657 | if namespace == &*self.global_egress_network_namespace || namespace == &*ns.namespace { | ^^^^^^^^^^^^^-------------- | | | help: use the right value directly: `*ns.namespace` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
ns.reinitialize_egress_watches()
}
}
Expand Down
5 changes: 5 additions & 0 deletions policy-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ impl Resource {

pub fn ip(&self) -> String {
match self {
// For EgressNetwork, we can just return a non-private
// IP address as our default cluster setup dictates that
// all non-private networks are considered egress. Since
// we do not modify this setting in tests for the time being,
// returning 1.1.1.1 is fine.
Self::EgressNetwork(_) => "1.1.1.1".to_string(),
Self::Service(s) => s
.spec
Expand Down
53 changes: 53 additions & 0 deletions policy-test/tests/e2e_egress_network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use linkerd_policy_controller_k8s_api as k8s;
use linkerd_policy_test::{
await_condition, create, create_ready_pod, curl, endpoints_ready, update, web, with_temp_ns,

Check warning on line 3 in policy-test/tests/e2e_egress_network.rs

View workflow job for this annotation

GitHub Actions / check

warning: unused imports: `await_condition`, `create_ready_pod`, `endpoints_ready`, `web` --> policy-test/tests/e2e_egress_network.rs:3:5 | 3 | await_condition, create, create_ready_pod, curl, endpoints_ready, update, web, with_temp_ns, | ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 3 in policy-test/tests/e2e_egress_network.rs

View workflow job for this annotation

GitHub Actions / check

warning: unused imports: `await_condition`, `create_ready_pod`, `endpoints_ready`, `web` --> policy-test/tests/e2e_egress_network.rs:3:5 | 3 | await_condition, create, create_ready_pod, curl, endpoints_ready, update, web, with_temp_ns, | ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 3 in policy-test/tests/e2e_egress_network.rs

View workflow job for this annotation

GitHub Actions / check

warning: unused imports: `await_condition`, `create_ready_pod`, `endpoints_ready`, `web` --> policy-test/tests/e2e_egress_network.rs:3:5 | 3 | await_condition, create, create_ready_pod, curl, endpoints_ready, update, web, with_temp_ns, | ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^ | = note: `#[warn(unused_imports)]` on by default

Check warning on line 3 in policy-test/tests/e2e_egress_network.rs

View workflow job for this annotation

GitHub Actions / check

warning: unused imports: `await_condition`, `create_ready_pod`, `endpoints_ready`, `web` --> policy-test/tests/e2e_egress_network.rs:3:5 | 3 | await_condition, create, create_ready_pod, curl, endpoints_ready, update, web, with_temp_ns, | ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^ | = note: `#[warn(unused_imports)]` on by default
LinkerdInject,
};

#[tokio::test(flavor = "current_thread")]
async fn default_traffic_policy() {
with_temp_ns(|client, ns| async move {
let mut egress_net = create(
&client,
k8s::policy::EgressNetwork {
metadata: k8s::ObjectMeta {
namespace: Some(ns.clone()),
name: Some("all-egress".to_string()),
..Default::default()
},
spec: k8s::policy::EgressNetworkSpec {
networks: None,
traffic_policy: k8s::policy::TrafficPolicy::Allow,
},
status: None,
},
)
.await;

let curl = curl::Runner::init(&client, &ns).await;

let allowed = curl
.run(
"curl-allowed",
"http://httpbin.org/get",
LinkerdInject::Enabled,
)
.await;
let allowed_status = allowed.http_status_code().await;
assert_eq!(allowed_status, 200, "request must be allowed");

egress_net.spec.traffic_policy = k8s::policy::TrafficPolicy::Deny;
update(&client, egress_net).await;

let not_allowed = curl
.run(
"curl-not-allowed",
"http://httpbin.org/get",
LinkerdInject::Enabled,
)
.await;
let not_allowed_status = not_allowed.http_status_code().await;
assert_eq!(not_allowed_status, 403, "request must be blocked");
})
.await;
}

0 comments on commit 742c0ab

Please sign in to comment.