From 31304ef2085e7225ce10d3897bd3fe56fa870922 Mon Sep 17 00:00:00 2001 From: RWDai <27391645+RWDai@users.noreply.github.com> Date: Thu, 25 Apr 2024 03:26:48 +0000 Subject: [PATCH] update --- .../service/k8s/convert/filter_k8s_conv.rs | 218 +++++++++++------- .../src/service/k8s/convert/route_k8s_conv.rs | 53 ++++- crates/config/src/service/k8s/retrieve.rs | 61 +++-- crates/model/src/constants.rs | 7 +- crates/model/src/ext/k8s/crd/sg_filter.rs | 3 - crates/model/src/plugin.rs | 6 + crates/shell/res/spacegate-gateway.yaml | 3 - crates/shell/res/spacegate-httproute.yaml | 2 - 8 files changed, 214 insertions(+), 139 deletions(-) diff --git a/crates/config/src/service/k8s/convert/filter_k8s_conv.rs b/crates/config/src/service/k8s/convert/filter_k8s_conv.rs index b5e9b34d..40977573 100644 --- a/crates/config/src/service/k8s/convert/filter_k8s_conv.rs +++ b/crates/config/src/service/k8s/convert/filter_k8s_conv.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; -use k8s_gateway_api::{HttpHeader, HttpPathModifier, HttpRequestHeaderFilter, HttpRequestRedirectFilter, HttpRouteFilter, HttpUrlRewriteFilter}; -use kube::Api; -use spacegate_model::ext::k8s::crd::sg_filter::SgFilter; +use k8s_gateway_api::{HttpHeader, HttpPathModifier, HttpRequestHeaderFilter, HttpRequestRedirectFilter, HttpRouteFilter, HttpUrlRewriteFilter, LocalObjectReference}; +use kube::{Api, ResourceExt}; +use spacegate_model::{constants::SG_FILTER_KIND, ext::k8s::crd::sg_filter::SgFilter}; use crate::{ ext::k8s::{ @@ -21,8 +21,6 @@ use crate::{ }; pub(crate) trait PluginIdConv { - fn from_http_route_filter(route_filter: HttpRouteFilter) -> BoxResult; - /// # to_singe_filter /// `to_single_filter` method and [SgRouteFilter::to_http_route_filter] method both convert from /// `SgRouteFilter`to the k8s model. The difference lies in that `to_single_filter` only includes @@ -32,13 +30,17 @@ pub(crate) trait PluginIdConv { /// # to_http_route_filter /// ref [SgRouteFilter::to_singe_filter] + /// can be use in rule level and backend level async fn to_http_route_filter(self, client: &K8s) -> Option; + fn from_http_route_filter(route_filter: HttpRouteFilter) -> Option; + + /// can be ues in gateway and route level async fn add_filter_target(&self, target: K8sSgFilterSpecTargetRef, client: &K8s); - /// mix of [SgRouteFilter::to_singe_filter] and [SgRouteFilter::to_http_route_filter] - /// PluginInstanceId can be converted into `SgRouteFilter` or `HttpRouteFilter` - async fn to_route_filter_or_add_filter_target(&self, target: K8sSgFilterSpecTargetRef, client: &K8s) -> Option; + // mix of [SgRouteFilter::to_singe_filter] and [SgRouteFilter::to_http_route_filter] + // PluginInstanceId can be converted into `SgRouteFilter` or `HttpRouteFilter` + // async fn to_route_filter_or_add_filter_target(&self, target: K8sSgFilterSpecTargetRef, client: &K8s) -> Option; } impl PluginIdConv for PluginInstanceId { @@ -109,7 +111,17 @@ impl PluginIdConv for PluginInstanceId { None } } else { - None + match self.name { + PluginInstanceName::Anon { uid: _ } => None, + PluginInstanceName::Named { name } => Some(HttpRouteFilter::ExtensionRef { + extension_ref: LocalObjectReference { + group: "".to_string(), + kind: SG_FILTER_KIND.to_string(), + name, + }, + }), + PluginInstanceName::Mono => None, + } } } else { None @@ -119,92 +131,120 @@ impl PluginIdConv for PluginInstanceId { } } - fn from_http_route_filter(route_filter: HttpRouteFilter) -> BoxResult { - let process_header_modifier = |header_modifier: HttpRequestHeaderFilter, modifier_kind: SgFilterHeaderModifierKind| -> BoxResult { - let mut sg_sets = HashMap::new(); - if let Some(adds) = header_modifier.add { - for add in adds { - sg_sets.insert(add.name, add.value); - } - } - if let Some(sets) = header_modifier.set { - for set in sets { - sg_sets.insert(set.name, set.value); - } - } + // fn from_http_route_filter(route_filter: HttpRouteFilter) -> BoxResult { + // let process_header_modifier = |header_modifier: HttpRequestHeaderFilter, modifier_kind: SgFilterHeaderModifierKind| -> BoxResult { + // let mut sg_sets = HashMap::new(); + // if let Some(adds) = header_modifier.add { + // for add in adds { + // sg_sets.insert(add.name, add.value); + // } + // } + // if let Some(sets) = header_modifier.set { + // for set in sets { + // sg_sets.insert(set.name, set.value); + // } + // } - Ok(PluginConfig { - id: PluginInstanceId { - code: SG_FILTER_HEADER_MODIFIER_CODE.into(), - name: PluginInstanceName::Mono {}, - }, - spec: serde_json::to_value(SgFilterHeaderModifier { - kind: modifier_kind, - sets: if sg_sets.is_empty() { None } else { Some(sg_sets) }, - remove: header_modifier.remove, - })?, - }) - }; - let sg_filter = match route_filter { - k8s_gateway_api::HttpRouteFilter::RequestHeaderModifier { request_header_modifier } => { - process_header_modifier(request_header_modifier, SgFilterHeaderModifierKind::Request)? - } - k8s_gateway_api::HttpRouteFilter::ResponseHeaderModifier { response_header_modifier } => { - process_header_modifier(response_header_modifier, SgFilterHeaderModifierKind::Response)? - } - k8s_gateway_api::HttpRouteFilter::RequestRedirect { request_redirect } => PluginConfig { - id: PluginInstanceId { - code: SG_FILTER_REDIRECT_CODE.into(), - name: PluginInstanceName::Mono {}, - }, - spec: serde_json::to_value(SgFilterRedirect { - scheme: request_redirect.scheme, - hostname: request_redirect.hostname, - path: request_redirect.path.map(|path| match path { - k8s_gateway_api::HttpPathModifier::ReplaceFullPath { replace_full_path } => SgHttpPathModifier { - kind: SgHttpPathModifierType::ReplaceFullPath, - value: replace_full_path, - }, - k8s_gateway_api::HttpPathModifier::ReplacePrefixMatch { replace_prefix_match } => SgHttpPathModifier { - kind: SgHttpPathModifierType::ReplacePrefixMatch, - value: replace_prefix_match, - }, - }), - port: request_redirect.port, - status_code: request_redirect.status_code, - })?, - }, - k8s_gateway_api::HttpRouteFilter::URLRewrite { url_rewrite } => PluginConfig { - id: PluginInstanceId { - code: SG_FILTER_REWRITE_CODE.into(), - name: PluginInstanceName::Mono {}, - }, - spec: serde_json::to_value(SgFilterRewrite { - hostname: url_rewrite.hostname, - path: url_rewrite.path.map(|path| match path { - k8s_gateway_api::HttpPathModifier::ReplaceFullPath { replace_full_path } => SgHttpPathModifier { - kind: SgHttpPathModifierType::ReplaceFullPath, - value: replace_full_path, - }, - k8s_gateway_api::HttpPathModifier::ReplacePrefixMatch { replace_prefix_match } => SgHttpPathModifier { - kind: SgHttpPathModifierType::ReplacePrefixMatch, - value: replace_prefix_match, - }, - }), - })?, - }, - k8s_gateway_api::HttpRouteFilter::RequestMirror { .. } => return Err("[SG.Common] HttpRoute [spec.rules.filters.type=RequestMirror] not supported yet".into()), - k8s_gateway_api::HttpRouteFilter::ExtensionRef { .. } => return Err("[SG.Common] HttpRoute [spec.rules.filters.type=ExtensionRef] not supported yet".into()), - }; - Ok(sg_filter) - } + // Ok(PluginConfig { + // id: PluginInstanceId { + // code: SG_FILTER_HEADER_MODIFIER_CODE.into(), + // name: PluginInstanceName::Mono {}, + // }, + // spec: serde_json::to_value(SgFilterHeaderModifier { + // kind: modifier_kind, + // sets: if sg_sets.is_empty() { None } else { Some(sg_sets) }, + // remove: header_modifier.remove, + // })?, + // }) + // }; + // let sg_filter = match route_filter { + // k8s_gateway_api::HttpRouteFilter::RequestHeaderModifier { request_header_modifier } => { + // process_header_modifier(request_header_modifier, SgFilterHeaderModifierKind::Request)? + // } + // k8s_gateway_api::HttpRouteFilter::ResponseHeaderModifier { response_header_modifier } => { + // process_header_modifier(response_header_modifier, SgFilterHeaderModifierKind::Response)? + // } + // k8s_gateway_api::HttpRouteFilter::RequestRedirect { request_redirect } => PluginConfig { + // id: PluginInstanceId { + // code: SG_FILTER_REDIRECT_CODE.into(), + // name: PluginInstanceName::Mono {}, + // }, + // spec: serde_json::to_value(SgFilterRedirect { + // scheme: request_redirect.scheme, + // hostname: request_redirect.hostname, + // path: request_redirect.path.map(|path| match path { + // k8s_gateway_api::HttpPathModifier::ReplaceFullPath { replace_full_path } => SgHttpPathModifier { + // kind: SgHttpPathModifierType::ReplaceFullPath, + // value: replace_full_path, + // }, + // k8s_gateway_api::HttpPathModifier::ReplacePrefixMatch { replace_prefix_match } => SgHttpPathModifier { + // kind: SgHttpPathModifierType::ReplacePrefixMatch, + // value: replace_prefix_match, + // }, + // }), + // port: request_redirect.port, + // status_code: request_redirect.status_code, + // })?, + // }, + // k8s_gateway_api::HttpRouteFilter::URLRewrite { url_rewrite } => PluginConfig { + // id: PluginInstanceId { + // code: SG_FILTER_REWRITE_CODE.into(), + // name: PluginInstanceName::Mono {}, + // }, + // spec: serde_json::to_value(SgFilterRewrite { + // hostname: url_rewrite.hostname, + // path: url_rewrite.path.map(|path| match path { + // k8s_gateway_api::HttpPathModifier::ReplaceFullPath { replace_full_path } => SgHttpPathModifier { + // kind: SgHttpPathModifierType::ReplaceFullPath, + // value: replace_full_path, + // }, + // k8s_gateway_api::HttpPathModifier::ReplacePrefixMatch { replace_prefix_match } => SgHttpPathModifier { + // kind: SgHttpPathModifierType::ReplacePrefixMatch, + // value: replace_prefix_match, + // }, + // }), + // })?, + // }, + // k8s_gateway_api::HttpRouteFilter::RequestMirror { .. } => return Err("[SG.Common] HttpRoute [spec.rules.filters.type=RequestMirror] not supported yet".into()), + // k8s_gateway_api::HttpRouteFilter::ExtensionRef { .. } => return Err("[SG.Common] HttpRoute [spec.rules.filters.type=ExtensionRef] not supported yet".into()), + // }; + // Ok(sg_filter) + // } async fn add_filter_target(&self, target: K8sSgFilterSpecTargetRef, client: &K8s) { todo!() } - async fn to_route_filter_or_add_filter_target(&self, target: K8sSgFilterSpecTargetRef, client: &K8s) -> Option { - todo!() + fn from_http_route_filter(route_filter: HttpRouteFilter) -> Option { + match route_filter { + HttpRouteFilter::RequestHeaderModifier { request_header_modifier } => None, + HttpRouteFilter::ResponseHeaderModifier { response_header_modifier } => None, + HttpRouteFilter::RequestMirror { request_mirror } => None, + HttpRouteFilter::RequestRedirect { request_redirect } => None, + HttpRouteFilter::URLRewrite { url_rewrite } => None, + HttpRouteFilter::ExtensionRef { extension_ref } => Some(PluginInstanceId { + code: extension_ref.kind.into(), + name: PluginInstanceName::Named { name: extension_ref.name }, + }), + } + } +} + +pub(crate) trait PluginConfigConv { + fn from_first_filter_obj(filter_obj: SgFilter) -> Option; +} + +impl PluginConfigConv for PluginConfig { + fn from_first_filter_obj(filter_obj: SgFilter) -> Option { + filter_obj.spec.filters.into_iter().filter(|f| f.enable).next().map(|f| PluginConfig { + id: PluginInstanceId { + code: f.code.into(), + name: PluginInstanceName::Named { + name: f.name.unwrap_or(filter_obj.name_any()), + }, + }, + spec: f.config, + }) } } diff --git a/crates/config/src/service/k8s/convert/route_k8s_conv.rs b/crates/config/src/service/k8s/convert/route_k8s_conv.rs index c859a998..1c4b911d 100644 --- a/crates/config/src/service/k8s/convert/route_k8s_conv.rs +++ b/crates/config/src/service/k8s/convert/route_k8s_conv.rs @@ -98,9 +98,48 @@ impl SgHttpRouteRuleConv for SgHttpRouteRule { } fn from_kube_httproute(rule: http_spaceroute::HttpRouteRule) -> BoxResult { + let (ext_plugins, legacy_plugins): (Vec<_>, Vec<_>) = + 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() { + 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() { + return Err("request_header_modifier is not supported with multiple matches".into()); + } + Some(matches.into_iter().map(|m| SgHttpRouteMatch::from_kube_httproute(m)).collect::>()) + } else if let Some(match_) = matches.pop() { + let mut m = SgHttpRouteMatch::from_kube_httproute(match_); + if legacy_plugins.iter().filter(|p| matches!(p, HttpRouteFilter::URLRewrite { url_rewrite: _ })).count() > 1 { + return Err("url_rewrite can only have one in each rule".into()); + } else if let Some(url_rewrite) = legacy_plugins.iter().find(|p| matches!(p, HttpRouteFilter::URLRewrite { url_rewrite: _ })) { + m.path.map(|m_p| match url_rewrite { + HttpRouteFilter::URLRewrite { url_rewrite } => { + if let Some(rewrite_path) = url_rewrite.path { + match m_p { + SgHttpPathMatch::Exact { value, replace } => match rewrite_path { + HttpPathModifier::ReplaceFullPath { replace_full_path } => todo!(), + HttpPathModifier::ReplacePrefixMatch { replace_prefix_match } => todo!(), + }, + SgHttpPathMatch::Prefix { value, replace } => todo!(), + SgHttpPathMatch::RegExp { value, replace } => todo!(), + } + } + } + _ => unreachable!(), + }); + } + Some(vec![m]) + } else { + Some(vec![]) + } + } else { + None + }; Ok(SgHttpRouteRule { - matches: rule.matches.map(|m_vec| m_vec.into_iter().map(SgHttpRouteMatch::from_kube_httproute).collect::>()), - plugins: rule.filters.map(|f_vec| f_vec.into_iter().map(PluginConfig::from_http_route_filter).collect::>>()).transpose()?.unwrap_or_default(), + matches, + plugins: ext_plugins.into_iter().filter_map(|f| PluginInstanceId::from_http_route_filter(f)).collect(), backends: rule .backend_refs .map(|b_vec| b_vec.into_iter().filter_map(|b| SgBackendRef::from_kube_httproute(b).transpose()).collect::>>()) @@ -271,8 +310,8 @@ impl SgBackendRefConv for SgBackendRef { let backend_inner_ref = match self.host { BackendHost::Host { host } => { let kind = match self.protocol { - Some(SgBackendProtocol::Https) => Some(constants::BANCKEND_KIND_EXTERNAL_HTTPS.to_string()), - _ => Some(constants::BANCKEND_KIND_EXTERNAL_HTTP.to_string()), + Some(SgBackendProtocol::Https) => Some(constants::BACKEND_KIND_EXTERNAL_HTTPS.to_string()), + _ => Some(constants::BACKEND_KIND_EXTERNAL_HTTP.to_string()), }; BackendObjectReference { group: None, @@ -306,15 +345,15 @@ impl SgBackendRefConv for SgBackendRef { .map(|backend| { let (protocol, backend_host) = if let Some(kind) = backend.inner.kind.as_ref() { match kind.as_str() { - constants::BANCKEND_KIND_SERVICE => ( + constants::BACKEND_KIND_SERVICE => ( None, BackendHost::K8sService(K8sServiceData { name: backend.inner.name, namespace: backend.inner.namespace, }), ), - constants::BANCKEND_KIND_EXTERNAL_HTTP => (Some(gateway::SgBackendProtocol::Http), BackendHost::Host { host: backend.inner.name }), - constants::BANCKEND_KIND_EXTERNAL_HTTPS => (Some(gateway::SgBackendProtocol::Https), BackendHost::Host { host: backend.inner.name }), + constants::BACKEND_KIND_EXTERNAL_HTTP => (Some(gateway::SgBackendProtocol::Http), BackendHost::Host { host: backend.inner.name }), + constants::BACKEND_KIND_EXTERNAL_HTTPS => (Some(gateway::SgBackendProtocol::Https), BackendHost::Host { host: backend.inner.name }), _ => (None, BackendHost::Host { host: backend.inner.name }), } } else { diff --git a/crates/config/src/service/k8s/retrieve.rs b/crates/config/src/service/k8s/retrieve.rs index cc310771..0706206c 100644 --- a/crates/config/src/service/k8s/retrieve.rs +++ b/crates/config/src/service/k8s/retrieve.rs @@ -4,7 +4,13 @@ use http_route::SgHttpRouteRule; use k8s_gateway_api::{Gateway, HttpRoute, Listener}; use k8s_openapi::api::core::v1::Secret; use kube::{api::ListParams, Api, ResourceExt}; -use spacegate_model::ext::k8s::crd::{http_spaceroute::HttpSpaceroute, sg_filter::SgFilter}; +use spacegate_model::{ + ext::k8s::crd::{ + http_spaceroute::HttpSpaceroute, + sg_filter::{K8sSgFilterSpecTargetRef, SgFilter, SgFilterTargetKind}, + }, + PluginInstanceId, +}; use crate::{ constants::{self, GATEWAY_CLASS_NAME}, @@ -13,7 +19,10 @@ use crate::{ BoxError, BoxResult, }; -use super::K8s; +use super::{ + convert::{filter_k8s_conv::PluginConfigConv, gateway_k8s_conv::SgParametersConv as _, route_k8s_conv::SgHttpRouteRuleConv as _}, + K8s, +}; impl Retrieve for K8s { async fn retrieve_config_item_gateway(&self, gateway_name: &str) -> BoxResult> { @@ -124,39 +133,27 @@ impl Retrieve for K8s { } async fn retrieve_all_plugins(&self) -> Result, BoxError> { - let filter_api: Api = self.get_namespace_api(); - - let result = filter_api.list(&ListParams::default()).await?.iter().map(|gateway| gateway.to_pluginconfig()).collect(); + let filter_api: Api = self.get_namespace_api(); - Ok(result) + let result = filter_api.list(&ListParams::default()).await?.into_iter().filter_map(|filter_obj| PluginConfig::from_first_filter_obj(filter_obj)).collect(); + Ok(result) } async fn retrieve_plugin(&self, id: &spacegate_model::PluginInstanceId) -> Result, BoxError> { let filter_api: Api = self.get_namespace_api(); - match id.name { - spacegate_model::PluginInstanceName::Anon { uid } => Ok(None), + match &id.name { + spacegate_model::PluginInstanceName::Anon { uid: _ } => Ok(None), spacegate_model::PluginInstanceName::Named { name } => { - let result = if let Some(gateway_obj) = filter_api.get_opt(&name).await?.and_then(|gateway_obj| { - if gateway_obj.spec. == GATEWAY_CLASS_NAME { - Some(gateway_obj) - } else { - None - } - }) { - Some() - } else { - None - } + let result = filter_api.get_opt(&name).await?.and_then(|filter_obj| PluginConfig::from_first_filter_obj(filter_obj)); Ok(result) } spacegate_model::PluginInstanceName::Mono => Ok(None), } - } async fn retrieve_plugins_by_code(&self, code: &str) -> Result, BoxError> { - todo!() + Ok(self.retrieve_all_plugins().await?.into_iter().filter(|p| p.code() == code).collect()) } } @@ -180,17 +177,17 @@ impl K8s { } async fn kube_httpspaceroute_2_sg_route(&self, httpspace_route: HttpSpaceroute) -> BoxResult { + let route_name = httpspace_route.name_any(); let kind = if let Some(kind) = httpspace_route.annotations().get(constants::RAW_HTTP_ROUTE_KIND) { kind.clone() } else { SgFilterTargetKind::Httpspaceroute.into() }; let priority = httpspace_route.annotations().get(crate::constants::ANNOTATION_RESOURCE_PRIORITY).and_then(|a| a.parse::().ok()).unwrap_or(0); - let gateway_refs = httpspace_route.spec.inner.parent_refs.clone().unwrap_or_default(); - let filters = self + let plugins = self .retrieve_config_item_filters(K8sSgFilterSpecTargetRef { kind, - name: httpspace_route.name_any(), + name: route_name.clone(), namespace: httpspace_route.namespace(), }) .await?; @@ -204,7 +201,7 @@ impl K8s { .transpose()? .unwrap_or_default(), priority, - route_name: httpspace_route.name_any(), + route_name, }) } @@ -212,13 +209,13 @@ impl K8s { self.kube_httpspaceroute_2_sg_route(http_route.into()).await } - async fn retrieve_config_item_filters(&self, target: K8sSgFilterSpecTargetRef) -> BoxResult> { + async fn retrieve_config_item_filters(&self, target: K8sSgFilterSpecTargetRef) -> BoxResult> { let kind = target.kind; let name = target.name; let namespace = target.namespace.unwrap_or(self.namespace.to_string()); let filter_api: Api = self.get_all_api(); - let filter_objs: Vec = filter_api + let plugin_ids: Vec = filter_api .list(&ListParams::default()) .await .map_err(Box::new)? @@ -230,19 +227,19 @@ impl K8s { && target_ref.namespace.as_deref().unwrap_or("default").eq_ignore_ascii_case(&namespace) }) }) - .flat_map(|filter_obj| filter_obj.spec.filters.into_iter().map(|filter| PluginConfig { spec: filter.config, id: todo!() })) + .flat_map(|filter_obj| PluginConfig::from_first_filter_obj(filter_obj).map(|f| f.into())) .collect(); - if !filter_objs.is_empty() { + if !plugin_ids.is_empty() { let mut filter_vec = String::new(); - filter_objs.clone().into_iter().for_each(|filter| filter_vec.push_str(&format!("Filter{{code: {},name:{}}},", filter.code, filter.name.unwrap_or("None".to_string())))); + plugin_ids.clone().into_iter().for_each(|id| filter_vec.push_str(&format!("plugin:{{id:{}}},", id.to_string()))); tracing::trace!("[SG.Common] {namespace}.{kind}.{name} filter found: {}", filter_vec.trim_end_matches(',')); } - if filter_objs.is_empty() { + if plugin_ids.is_empty() { Ok(vec![]) } else { - Ok(filter_objs) + Ok(plugin_ids) } } diff --git a/crates/model/src/constants.rs b/crates/model/src/constants.rs index c799a389..6aef3f0a 100644 --- a/crates/model/src/constants.rs +++ b/crates/model/src/constants.rs @@ -4,6 +4,7 @@ pub const GATEWAY_ANNOTATION_LOG_LEVEL: &str = "log_level"; pub const GATEWAY_ANNOTATION_LANGUAGE: &str = "lang"; pub const GATEWAY_ANNOTATION_IGNORE_TLS_VERIFICATION: &str = "ignore_tls_verification"; +pub const SG_FILTER_KIND: &str = "sgfilter"; pub const DEFAULT_NAMESPACE: &str = "default"; pub const ANNOTATION_RESOURCE_PRIORITY: &str = "priority"; @@ -11,8 +12,8 @@ pub const RAW_HTTP_ROUTE_KIND: &str = "raw.http.route.kind"; pub const RAW_HTTP_ROUTE_KIND_DEFAULT: &str = "HTTPRoute"; pub const RAW_HTTP_ROUTE_KIND_SPACEROUTE: &str = "HTTPSpaceroute"; -pub const BANCKEND_KIND_SERVICE: &str = "Service"; -pub const BANCKEND_KIND_EXTERNAL_HTTP: &str = "ExternalHttp"; -pub const BANCKEND_KIND_EXTERNAL_HTTPS: &str = "ExternalHttps"; +pub const BACKEND_KIND_SERVICE: &str = "Service"; +pub const BACKEND_KIND_EXTERNAL_HTTP: &str = "ExternalHttp"; +pub const BACKEND_KIND_EXTERNAL_HTTPS: &str = "ExternalHttps"; pub const DEFAULT_API_PORT: u16 = 9876; diff --git a/crates/model/src/ext/k8s/crd/sg_filter.rs b/crates/model/src/ext/k8s/crd/sg_filter.rs index e36f9cf8..b58e24b7 100644 --- a/crates/model/src/ext/k8s/crd/sg_filter.rs +++ b/crates/model/src/ext/k8s/crd/sg_filter.rs @@ -37,9 +37,6 @@ pub struct K8sSgFilterSpecTargetRef { pub name: String, /// if namespace is None, use SgFilter's namespace pub namespace: Option, - /// if kind is `HttpspacerouteRule` or `HttpspacerouteBackend`, parent_ref must be set, otherwise target_ref will be ignored - /// value should be `Httpspaceroute`'s name - pub parent_ref: Option, } impl PartialEq for K8sSgFilterSpecTargetRef { diff --git a/crates/model/src/plugin.rs b/crates/model/src/plugin.rs index 3ffae32f..69fd27f8 100644 --- a/crates/model/src/plugin.rs +++ b/crates/model/src/plugin.rs @@ -53,6 +53,12 @@ impl ToString for PluginInstanceId { } } +impl From for PluginInstanceId { + fn from(value: PluginConfig) -> Self { + value.id + } +} + impl PluginInstanceId { pub fn new(code: impl Into>, name: PluginInstanceName) -> Self { PluginInstanceId { code: code.into(), name } diff --git a/crates/shell/res/spacegate-gateway.yaml b/crates/shell/res/spacegate-gateway.yaml index 1d5d1e0a..ef81c40a 100644 --- a/crates/shell/res/spacegate-gateway.yaml +++ b/crates/shell/res/spacegate-gateway.yaml @@ -59,9 +59,6 @@ spec: namespace: type: string minLength: 1 - parentRef: - type: string - minLength: 1 required: - kind - name diff --git a/crates/shell/res/spacegate-httproute.yaml b/crates/shell/res/spacegate-httproute.yaml index 1c99c53a..bad3c7ad 100644 --- a/crates/shell/res/spacegate-httproute.yaml +++ b/crates/shell/res/spacegate-httproute.yaml @@ -883,7 +883,6 @@ spec: minimum: 0 type: integer timeoutMs: - default: 5000 description: TimeoutMs specifies the timeout for backend by milliseconds format: int32 maximum: 10000000 @@ -1637,7 +1636,6 @@ spec: maxItems: 8 type: array timeoutMs: - default: 5000 description: TimeoutMs specifies the timeout for rules by milliseconds format: int32 maximum: 10000000