Skip to content

Commit

Permalink
Merge branch 'master' into moustafab/applier-hang
Browse files Browse the repository at this point in the history
  • Loading branch information
moustafab authored Jun 3, 2022
2 parents c90c88a + 80272c0 commit 3848060
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 94 deletions.
29 changes: 28 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,36 @@ UNRELEASED
===================
* see https://github.com/kube-rs/kube-rs/compare/0.73.0...master

0.73.0 / 2022-05-23
[0.73.0](https://github.com/kube-rs/kube-rs/releases/tag/0.73.0) / 2022-05-23
===================

## Highlights

### [New `k8s-openapi` version and MSRV](https://github.com/kube-rs/kube-rs/pull/916)

Support added for Kubernetes `v1_24` support via the [new `k8s-openapi` version](https://github.com/Arnavion/k8s-openapi/releases/tag/v0.15.0). Please also run `cargo upgrade --workspace k8s-openapi` when upgrading `kube`.

This also bumps our [MSRV](https://rust-lang.github.io/rfcs/2495-min-rust-version.html) to [`1.60.0`](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html).

### [Reconciler change](https://github.com/kube-rs/kube-rs/pull/910)
A small ergonomic change in the `reconcile` signature has removed the need for the `Context` object. This has been replaced by an [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html). The following change is needed in your controller:

```diff
-async fn reconcile(doc: Arc<MyObject>, context: Context<Data>) -> Result<Action, Error>
+async fn reconcile(doc: Arc<MyObject>, context: Arc<Data>) -> Result<Action, Error>
```

This will simplify the usage of the `context` argument. You should no longer need to pass `.get_ref()` on its every use.
See the [controller-rs upgrade change for details](https://github.com/kube-rs/controller-rs/commit/2976e046409ec033b86dfe8d60173ebc2b4e5dbf#diff-7143adb2b6aaf4eac74de6b133c6a9cf6d2d34bf6929972361f93100abdfc074).

## What's Changed
### Added
* Add Discovery::groups_alphabetical following kubectl sort order by @clux in https://github.com/kube-rs/kube-rs/pull/887
### Changed
* Replace runtime::controller::Context with Arc by @teozkr in https://github.com/kube-rs/kube-rs/pull/910
* runtime: Return the object from `await_condition` by @olix0r in https://github.com/kube-rs/kube-rs/pull/877
* Bump k8s-openapi to 0.15 for kubernetes v1_24 and bump MSRV to 1.60 by @clux in https://github.com/kube-rs/kube-rs/pull/916

[0.72.0](https://github.com/kube-rs/kube-rs/releases/tag/0.72.0) / 2022-05-13
===================

Expand Down
8 changes: 4 additions & 4 deletions examples/crd_apply.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Generated types support documentation
#![deny(missing_docs)]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use tracing::*;
Expand All @@ -11,10 +13,7 @@ use kube::{
Client, CustomResource, CustomResourceExt,
};

// NB: This example uses server side apply and beta1 customresources
// Please test against Kubernetes 1.16.X!

// Own custom resource
/// Spec object for Foo
#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
#[kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced)]
#[kube(status = "FooStatus")]
Expand All @@ -25,6 +24,7 @@ pub struct FooSpec {
replicas: isize,
}

/// Status object for Foo
#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
pub struct FooStatus {
is_bad: bool,
Expand Down
1 change: 0 additions & 1 deletion examples/crd_derive_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use serde::{Deserialize, Serialize};
derive = "PartialEq",
derive = "Default"
)]
#[kube(apiextensions = "v1")]
pub struct FooSpec {
// Non-nullable without default is required.
//
Expand Down
2 changes: 0 additions & 2 deletions kube-core/src/crd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions as apiexts;
pub mod v1 {
use super::apiexts::v1::CustomResourceDefinition as Crd;
/// Extension trait that is implemented by kube-derive
///
/// This trait variant is implemented by default (or when `#[kube(apiextensions = "v1")]`)
pub trait CustomResourceExt {
/// Helper to generate the CRD including the JsonSchema
///
Expand Down
108 changes: 33 additions & 75 deletions kube-derive/src/custom_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ struct KubeAttrs {
singular: Option<String>,
#[darling(default)]
namespaced: bool,
#[darling(default = "default_apiext")]
apiextensions: String,
#[darling(multiple, rename = "derive")]
derives: Vec<String>,
schema: Option<SchemaMode>,
Expand Down Expand Up @@ -84,10 +82,6 @@ impl Crates {
}
}

fn default_apiext() -> String {
"v1".to_owned()
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
enum SchemaMode {
Disabled,
Expand Down Expand Up @@ -159,7 +153,6 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
categories,
shortnames,
printcolums,
apiextensions,
scale,
crates:
Crates {
Expand Down Expand Up @@ -231,12 +224,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
}
}

// Enable schema generation by default for v1 because it's mandatory.
let schema_mode = schema_mode.unwrap_or(if apiextensions == "v1" {
SchemaMode::Derived
} else {
SchemaMode::Disabled
});
// Enable schema generation by default as in v1 it is mandatory.
let schema_mode = schema_mode.unwrap_or(SchemaMode::Derived);
// We exclude fields `apiVersion`, `kind`, and `metadata` from our schema because
// these are validated by the API server implicitly. Also, we can't generate the
// schema for `metadata` (`ObjectMeta`) because it doesn't implement `JsonSchema`.
Expand All @@ -252,6 +241,8 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
let docstr = format!(" Auto-generated derived type for {} via `CustomResource`", ident);
let root_obj = quote! {
#[doc = #docstr]
#[automatically_derived]
#[allow(missing_docs)]
#[derive(#(#derive_paths),*)]
#[serde(rename_all = "camelCase")]
#visibility struct #rootident {
Expand All @@ -261,6 +252,7 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
#status_field
}
impl #rootident {
/// Spec based constructor for derived custom resource
pub fn new(name: &str, spec: #ident) -> Self {
Self {
metadata: #k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta {
Expand Down Expand Up @@ -346,20 +338,15 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
// 4. Implement CustomResource

// Compute a bunch of crd props
let mut printers = format!("[ {} ]", printcolums.join(",")); // hacksss
if apiextensions == "v1beta1" {
// only major api inconsistency..
printers = printers.replace("jsonPath", "JSONPath");
}
let printers = format!("[ {} ]", printcolums.join(",")); // hacksss
let scale_code = if let Some(s) = scale { s } else { "".to_string() };

// Ensure it generates for the correct CRD version
let v1ident = format_ident!("{}", apiextensions);
// Ensure it generates for the correct CRD version (only v1 supported now)
let apiext = quote! {
#k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::#v1ident
#k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1
};
let extver = quote! {
#kube_core::crd::#v1ident
#kube_core::crd::v1
};

let shortnames_slice = {
Expand Down Expand Up @@ -396,61 +383,33 @@ pub(crate) fn derive(input: proc_macro2::TokenStream) -> proc_macro2::TokenStrea
}
};

let jsondata = if apiextensions == "v1" {
quote! {
#schemagen

let jsondata = #serde_json::json!({
"metadata": #crd_meta,
"spec": {
"group": #group,
"scope": #scope,
"names": {
"categories": categories,
"plural": #plural,
"singular": #name,
"kind": #kind,
"shortNames": shorts
let jsondata = quote! {
#schemagen

let jsondata = #serde_json::json!({
"metadata": #crd_meta,
"spec": {
"group": #group,
"scope": #scope,
"names": {
"categories": categories,
"plural": #plural,
"singular": #name,
"kind": #kind,
"shortNames": shorts
},
"versions": [{
"name": #version,
"served": true,
"storage": true,
"schema": {
"openAPIV3Schema": schema,
},
"versions": [{
"name": #version,
"served": true,
"storage": true,
"schema": {
"openAPIV3Schema": schema,
},
"additionalPrinterColumns": columns,
"subresources": subres,
}],
}
});
}
} else {
// TODO Include schema if enabled
quote! {
let jsondata = #serde_json::json!({
"metadata": #crd_meta,
"spec": {
"group": #group,
"scope": #scope,
"names": {
"categories": categories,
"plural": #plural,
"singular": #name,
"kind": #kind,
"shortNames": shorts
},
// printer columns can't be on versions reliably in v1beta..
"additionalPrinterColumns": columns,
"versions": [{
"name": #version,
"served": true,
"storage": true,
}],
"subresources": subres,
}
});
}
}],
}
});
};

// Implement the CustomResourceExt trait to allow users writing generic logic on top of them
Expand Down Expand Up @@ -641,6 +600,5 @@ mod tests {
};
let input = syn::parse2(input).unwrap();
let kube_attrs = KubeAttrs::from_derive_input(&input).unwrap();
assert_eq!(kube_attrs.apiextensions, "v1");
}
}
11 changes: 2 additions & 9 deletions kube-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ mod custom_resource;
///
/// # Optional `#[kube]` attributes
///
/// ## `#[kube(apiextensions = "v1beta1")]`
/// The version for `CustomResourceDefinition` desired in the `apiextensions.k8s.io` group.
/// Default is `v1` (for clusters >= 1.17). If using kubernetes <= 1.16 please use `v1beta1`.
///
/// - **NOTE**: Support for `v1` requires deriving the openapi v3 `JsonSchema` via the `schemars` dependency.
/// - **NOTE**: When using `v1beta` the associated `CustomResourceExt` trait lives in `kube::core::crd::v1beta`
///
/// ## `#[kube(singular = "nonstandard-singular")]`
/// To specify the singular name. Defaults to lowercased `kind`.
///
Expand Down Expand Up @@ -122,9 +115,9 @@ mod custom_resource;
/// This can be used to provide a completely custom schema, or to interact with third-party custom resources
/// where you are not responsible for installing the `CustomResourceDefinition`.
///
/// Defaults to `"disabled"` when `apiextensions = "v1beta1"`, otherwise `"derived"`.
/// Defaults to `"derived"`.
///
/// NOTE: `apiextensions = "v1"` `CustomResourceDefinition`s require a schema. If `schema = "disabled"` then
/// NOTE: `CustomResourceDefinition`s require a schema. If `schema = "disabled"` then
/// `Self::crd()` will not be installable into the cluster as-is.
///
/// ## `#[kube(scale = r#"json"#)]`
Expand Down
1 change: 0 additions & 1 deletion kube-derive/tests/crd_enum_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};

#[derive(CustomResource, Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[kube(group = "clux.dev", version = "v1", kind = "FooEnum")]
#[kube(apiextensions = "v1")]
#[serde(rename_all = "camelCase")]
#[allow(clippy::enum_variant_names)]
enum FooEnumSpec {
Expand Down
1 change: 0 additions & 1 deletion kube-derive/tests/crd_schema_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::collections::HashMap;
shortname = "fo",
shortname = "f"
)]
#[kube(apiextensions = "v1")]
#[serde(rename_all = "camelCase")]
struct FooSpec {
non_nullable: String,
Expand Down

0 comments on commit 3848060

Please sign in to comment.