use kube::Error as KubeError; use tonic::Status; pub fn kube_status(action: &str, error: KubeError) -> Status { match error { KubeError::Api(response) if response.code == 404 => { Status::not_found(format!("{action}: {}", response.message)) } KubeError::Api(response) if response.code == 401 || response.code == 403 => { Status::permission_denied(format!("{action}: {}", response.message)) } KubeError::Api(response) if response.code == 409 => { Status::already_exists(format!("{action}: {}", response.message)) } KubeError::Api(response) if response.code == 429 || response.code >= 500 => { Status::unavailable(format!("{action}: {}", response.message)) } _ => Status::internal(format!("{action}: {error}")), } }