Skip to content

Commit

Permalink
update cargo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RWDai committed May 9, 2024
1 parent 82e63d3 commit a177e45
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 46 deletions.
4 changes: 2 additions & 2 deletions binary/admin-server/src/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const DEFAULT_PORT: u16 = 9992;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
///
/// the port of the server
#[arg(short, long, env, default_value_t = DEFAULT_PORT)]
pub port: u16,
///
/// the host of the server
#[arg(short='H', env, long, default_value_t = DEFAULT_HOST)]
pub host: IpAddr,
/// the config backend you choose
Expand Down
19 changes: 7 additions & 12 deletions crates/config/src/service/k8s/convert/filter_k8s_conv.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::HashMap;

use k8s_gateway_api::{HttpHeader, HttpPathModifier, HttpRequestHeaderFilter, HttpRequestRedirectFilter, HttpRouteFilter, HttpUrlRewriteFilter, LocalObjectReference};
use k8s_gateway_api::{HttpPathModifier, HttpRouteFilter, LocalObjectReference};
use kube::{
api::{DeleteParams, PatchParams, PostParams},
api::{DeleteParams, PostParams},
Api, ResourceExt,
};
use spacegate_model::{constants::SG_FILTER_KIND, ext::k8s::crd::sg_filter::SgFilter};
Expand All @@ -13,13 +11,10 @@ use crate::{
helper_struct::SgSingeFilter,
},
plugin::{
gatewayapi_support_filter::{
SgFilterHeaderModifier, SgFilterHeaderModifierKind, SgFilterRedirect, SgFilterRewrite, SgHttpPathModifier, SgHttpPathModifierType, SG_FILTER_HEADER_MODIFIER_CODE,
SG_FILTER_REDIRECT_CODE, SG_FILTER_REWRITE_CODE,
},
gatewayapi_support_filter::{SgHttpPathModifier, SgHttpPathModifierType},
PluginConfig,
},
service::{self, k8s::K8s},
service::k8s::K8s,
BoxResult, PluginInstanceId, PluginInstanceName,
};

Expand Down Expand Up @@ -151,7 +146,7 @@ impl PluginIdConv for PluginInstanceId {
async fn add_filter_target(&self, target: K8sSgFilterSpecTargetRef, client: &K8s) -> BoxResult<()> {
let filter_api: Api<SgFilter> = client.get_namespace_api();
if let Ok(mut filter) = filter_api.get(&self.name.to_string()).await {
if filter.spec.target_refs.iter().find(|t| t.eq(&&target)).is_none() {
if !filter.spec.target_refs.iter().any(|t| t.eq((&target))) {
filter.spec.target_refs.push(target);
filter_api.replace(&filter.name_any(), &PostParams::default(), &filter).await?;
};
Expand All @@ -162,7 +157,7 @@ impl PluginIdConv for PluginInstanceId {
async fn remove_filter_target(&self, target: K8sSgFilterSpecTargetRef, client: &K8s) -> BoxResult<()> {
let filter_api: Api<SgFilter> = client.get_namespace_api();
if let Ok(mut filter) = filter_api.get(&self.name.to_string()).await {
if filter.spec.target_refs.iter().find(|t| t.eq(&&target)).is_some() {
if filter.spec.target_refs.iter().any(|t| t.eq((&target))) {
filter.spec.target_refs.retain(|t| !t.eq(&target));

if filter.spec.target_refs.is_empty() {
Expand Down Expand Up @@ -211,7 +206,7 @@ pub(crate) trait PluginConfigConv {
impl PluginConfigConv for PluginConfig {
fn from_first_filter_obj(filter_obj: SgFilter) -> Option<PluginConfig> {
let filter_name = filter_obj.name_any();
filter_obj.spec.filters.into_iter().filter(|f| f.enable).next().map(|f| PluginConfig {
filter_obj.spec.filters.into_iter().find(|f| f.enable).map(|f| PluginConfig {
id: PluginInstanceId {
code: f.code.into(),
name: PluginInstanceName::Named {
Expand Down
24 changes: 9 additions & 15 deletions crates/config/src/service/k8s/convert/route_k8s_conv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{cmp::Ordering, collections::BTreeMap};

use futures_util::future::join_all;
use gateway::SgBackendProtocol;
use http_route::SgHttpRoute;
use k8s_gateway_api::{
Expand All @@ -19,13 +18,8 @@ use spacegate_model::{

use crate::{
constants,
ext::k8s::{
crd::http_spaceroute::{self, BackendRef, HttpBackendRef, HttpRouteRule, HttpSpaceroute, HttpSpacerouteSpec},
helper_struct::SgSingeFilter,
},
gateway, http_route,
service::k8s::K8s,
BackendHost, BoxResult, K8sServiceData, PluginConfig, SgBackendRef, SgHttpHeaderMatch, SgHttpPathMatch, SgHttpQueryMatch, SgHttpRouteMatch, SgHttpRouteRule,
ext::k8s::crd::http_spaceroute::{self, BackendRef, HttpBackendRef, HttpRouteRule, HttpSpaceroute, HttpSpacerouteSpec},
gateway, http_route, BackendHost, BoxResult, K8sServiceData, SgBackendRef, SgHttpHeaderMatch, SgHttpPathMatch, SgHttpQueryMatch, SgHttpRouteMatch, SgHttpRouteRule,
};

use super::{filter_k8s_conv::PluginIdConv as _, ToTarget};
Expand Down Expand Up @@ -104,13 +98,13 @@ impl SgHttpRouteRuleConv for SgHttpRouteRule {
rule.filters.map(|f_vec| f_vec.into_iter().partition(|f| matches!(f, HttpRouteFilter::ExtensionRef { extension_ref: _ }))).unwrap_or_default();
let matches = if let Some(mut matches) = rule.matches {
if matches.len() > 1 {
if legacy_plugins.iter().find(|p| matches!(p, HttpRouteFilter::URLRewrite { url_rewrite: _ })).is_some() {
if legacy_plugins.iter().any(|p| matches!(&p, HttpRouteFilter::URLRewrite { url_rewrite: _ })) {
return Err("url_rewrite is not supported with multiple matches".into());
}
if legacy_plugins.iter().find(|p| matches!(p, HttpRouteFilter::RequestHeaderModifier { request_header_modifier: _ })).is_some() {
if legacy_plugins.iter().any(|p| matches!(&p, HttpRouteFilter::RequestHeaderModifier { request_header_modifier: _ })) {
return Err("request_header_modifier is not supported with multiple matches".into());
}
Some(matches.into_iter().map(|m| SgHttpRouteMatch::from_kube_httproute(m)).collect::<Vec<_>>())
Some(matches.into_iter().map(SgHttpRouteMatch::from_kube_httproute).collect::<Vec<_>>())
} else if let Some(match_) = matches.pop() {
let mut m: SgHttpRouteMatch = SgHttpRouteMatch::from_kube_httproute(match_);
if legacy_plugins.iter().filter(|p| matches!(p, HttpRouteFilter::URLRewrite { url_rewrite: _ })).count() > 1 {
Expand Down Expand Up @@ -232,11 +226,11 @@ impl SgHttpRouteMatchConv for SgHttpRouteMatch {
(a, b)
})
.unwrap_or((vec![], vec![]));
let header_paths: Vec<_> = header_path.into_iter().filter_map(|x| x).collect();
let header_paths: Vec<_> = header_path.into_iter().flatten().collect();

(
HttpRouteMatch {
path: path,
path,
headers: if header_paths.is_empty() { None } else { Some(header_paths) },
query_params: self.query.clone().map(|q_vec| q_vec.into_iter().map(|q| q.into_kube_httproute()).collect::<Vec<_>>()),
method: Some(m.0),
Expand All @@ -256,7 +250,7 @@ impl SgHttpRouteMatchConv for SgHttpRouteMatch {
.unwrap_or((None, None));
(
vec![HttpRouteMatch {
path: path,
path,
//TODO
headers: None,
query_params: self.query.map(|q_vec| q_vec.into_iter().map(|q| q.into_kube_httproute()).collect::<Vec<_>>()),
Expand All @@ -265,7 +259,7 @@ impl SgHttpRouteMatchConv for SgHttpRouteMatch {
vec![plugin],
)
};
(match_vec, plugins.into_iter().filter_map(|x| x).collect())
(match_vec, plugins.into_iter().flatten().collect())
}

fn from_kube_httproute(route_match: HttpRouteMatch) -> SgHttpRouteMatch {
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/service/k8s/retrieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Retrieve for K8s {
match &id.name {
spacegate_model::PluginInstanceName::Anon { uid: _ } => Ok(None),
spacegate_model::PluginInstanceName::Named { name } => {
let result = filter_api.get_opt(&name).await?.and_then(|filter_obj| PluginConfig::from_first_filter_obj(filter_obj));
let result = filter_api.get_opt(name).await?.and_then(PluginConfig::from_first_filter_obj);
Ok(result)
}
spacegate_model::PluginInstanceName::Mono => Ok(None),
Expand Down
4 changes: 2 additions & 2 deletions crates/config/src/service/k8s/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ impl K8s {

let add_vec: Vec<_> = update_set.difference(&old_set).collect();
for add_id in add_vec {
add_id.add_filter_target(target.clone(), &self).await?;
add_id.add_filter_target(target.clone(), self).await?;
}
let delete_vec: Vec<_> = old_set.difference(&update_set).collect();
for delete_id in delete_vec {
delete_id.remove_filter_target(target.clone(), &self).await?;
delete_id.remove_filter_target(target.clone(), self).await?;
}

Ok(())
Expand Down
5 changes: 0 additions & 5 deletions crates/kernel/src/service/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//!
//!
//!
//!
pub mod builder;

use std::{collections::HashMap, ops::Index, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion crates/kernel/src/service/gateway/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl GatewayBuilder {
}
pub fn http_routers(mut self, routes: impl IntoIterator<Item = (String, HttpRoute)>) -> Self {
for (name, mut route) in routes {
route.name = name.clone();
route.name.clone_from(&name);
self.http_routers.insert(name, route);
}
self
Expand Down
2 changes: 1 addition & 1 deletion crates/kernel/src/utils/fold_box_layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{ArcHyperService, BoxLayer};

/// Fold layers into a single service,
/// the order of the layers is reversed.
pub fn fold_layers<'a>(layers: impl Iterator<Item = &'a BoxLayer> + std::iter::DoubleEndedIterator, mut inner: ArcHyperService) -> ArcHyperService {
pub fn fold_layers<'a>(layers: impl std::iter::DoubleEndedIterator<Item = &'a BoxLayer>, mut inner: ArcHyperService) -> ArcHyperService {
for l in layers.rev() {
inner = l.layer_shared(inner);
}
Expand Down
3 changes: 1 addition & 2 deletions crates/model/src/ext/k8s/helper_struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::hash::{Hash, Hasher};

#[derive(Clone)]
pub struct SgSingeFilter {
pub name: String,
Expand All @@ -8,6 +6,7 @@ pub struct SgSingeFilter {
pub target_ref: Option<super::crd::sg_filter::K8sSgFilterSpecTargetRef>,
}

//TODO remove
// impl PartialEq for SgSingeFilter {
// fn eq(&self, other: &Self) -> bool {
// self.name == other.name
Expand Down
10 changes: 5 additions & 5 deletions crates/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ pub async fn startup_file(conf_dir: impl AsRef<std::path::Path>) -> Result<(), B
/// The `namespace` is the k8s namespace.
/// If the `namespace` is None, it will use the default namespace.
pub async fn startup_k8s(namespace: Option<&str>) -> Result<(), BoxError> {
// use spacegate_config::service::backend::k8s::K8s;
// let namespace = namespace.unwrap_or("default");
// let config = K8s::new(namespace, kube::Client::try_default().await?);
// startup(config)
unimplemented!()
use spacegate_config::service::k8s::K8s;

let namespace = namespace.unwrap_or("default");
let config = K8s::with_default_client(namespace).await?;
startup(config).await
}
#[cfg(feature = "cache")]
/// # Startup the gateway by redis
Expand Down

0 comments on commit a177e45

Please sign in to comment.