Skip to content

Commit

Permalink
Fix CustomResource apiVersion for the default group
Browse files Browse the repository at this point in the history
CustomResources generated broken URLs for Kinds in the default API
group, like Services, ConfigMaps and so on. That lead to strange 403
responses by the API server.
  • Loading branch information
twz123 committed Jul 18, 2020
1 parent 29cfca6 commit 5dbb322
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion kube/src/api/crds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ impl CrBuilder {
let version = self.version.expect("Crd must have a version");
let group = self.group.expect("Crd must have a group");
CustomResource {
api_version: format!("{}/{}", group, version),
api_version: if group == "" {
version.clone()
} else {
format!("{}/{}", group, version)
},
kind: self.kind,
version,
group,
Expand Down Expand Up @@ -157,6 +161,18 @@ mod test {
assert_eq!(req.method(), "PATCH");
}

#[test]
fn raw_resource_in_default_group() {
let r: Resource = CustomResource::kind("Service")
.group("")
.version("v1")
.into_resource();

let pp = PostParams::default();
let req = r.create(&pp, vec![]).unwrap();
assert_eq!(req.uri(), "/api/v1/services?");
}

#[tokio::test]
#[ignore] // circle has no kubeconfig
async fn convenient_custom_resource() {
Expand Down

0 comments on commit 5dbb322

Please sign in to comment.