Skip to content

Commit

Permalink
policy-controller compiles
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Leong <[email protected]>
  • Loading branch information
adleong committed Feb 11, 2025
1 parent 668a0e2 commit 1099bde
Show file tree
Hide file tree
Showing 21 changed files with 1,680 additions and 1,141 deletions.
2 changes: 1 addition & 1 deletion policy-controller/k8s/index/src/inbound/index/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl TryFrom<grpcroutes::GRPCRoute> for RouteBinding<GrpcRoute> {

let statuses = route
.status
.map_or_else(Vec::new, |status| Status::collect_from_grpc(status));
.map_or_else(Vec::new, Status::collect_from_grpc);

Ok(RouteBinding {
parents,
Expand Down
2 changes: 1 addition & 1 deletion policy-controller/k8s/index/src/inbound/index/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl TryFrom<gateway::HTTPRoute> for RouteBinding<HttpRoute> {

let statuses = route
.status
.map_or_else(Vec::new, |status| Status::collect_from_http(status));
.map_or_else(Vec::new, Status::collect_from_http);

Ok(RouteBinding {
parents,
Expand Down
4 changes: 2 additions & 2 deletions policy-controller/k8s/index/src/outbound/index/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub(super) fn convert_backend(
};

Some(Backend::Service(WeightedService {
weight: weight as u32,
weight,
authority: cluster.service_dns_authority(&backend_ref.namespace, &name, port),
name,
namespace: backend_ref.namespace.to_string(),
Expand All @@ -175,7 +175,7 @@ pub(super) fn convert_backend(
}))
}
ResourceKind::EgressNetwork => Some(Backend::EgressNetwork(WeightedEgressNetwork {
weight: weight.into(),
weight,
name,
namespace: backend_ref.namespace.to_string(),
port,
Expand Down
4 changes: 2 additions & 2 deletions policy-controller/k8s/index/src/outbound/index/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub(super) fn convert_backend(
};

Some(Backend::Service(WeightedService {
weight: weight as u32,
weight,
authority: cluster.service_dns_authority(&backend_ref.namespace, &name, port),
name,
namespace: backend_ref.namespace.to_string(),
Expand All @@ -273,7 +273,7 @@ pub(super) fn convert_backend(
}))
}
ResourceKind::EgressNetwork => Some(Backend::EgressNetwork(WeightedEgressNetwork {
weight: weight.into(),
weight,
name,
namespace: backend_ref.namespace.to_string(),
port,
Expand Down
4 changes: 2 additions & 2 deletions policy-controller/k8s/index/src/outbound/index/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(super) fn convert_backend(
};

Some(Backend::Service(WeightedService {
weight: weight.into(),
weight,
authority: cluster.service_dns_authority(&backend_ref.namespace, &name, port),
name,
namespace: backend_ref.namespace.to_string(),
Expand All @@ -97,7 +97,7 @@ pub(super) fn convert_backend(
}))
}
ResourceKind::EgressNetwork => Some(Backend::EgressNetwork(WeightedEgressNetwork {
weight: weight.into(),
weight,
name,
namespace: backend_ref.namespace.to_string(),
port,
Expand Down
4 changes: 2 additions & 2 deletions policy-controller/k8s/index/src/outbound/index/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(super) fn convert_backend(
};

Some(Backend::Service(WeightedService {
weight: weight.into(),
weight,
authority: cluster.service_dns_authority(&backend_ref.namespace, &name, port),
name,
namespace: backend_ref.namespace.to_string(),
Expand All @@ -108,7 +108,7 @@ pub(super) fn convert_backend(
}))
}
ResourceKind::EgressNetwork => Some(Backend::EgressNetwork(WeightedEgressNetwork {
weight: weight.into(),
weight,
name,
namespace: backend_ref.namespace.to_string(),
port,
Expand Down
2 changes: 1 addition & 1 deletion policy-controller/k8s/index/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl HttpRouteResource {
pub(crate) fn status(&self) -> Option<&gateway::httproutes::HTTPRouteStatus> {
match self {
Self::LinkerdHttp(route) => route.status.as_ref().map(|status| &status.inner),
Self::GatewayHttp(route) => route.status.as_ref().map(|status| status),
Self::GatewayHttp(route) => route.status.as_ref(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion policy-controller/k8s/status/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl Index {
// attach to has any routes attached that are in conflict with the one
// that we are about to attach. This is done following the logs outlined in:
// https://gateway-api.sigs.k8s.io/geps/gep-1426/#route-types
pub fn parent_has_conflicting_routes<'p>(
pub fn parent_has_conflicting_routes(
&self,
parent_ref: &routes::ParentReference,
candidate_kind: &str,
Expand Down
2 changes: 0 additions & 2 deletions policy-controller/k8s/status/src/routes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::resource_id::ResourceId;
use anyhow::Result;
use linkerd_policy_controller_k8s_api::{self as k8s_core_api, gateway, policy as linkerd_k8s_api};

pub(crate) mod grpc;
pub(crate) mod http;
Expand Down
2 changes: 1 addition & 1 deletion policy-controller/k8s/status/src/routes/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) fn make_backends(

pub(crate) fn make_parents(
namespace: &str,
parents: &Vec<gateway::GRPCRouteParentRefs>,
parents: &[gateway::GRPCRouteParentRefs],
) -> Vec<ParentReference> {
parents
.iter()
Expand Down
2 changes: 1 addition & 1 deletion policy-controller/k8s/status/src/routes/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn make_backends(

pub(crate) fn make_parents(
namespace: &str,
parents: &Vec<gateway::HTTPRouteParentRefs>,
parents: &[gateway::HTTPRouteParentRefs],
) -> Vec<ParentReference> {
parents
.iter()
Expand Down
2 changes: 1 addition & 1 deletion policy-controller/k8s/status/src/routes/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn make_backends(

pub(crate) fn make_parents(
namespace: &str,
parents: &Vec<gateway::TCPRouteParentRefs>,
parents: &[gateway::TCPRouteParentRefs],
) -> Vec<ParentReference> {
parents
.iter()
Expand Down
2 changes: 1 addition & 1 deletion policy-controller/k8s/status/src/routes/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn make_backends(

pub(crate) fn make_parents(
namespace: &str,
parents: &Vec<gateway::TLSRouteParentRefs>,
parents: &[gateway::TLSRouteParentRefs],
) -> Vec<ParentReference> {
parents
.iter()
Expand Down
91 changes: 34 additions & 57 deletions policy-controller/k8s/status/src/tests/conflict.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
#[cfg(test)]
use crate::{
index::{GRPCRouteRef, HTTPRouteRef},
resource_id::NamespaceGroupKindName,
index::{GRPCRouteRef, HTTPRouteRef, SharedIndex, TCPRouteRef, TLSRouteRef},
resource_id::{NamespaceGroupKindName, ResourceId},
routes,
};

use crate::{
index::{accepted, in_cluster_net_overlap, SharedIndex, TCPRouteRef, TLSRouteRef},
resource_id::NamespaceGroupKindName,
tests::default_cluster_networks,
Index, IndexMetrics,
};
use crate::{resource_id::ResourceId, Index};
use ahash::HashMap;
use chrono::{DateTime, Utc};
use kubert::index::IndexNamespacedResource;
use linkerd_policy_controller_core::routes::GroupKindName;
use linkerd_policy_controller_core::routes::GroupKindName;
use linkerd_policy_controller_k8s_api::{
self as k8s_core_api,
policy::{self as linkerd_k8s_api, EgressNetworkStatus},
Resource,
};
use linkerd_policy_controller_k8s_api::{gateway, Resource};
use std::vec;
use std::{sync::Arc, vec};
use tokio::sync::{mpsc, watch};

Expand Down Expand Up @@ -356,6 +341,8 @@ fn tls_route_no_conflict(p: ParentRefType) {
}

fn tcp_route_conflict_grpc(p: ParentRefType) {
let index = make_index();

let parent = match p {
ParentRefType::Service => routes::ParentReference::Service(
ResourceId::new("ns".to_string(), "service".to_string()),
Expand All @@ -368,7 +355,7 @@ fn tcp_route_conflict_grpc(p: ParentRefType) {
),
};

let known_routes: HashMap<_, _> = vec![(
index.write().update_grpc_route(
NamespaceGroupKindName {
namespace: "default".to_string(),
gkn: GroupKindName {
Expand All @@ -377,23 +364,21 @@ fn tcp_route_conflict_grpc(p: ParentRefType) {
name: "grpc-1".into(),
},
},
RouteRef {
&GRPCRouteRef {
parents: vec![parent.clone()],
statuses: vec![],
backends: vec![],
},
)]
.into_iter()
.collect();
);

assert!(parent_has_conflicting_routes(
&mut known_routes.iter(),
&parent,
"TCPRoute"
));
assert!(index
.read()
.parent_has_conflicting_routes(&parent, "TCPRoute"));
}

fn tcp_route_conflict_http(p: ParentRefType) {
let index = make_index();

let parent = match p {
ParentRefType::Service => routes::ParentReference::Service(
ResourceId::new("ns".to_string(), "service".to_string()),
Expand All @@ -406,7 +391,7 @@ fn tcp_route_conflict_http(p: ParentRefType) {
),
};

let known_routes: HashMap<_, _> = vec![(
index.write().update_http_route(
NamespaceGroupKindName {
namespace: "default".to_string(),
gkn: GroupKindName {
Expand All @@ -415,23 +400,21 @@ fn tcp_route_conflict_http(p: ParentRefType) {
name: "http-1".into(),
},
},
RouteRef {
&HTTPRouteRef {
parents: vec![parent.clone()],
statuses: vec![],
backends: vec![],
},
)]
.into_iter()
.collect();
);

assert!(parent_has_conflicting_routes(
&mut known_routes.iter(),
&parent,
"TCPRoute"
));
assert!(index
.read()
.parent_has_conflicting_routes(&parent, "TCPRoute"));
}

fn tcp_route_conflict_tls(p: ParentRefType) {
let index = make_index();

let parent = match p {
ParentRefType::Service => routes::ParentReference::Service(
ResourceId::new("ns".to_string(), "service".to_string()),
Expand All @@ -444,7 +427,7 @@ fn tcp_route_conflict_tls(p: ParentRefType) {
),
};

let known_routes: HashMap<_, _> = vec![(
index.write().update_tls_route(
NamespaceGroupKindName {
namespace: "default".to_string(),
gkn: GroupKindName {
Expand All @@ -453,23 +436,21 @@ fn tcp_route_conflict_tls(p: ParentRefType) {
name: "tls-1".into(),
},
},
RouteRef {
&TLSRouteRef {
parents: vec![parent.clone()],
statuses: vec![],
backends: vec![],
},
)]
.into_iter()
.collect();
);

assert!(parent_has_conflicting_routes(
&mut known_routes.iter(),
&parent,
"TCPRoute"
));
assert!(index
.read()
.parent_has_conflicting_routes(&parent, "TCPRoute"));
}

fn tcp_route_no_conflict(p: ParentRefType) {
let index = make_index();

let parent = match p {
ParentRefType::Service => routes::ParentReference::Service(
ResourceId::new("ns".to_string(), "service".to_string()),
Expand All @@ -482,7 +463,7 @@ fn tcp_route_no_conflict(p: ParentRefType) {
),
};

let known_routes: HashMap<_, _> = vec![(
index.write().update_tcp_route(
NamespaceGroupKindName {
namespace: "default".to_string(),
gkn: GroupKindName {
Expand All @@ -491,20 +472,16 @@ fn tcp_route_no_conflict(p: ParentRefType) {
name: "tcp-1".into(),
},
},
RouteRef {
&TCPRouteRef {
parents: vec![parent.clone()],
statuses: vec![],
backends: vec![],
},
)]
.into_iter()
.collect();
);

assert!(!parent_has_conflicting_routes(
&mut known_routes.iter(),
&parent,
"TCPRoute"
));
assert!(!index
.read()
.parent_has_conflicting_routes(&parent, "TCPRoute"));
}

#[test]
Expand Down
Loading

0 comments on commit 1099bde

Please sign in to comment.