policy: Ignore case when comparing resource kinds
Kubernetes resource type names are not case-sensitive. This change
updates `kind` and `group` comparisons to ignore case.
@@ -160,7 +160,8 @@ where
T::DynamicType: Default,
{
let dt = Default::default();
- *req.kind.group == *T::group(&dt) && *req.kind.kind == *T::kind(&dt)
+ req.kind.group.eq_ignore_ascii_case(&*T::group(&dt))
+ && req.kind.kind.eq_ignore_ascii_case(&*T::kind(&dt))
}
fn json_response(rsp: AdmissionReview) -> Result<Response<Body>, Error> {
@@ -413,15 +414,23 @@ impl Validate<ServerAuthorizationSpec> for Admission {
#[async_trait::async_trait]
impl Validate<HttpRouteSpec> for Admission {
async fn validate(self, _ns: &str, _name: &str, spec: HttpRouteSpec) -> Result<()> {
+ let targets_server = spec.inner.parent_refs.iter().flatten().any(|parent_ref| {
+ if let Some(p) = parent_ref.group.as_deref() {
+ if let Some(k) = parent_ref.kind.as_deref() {
+ return p.eq_ignore_ascii_case("policy.linkerd.io")
+ && k.eq_ignore_ascii_case("server");
+ }
+ }
+ false
+ });
// Only validate HttpRoutes which have a Server as a parent_ref.
- if spec.inner.parent_refs.iter().flatten().any(|parent_ref| {
- parent_ref.kind.as_deref() == Some("Server")
- && parent_ref.group.as_deref() == Some("policy.linkerd.io")
- }) {
+ if !targets_server {
+ return Ok(());
+ }
+
for rule in spec.rules.iter().flatten() {
validate_http_route_rule(rule)?;
}
- }
Ok(())
}
