Skip to main content

armada_client/
lib.rs

1//! Rust client for the [Armada](https://armadaproject.io) batch-job scheduler.
2//!
3//! This crate provides an async gRPC client for submitting and monitoring batch
4//! jobs on an Armada cluster. It is built on top of [tonic] and exposes a
5//! small, ergonomic API that can be shared across async tasks without locking.
6//!
7//! # Quick start
8//!
9//! ```no_run
10//! use armada_client::k8s::io::api::core::v1::{Container, PodSpec};
11//! use armada_client::{
12//!     ArmadaClient, JobRequestItemBuilder, JobSubmitRequest, StaticTokenProvider,
13//! };
14//!
15//! #[tokio::main]
16//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
17//!     // 1. Connect (plaintext). Use `connect_tls` for production clusters.
18//!     let client = ArmadaClient::connect(
19//!         "http://localhost:50051",
20//!         StaticTokenProvider::new("my-token"),
21//!     )
22//!     .await?;
23//!
24//!     // 2. Build a job item — pod spec required before `.build()` compiles.
25//!     let pod_spec = PodSpec {
26//!         containers: vec![Container {
27//!             name: Some("main".into()),
28//!             image: Some("busybox:latest".into()),
29//!             command: vec!["echo".into()],
30//!             args: vec!["hello".into()],
31//!             ..Default::default()
32//!         }],
33//!         ..Default::default()
34//!     };
35//!
36//!     let item = JobRequestItemBuilder::new()
37//!         .namespace("default")
38//!         .priority(1.0)
39//!         .pod_spec(pod_spec)
40//!         .build();
41//!
42//!     // 3. Submit.
43//!     let response = client
44//!         .submit(JobSubmitRequest {
45//!             queue: "my-queue".into(),
46//!             job_set_id: "my-job-set".into(),
47//!             job_request_items: vec![item],
48//!         })
49//!         .await?;
50//!
51//!     for r in &response.job_response_items {
52//!         println!("job_id={}", r.job_id);
53//!     }
54//!     Ok(())
55//! }
56//! ```
57//!
58//! # Features
59//!
60//! | Feature | How to use |
61//! |---|---|
62//! | Plaintext connection | [`ArmadaClient::connect`] |
63//! | TLS connection (system roots) | [`ArmadaClient::connect_tls`] |
64//! | Per-call timeout | [`ArmadaClient::with_timeout`] |
65//! | Job submission | [`ArmadaClient::submit`] |
66//! | Event streaming | [`ArmadaClient::watch`] |
67//! | Static bearer token | [`StaticTokenProvider`] |
68//! | Custom auth (OIDC, OAuth2…) | Implement [`TokenProvider`] |
69//! | Compile-time safe job builder | [`JobRequestItemBuilder`] |
70//!
71//! # Kubernetes proto types
72//!
73//! Armada job specs embed Kubernetes `PodSpec` and related types. These are
74//! generated from the upstream k8s protobufs and re-exported under the
75//! [`k8s`] module, mirroring the proto package hierarchy:
76//!
77//! ```ignore
78//! use armada_client::k8s::io::api::core::v1::{Container, PodSpec, ResourceRequirements};
79//! use armada_client::k8s::io::apimachinery::pkg::api::resource::Quantity;
80//! ```
81//!
82//! # Cloning and concurrent use
83//!
84//! [`ArmadaClient`] is `Clone`. All clones share the same underlying
85//! connection pool — cloning is cheap and the correct way to use the client
86//! across multiple tasks:
87//!
88//! ```no_run
89//! # use armada_client::{ArmadaClient, StaticTokenProvider};
90//! # async fn example() -> Result<(), armada_client::Error> {
91//! let client = ArmadaClient::connect("http://localhost:50051", StaticTokenProvider::new("tok"))
92//!     .await?;
93//!
94//! let c1 = client.clone();
95//! let c2 = client.clone();
96//! tokio::join!(
97//!     async move { /* use c1 */ },
98//!     async move { /* use c2 */ },
99//! );
100//! # Ok(())
101//! # }
102//! ```
103
104pub mod api {
105    #![allow(
106        clippy::tabs_in_doc_comments,
107        clippy::doc_lazy_continuation,
108        clippy::doc_overindented_list_items,
109        clippy::large_enum_variant
110    )]
111    tonic::include_proto!("api");
112}
113
114// google.api types (HttpRule etc.) generated as a side-effect of compiling the
115// Armada API protos. Not part of the public API — used internally by api.rs.
116pub(crate) mod google {
117    pub mod api {
118        #![allow(
119            dead_code,
120            clippy::tabs_in_doc_comments,
121            clippy::doc_lazy_continuation,
122            clippy::doc_overindented_list_items,
123            clippy::large_enum_variant
124        )]
125        tonic::include_proto!("google.api");
126    }
127}
128
129// k8s types referenced by the api package — must mirror the proto package hierarchy
130// so that generated api.rs cross-package refs (e.g., super::k8s::io::api::core::v1::PodSpec) resolve.
131pub mod k8s {
132    #![allow(
133        clippy::tabs_in_doc_comments,
134        clippy::doc_lazy_continuation,
135        clippy::doc_overindented_list_items,
136        clippy::large_enum_variant
137    )]
138    pub mod io {
139        pub mod api {
140            pub mod core {
141                pub mod v1 {
142                    tonic::include_proto!("k8s.io.api.core.v1");
143                }
144            }
145            pub mod networking {
146                pub mod v1 {
147                    tonic::include_proto!("k8s.io.api.networking.v1");
148                }
149            }
150        }
151        pub mod apimachinery {
152            pub mod pkg {
153                pub mod api {
154                    pub mod resource {
155                        tonic::include_proto!("k8s.io.apimachinery.pkg.api.resource");
156                    }
157                }
158                pub mod apis {
159                    pub mod meta {
160                        pub mod v1 {
161                            tonic::include_proto!("k8s.io.apimachinery.pkg.apis.meta.v1");
162                        }
163                    }
164                }
165                pub mod runtime {
166                    tonic::include_proto!("k8s.io.apimachinery.pkg.runtime");
167                }
168                pub mod util {
169                    pub mod intstr {
170                        tonic::include_proto!("k8s.io.apimachinery.pkg.util.intstr");
171                    }
172                }
173            }
174        }
175    }
176}
177
178pub mod auth;
179pub mod builder;
180pub mod client;
181pub mod error;
182
183// Convenience re-exports for the public API surface
184pub use api::{
185    EventMessage, EventStreamMessage, JobSubmitRequest, JobSubmitRequestItem, JobSubmitResponse,
186};
187pub use auth::{BasicAuthProvider, StaticTokenProvider, TokenProvider};
188pub use builder::JobRequestItemBuilder;
189pub use client::ArmadaClient;
190pub use error::Error;
191pub use futures::stream::BoxStream;