Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Oct 12, 2023
1 parent 1d36d87 commit 50fda71
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/crd_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn main() -> Result<()> {
let client = Client::try_default().await?;

// Manage CRDs first
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());

// Delete any old versions of it first:
let dp = DeleteParams::default();
Expand Down
2 changes: 1 addition & 1 deletion examples/crd_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() -> anyhow::Result<()> {

// 0. Ensure the CRD is installed (you probably just want to do this on CI)
// (crd file can be created by piping `Foo::crd`'s yaml ser to kubectl apply)
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
info!("Creating crd: {}", serde_yaml::to_string(&Foo::crd())?);
crds.patch("foos.clux.dev", &ssapply, &Patch::Apply(Foo::crd()))
.await?;
Expand Down
4 changes: 2 additions & 2 deletions examples/crd_derive_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async fn main() -> anyhow::Result<()> {
}

async fn apply_crd(client: Client, crd: CustomResourceDefinition) -> anyhow::Result<()> {
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
info!("Creating crd: {}", serde_yaml::to_string(&crd)?);
let ssapply = PatchParams::apply("crd_derive_multi").force();
crds.patch("manyderives.kube.rs", &ssapply, &Patch::Apply(&crd))
Expand All @@ -116,7 +116,7 @@ async fn apply_crd(client: Client, crd: CustomResourceDefinition) -> anyhow::Res
}

async fn cleanup(client: Client) -> anyhow::Result<()> {
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
let obj = crds.delete("manyderives.kube.rs", &Default::default()).await?;
if let either::Either::Left(o) = obj {
let uid = o.uid().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions examples/crd_derive_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ async fn main() -> Result<()> {

// Create CRD and wait for it to be ready.
async fn create_crd(client: Client) -> Result<CustomResourceDefinition> {
let api = Api::<CustomResourceDefinition>::all(client);
let api = Api::<CustomResourceDefinition>::cluster(client);
api.create(&PostParams::default(), &Foo::crd()).await?;

// Wait until it's accepted and established by the api-server
Expand All @@ -235,7 +235,7 @@ async fn create_crd(client: Client) -> Result<CustomResourceDefinition> {

// Delete the CRD if it exists and wait until it's deleted.
async fn delete_crd(client: Client) -> Result<()> {
let api = Api::<CustomResourceDefinition>::all(client);
let api = Api::<CustomResourceDefinition>::cluster(client);
if api.get("foos.clux.dev").await.is_ok() {
api.delete("foos.clux.dev", &DeleteParams::default()).await?;

Expand Down
2 changes: 1 addition & 1 deletion examples/crd_reflector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn main() -> anyhow::Result<()> {

// 0. Ensure the CRD is installed (you probably just want to do this on CI)
// (crd file can be created by piping `Foo::crd`'s yaml ser to kubectl apply)
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
info!("Creating crd: {}", serde_yaml::to_string(&Foo::crd())?);
let ssapply = PatchParams::apply("crd_reflector_example").force();
crds.patch("foos.clux.dev", &ssapply, &Patch::Apply(Foo::crd()))
Expand Down
8 changes: 2 additions & 6 deletions examples/dynamic_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use kube::{
api::{Api, DynamicObject, ResourceExt},
discovery::{verbs, Discovery, Scope},
discovery::{verbs, Discovery},
Client,
};
use tracing::*;
Expand All @@ -18,11 +18,7 @@ async fn main() -> anyhow::Result<()> {
if !caps.supports_operation(verbs::LIST) {
continue;
}
let api: Api<DynamicObject> = if caps.scope == Scope::Cluster {
Api::all_with(client.clone(), &ar)
} else {
Api::default_namespaced_with(client.clone(), &ar)
};
let api: Api<DynamicObject> = Api::dynamic(client.clone(), &ar, caps.scope);

info!("{}/{} : {}", group.name(), ar.version, ar.kind);

Expand Down
17 changes: 11 additions & 6 deletions examples/kubectl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,17 @@ fn dynamic_api(
ns: Option<&str>,
all: bool,
) -> Api<DynamicObject> {
if caps.scope == Scope::Cluster || all {
Api::all_with(client, &ar)
} else if let Some(namespace) = ns {
Api::namespaced_with(client, namespace, &ar)
} else {
Api::default_namespaced_with(client, &ar)
match caps.scope {
Scope::Cluster => Api::cluster_with(client, &ar),
Scope::Namespaced => {
if all {
Api::all_with(client, &ar)
} else if let Some(namespace) = ns {
Api::namespaced_with(client, namespace, &ar)
} else {
Api::default_namespaced_with(client, &ar)
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/node_reflector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let client = Client::try_default().await?;

let nodes: Api<Node> = Api::all(client.clone());
let nodes: Api<Node> = Api::cluster(client.clone());
let wc = watcher::Config::default()
.labels("kubernetes.io/arch=amd64") // filter instances by label
.timeout(10); // short watch timeout in this example
Expand Down
2 changes: 1 addition & 1 deletion examples/node_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
let client = Client::try_default().await?;
let events: Api<Event> = Api::all(client.clone());
let nodes: Api<Node> = Api::all(client.clone());
let nodes: Api<Node> = Api::cluster(client.clone());

let use_watchlist = std::env::var("WATCHLIST").map(|s| s == "1").unwrap_or(false);
let wc = if use_watchlist {
Expand Down
2 changes: 1 addition & 1 deletion kube-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod custom_resource;
/// # struct FooSpec {}
/// # let client: Client = todo!();
/// let foos: Api<Foo> = Api::default_namespaced(client.clone());
/// let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
/// let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
/// crds.patch("foos.clux.dev", &PatchParams::apply("myapp"), &Patch::Apply(Foo::crd())).await;
/// # Ok(())
/// # }
Expand Down
6 changes: 3 additions & 3 deletions kube-runtime/src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,10 @@ where
/// ```
/// # use kube::runtime::{Controller, controller::Action, reflector::ObjectRef, watcher};
/// # use kube::{Api, ResourceExt};
/// # use k8s_openapi::api::core::v1::{ConfigMap, Namespace};
/// # use k8s_openapi::api::core::v1::{ConfigMap, Pod};
/// # use futures::StreamExt;
/// # use std::sync::Arc;
/// # type WatchedResource = Namespace;
/// # type WatchedResource = Pod;
/// # struct Context;
/// # async fn reconcile(_: Arc<ConfigMap>, _: Arc<Context>) -> Result<Action, kube::Error> {
/// # Ok(Action::await_change())
Expand Down Expand Up @@ -963,7 +963,7 @@ where
/// fn mapper(_: DaemonSet) -> Option<ObjectRef<CustomResource>> { todo!() }
/// # async fn doc(client: kube::Client) {
/// let api: Api<DaemonSet> = Api::all(client.clone());
/// let cr: Api<CustomResource> = Api::all(client.clone());
/// let cr: Api<CustomResource> = Api::default_namespaced(client.clone());
/// let daemons = watcher(api, watcher::Config::default())
/// .touched_objects()
/// .predicate_filter(predicates::generation);
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ mod test {
async fn event_recorder_attaches_events_without_namespace() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::try_default().await?;

let svcs: Api<ClusterRole> = Api::all(client.clone());
let svcs: Api<ClusterRole> = Api::cluster(client.clone());
let s = svcs.get("system:basic-user").await?; // always get this default ClusterRole
let recorder = Recorder::new(client.clone(), "kube".into(), s.object_ref(&()));
recorder
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/reflector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub use store::{store, Store};
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client: kube::Client = todo!();
///
/// let nodes: Api<Node> = Api::all(client);
/// let nodes: Api<Node> = Api::cluster(client);
/// let node_filter = Config::default().labels("kubernetes.io/arch=amd64");
/// let (reader, writer) = reflector::store();
///
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum Error {
/// # async fn wrapper() -> Result<(), Box<dyn std::error::Error>> {
/// # let client: kube::Client = todo!();
///
/// let crds: Api<CustomResourceDefinition> = Api::all(client);
/// let crds: Api<CustomResourceDefinition> = Api::cluster(client);
/// // .. create or apply a crd here ..
/// let establish = await_condition(crds, "foos.clux.dev", conditions::is_crd_established());
/// let _ = tokio::time::timeout(std::time::Duration::from_secs(10), establish).await?;
Expand Down
14 changes: 5 additions & 9 deletions kube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::try_default().await?;
//! let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
//! let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
//!
//! // Apply the CRD so users can create Foo instances in Kubernetes
//! crds.patch("foos.clux.dev",
Expand Down Expand Up @@ -241,7 +241,7 @@ mod test {
use serde_json::json;
let client = Client::try_default().await?;
let ssapply = PatchParams::apply("kube").force();
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
// Server-side apply CRD and wait for it to get ready
crds.patch("foos.clux.dev", &ssapply, &Patch::Apply(Foo::crd()))
.await?;
Expand Down Expand Up @@ -365,7 +365,7 @@ mod test {
async fn derived_resources_discoverable() -> Result<(), Box<dyn std::error::Error>> {
use crate::{
core::{DynamicObject, GroupVersion, GroupVersionKind},
discovery::{self, verbs, ApiGroup, Discovery, Scope},
discovery::{self, verbs, ApiGroup, Discovery},
runtime::wait::{await_condition, conditions, Condition},
};

Expand All @@ -377,7 +377,7 @@ mod test {
let client = Client::try_default().await?;

// install crd is installed
let crds: Api<CustomResourceDefinition> = Api::all(client.clone());
let crds: Api<CustomResourceDefinition> = Api::cluster(client.clone());
let ssapply = PatchParams::apply("kube").force();
crds.patch("testcrs.kube.rs", &ssapply, &Patch::Apply(TestCr::crd()))
.await?;
Expand Down Expand Up @@ -421,11 +421,7 @@ mod test {
if !caps.supports_operation(verbs::LIST) {
continue;
}
let api: Api<DynamicObject> = if caps.scope == Scope::Namespaced {
Api::default_namespaced_with(client.clone(), &ar)
} else {
Api::all_with(client.clone(), &ar)
};
let api: Api<DynamicObject> = Api::dynamic(client.clone(), &ar, caps.scope);
api.list(&Default::default()).await?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion kube/src/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn watchers_respect_pagination_limits() {
// NB: scenario only responds responds to TWO paginated list calls with two objects
let mocksrv = fakeserver.run(Scenario::PaginatedList);

let api: Api<Hack> = Api::all(client);
let api: Api<Hack> = Api::cluster(client);
let cfg = Config::default().page_size(1);
let mut stream = watcher(api, cfg).applied_objects().boxed();
let first: Hack = stream.try_next().await.unwrap().unwrap();
Expand Down

0 comments on commit 50fda71

Please sign in to comment.