Skip to content

Commit

Permalink
Merge branch 'main' into patch/trigger_owners_without_namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
sjbodzo authored Jan 12, 2024
2 parents c308644 + c7054b5 commit 8a0bd55
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/rust:1.65.0-bullseye
FROM docker.io/rust:1.70.0-bullseye

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt upgrade -y
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# kube-rs

[![Crates.io](https://img.shields.io/crates/v/kube.svg)](https://crates.io/crates/kube)
[![Rust 1.65](https://img.shields.io/badge/MSRV-1.65-dea584.svg)](https://github.com/rust-lang/rust/releases/tag/1.65.0)
[![Rust 1.70](https://img.shields.io/badge/MSRV-1.70-dea584.svg)](https://github.com/rust-lang/rust/releases/tag/1.70.0)
[![Tested against Kubernetes v1_23 and above](https://img.shields.io/badge/MK8SV-v1_23-326ce5.svg)](https://kube.rs/kubernetes-version)
[![Best Practices](https://bestpractices.coreinfrastructure.org/projects/5413/badge)](https://bestpractices.coreinfrastructure.org/projects/5413)
[![Discord chat](https://img.shields.io/discord/500028886025895936.svg?logo=discord&style=plastic)](https://discord.gg/tokio)
Expand Down
2 changes: 1 addition & 1 deletion kube-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/kube-rs/kube"
readme = "../README.md"
keywords = ["kubernetes", "client",]
categories = ["web-programming::http-client", "configuration", "network-programming", "api-bindings"]
rust-version = "1.65.0"
rust-version = "1.70.0"
edition = "2021"

[features]
Expand Down
2 changes: 1 addition & 1 deletion kube-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"kazk <[email protected]>",
]
edition = "2021"
rust-version = "1.65.0"
rust-version = "1.70.0"
license = "Apache-2.0"
keywords = ["kubernetes", "apimachinery"]
categories = ["api-bindings", "encoding", "parser-implementations"]
Expand Down
36 changes: 36 additions & 0 deletions kube-core/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@ pub struct TypeMeta {
pub kind: String,
}

impl TypeMeta {
/// Construct a new `TypeMeta` for the object list from the given resource.
///
/// ```
/// # use k8s_openapi::api::core::v1::Pod;
/// # use kube_core::TypeMeta;
///
/// let type_meta = TypeMeta::list::<Pod>();
/// assert_eq!(type_meta.kind, "PodList");
/// assert_eq!(type_meta.api_version, "v1");
/// ```
pub fn list<K: Resource<DynamicType = ()>>() -> Self {
TypeMeta {
api_version: K::api_version(&()).into(),
kind: K::kind(&()).to_string() + "List",
}
}

/// Construct a new `TypeMeta` for the object from the given resource.
///
/// ```
/// # use k8s_openapi::api::core::v1::Pod;
/// # use kube_core::TypeMeta;
///
/// let type_meta = TypeMeta::resource::<Pod>();
/// assert_eq!(type_meta.kind, "Pod");
/// assert_eq!(type_meta.api_version, "v1");
/// ```
pub fn resource<K: Resource<DynamicType = ()>>() -> Self {
TypeMeta {
api_version: K::api_version(&()).into(),
kind: K::kind(&()).into(),
}
}
}

/// A generic representation of any object with `ObjectMeta`.
///
/// It allows clients to get access to a particular `ObjectMeta`
Expand Down
59 changes: 53 additions & 6 deletions kube-core/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub struct ObjectList<T>
where
T: Clone,
{
// NB: kind and apiVersion can be set here, but no need for it atm
/// The type fields, always present
#[serde(flatten, default)]
pub types: TypeMeta,

/// ListMeta - only really used for its `resourceVersion`
///
/// See [ListMeta](k8s_openapi::apimachinery::pkg::apis::meta::v1::ListMeta)
Expand Down Expand Up @@ -50,11 +53,13 @@ impl<T: Clone> ObjectList<T> {
/// # Example
///
/// ```
/// use kube::api::{ListMeta, ObjectList};
/// use kube::api::{ListMeta, ObjectList, TypeMeta};
/// use k8s_openapi::api::core::v1::Pod;
///
/// let types: TypeMeta = TypeMeta::list::<Pod>();
/// let metadata: ListMeta = Default::default();
/// let items = vec![1, 2, 3];
/// let objectlist = ObjectList { metadata, items };
/// # let objectlist = ObjectList { types, metadata, items };
///
/// let first = objectlist.iter().next();
/// println!("First element: {:?}", first); // prints "First element: Some(1)"
Expand All @@ -68,11 +73,13 @@ impl<T: Clone> ObjectList<T> {
/// # Example
///
/// ```
/// use kube::api::{ObjectList, ListMeta};
/// use kube::api::{ListMeta, ObjectList, TypeMeta};
/// use k8s_openapi::api::core::v1::Pod;
///
/// let types: TypeMeta = TypeMeta::list::<Pod>();
/// let metadata: ListMeta = Default::default();
/// let items = vec![1, 2, 3];
/// let mut objectlist = ObjectList { metadata, items };
/// # let mut objectlist = ObjectList { types, metadata, items };
///
/// let mut first = objectlist.iter_mut().next();
///
Expand Down Expand Up @@ -300,7 +307,9 @@ pub struct NotUsed {}

#[cfg(test)]
mod test {
use super::{ApiResource, HasSpec, HasStatus, NotUsed, Object, Resource};
use k8s_openapi::apimachinery::pkg::apis::meta::v1::{ListMeta, ObjectMeta};

use super::{ApiResource, HasSpec, HasStatus, NotUsed, Object, ObjectList, Resource, TypeMeta};
use crate::resource::ResourceExt;

#[test]
Expand Down Expand Up @@ -347,4 +356,42 @@ mod test {
assert_eq!(PodSimple::kind(&ar), "Pod");
assert_eq!(PodSimple::group(&ar), "");
}

#[test]
fn k8s_object_list() {
use k8s_openapi::api::core::v1::Pod;
// by grabbing the ApiResource info from the Resource trait
let ar = ApiResource::erase::<Pod>(&());
assert_eq!(ar.group, "");
assert_eq!(ar.kind, "Pod");
let podlist: ObjectList<Pod> = ObjectList {
types: TypeMeta {
api_version: ar.api_version,
kind: ar.kind + "List",
},
metadata: ListMeta { ..Default::default() },
items: vec![Pod {
metadata: ObjectMeta {
name: Some("test".into()),
namespace: Some("dev".into()),
..ObjectMeta::default()
},
spec: None,
status: None,
}],
};

assert_eq!(&podlist.types.kind, "PodList");
assert_eq!(&podlist.types.api_version, "v1");

let mypod = &podlist.items[0];
let meta = mypod.meta();
assert_eq!(&mypod.metadata, meta);
assert_eq!(meta.namespace.as_ref().unwrap(), "dev");
assert_eq!(meta.name.as_ref().unwrap(), "test");
assert_eq!(mypod.namespace().unwrap(), "dev");
assert_eq!(mypod.name_unchecked(), "test");
assert!(mypod.status.is_none());
assert!(mypod.spec.is_none());
}
}
2 changes: 1 addition & 1 deletion kube-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"kazk <[email protected]>",
]
edition = "2021"
rust-version = "1.65.0"
rust-version = "1.70.0"
license = "Apache-2.0"
repository = "https://github.com/kube-rs/kube"
readme = "../README.md"
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/kube-rs/kube"
readme = "../README.md"
keywords = ["kubernetes", "runtime", "reflector", "watcher", "controller"]
categories = ["web-programming::http-client", "caching", "network-programming"]
rust-version = "1.65.0"
rust-version = "1.70.0"
edition = "2021"

[features]
Expand Down
2 changes: 1 addition & 1 deletion kube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/kube-rs/kube"
readme = "../README.md"
keywords = ["kubernetes", "client", "runtime", "cncf"]
categories = ["network-programming", "caching", "api-bindings", "configuration", "encoding"]
rust-version = "1.65.0"
rust-version = "1.70.0"
edition = "2021"

[features]
Expand Down
4 changes: 4 additions & 0 deletions kube/src/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ impl ApiServerVerifier {
assert!(!req_uri.contains("continue=")); // first list has no continue

let respdata = json!({
"kind": "HackList",
"apiVersion": "kube.rs/v1",
"metadata": {
"continue": "first",
},
Expand All @@ -111,6 +113,8 @@ impl ApiServerVerifier {
let req_uri = request.uri().to_string();
assert!(req_uri.contains("&continue=first"));
let respdata = json!({
"kind": "HackList",
"apiVersion": "kube.rs/v1",
"metadata": {
"continue": "",
"resourceVersion": "2"
Expand Down

0 comments on commit 8a0bd55

Please sign in to comment.