Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create APIResource from ApiResource for extension an APIService #1195

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions kube-core/src/discovery.rs
@@ -1,5 +1,6 @@
//! Type information structs for API discovery
use crate::{gvk::GroupVersionKind, resource::Resource};
use k8s_openapi::apimachinery::pkg::apis::meta::v1::APIResource;
use serde::{Deserialize, Serialize};

/// Information about a Kubernetes API resource
Expand Down Expand Up @@ -57,6 +58,20 @@
}
}

impl Into<APIResource> for ApiResource {
fn into(self) -> APIResource {
APIResource {
group: Some(self.group),
kind: self.kind,
version: Option::from(self.api_version),
namespaced: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to look at ApiCapabilites::scope currently

name: self.plural,
verbs: vec!["list".to_string(), "get".to_string()],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would come from ApiCapabilities::subresources

..Default::default()
}
}
}

/// Resource scope
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub enum Scope {
Expand Down Expand Up @@ -204,3 +219,29 @@
assert_eq!(to_plural(&kind.to_ascii_lowercase()), plural);
}
}

#[test]
fn api_resource_into_k8s_open_api_api_resource() {
let api_resource = ApiResource {
group: "apps".to_string(),
version: "v1".to_string(),
api_version: "apps/v1".to_string(),
kind: "Deployment".to_string(),
plural: "deployments".to_string(),
};
assert_eq!(

Check warning on line 232 in kube-core/src/discovery.rs

View check run for this annotation

Codecov / codecov/patch

kube-core/src/discovery.rs#L232

Added line #L232 was not covered by tests
k8s_openapi::apimachinery::pkg::apis::meta::v1::APIResource {
categories: None,
group: Some("apps".to_string()),
kind: "Deployment".to_string(),
name: "deployments".to_string(),
namespaced: true,
short_names: None,
singular_name: "".to_string(),
storage_version_hash: None,
verbs: vec!["list".to_string(), "get".to_string()],
version: Some("apps/v1".to_string())
},
api_resource.into()
);
}