11//! `provider_config` parsing and the `info` config schema
22//! (spec §`provider_config` v1 fields, `docs/remote-agents.md:1384-1389`).
33//!
4- //! Nine fields, all optional except `image` (required at parse time; the
5- //! schema offers the published sprig image as a prefill default — §Image).
4+ //! Nine scalar fields and optional structured Pod controls. `image` is required
5+ //! at parse time (the schema offers the published sprig image as a prefill
6+ //! default — §Image).
67//! No credential field exists, by I2: cluster auth comes from ambient
78//! kubeconfig resolution and nothing else (`:196-198`).
89
910use crate :: image:: { self , ImageRef } ;
11+ use k8s_openapi:: api:: core:: v1:: Toleration ;
12+ use serde:: { Deserialize , Serialize } ;
13+ use std:: collections:: BTreeMap ;
1014
1115/// Resource requests and limits (§Pod shape: 1cpu/2Gi → 2cpu/4Gi, all four
1216/// configurable — `cargo build` in an agent workspace makes 500m/1Gi
@@ -61,7 +65,42 @@ pub const TERMINATION_GRACE_SECONDS: i64 = 60;
6165/// the combination rather than shipping against an undefended convention.
6266pub const RESTART_POLICY : & str = "Never" ;
6367
64- #[ derive( Debug , Clone , PartialEq , Eq ) ]
68+ /// Optional placement and resource bounds for a bare Pod. Defaults preserve
69+ /// the original Pod shape; configured fields participate in create intent.
70+ #[ derive( Debug , Clone , Default , PartialEq , Serialize , Deserialize ) ]
71+ #[ serde( deny_unknown_fields) ]
72+ pub struct PodOptions {
73+ #[ serde( default , skip_serializing_if = "BTreeMap::is_empty" ) ]
74+ /// Exact node labels required for scheduling.
75+ pub node_selector : BTreeMap < String , String > ,
76+ #[ serde( default , skip_serializing_if = "Vec::is_empty" ) ]
77+ /// Explicit taints this workload may tolerate.
78+ pub tolerations : Vec < Toleration > ,
79+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
80+ /// Optional emptyDir size limit, in Kubernetes quantity syntax.
81+ pub workspace_size_limit : Option < String > ,
82+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
83+ /// Scheduler reservation for writable storage and container logs.
84+ pub ephemeral_storage_request : Option < String > ,
85+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
86+ /// Eviction bound for aggregate container ephemeral storage.
87+ pub ephemeral_storage_limit : Option < String > ,
88+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
89+ /// Positive absolute Pod lifetime, including startup.
90+ pub active_deadline_seconds : Option < i64 > ,
91+ #[ serde( default , skip_serializing_if = "std::ops::Not::not" ) ]
92+ /// Expose the server-assigned Pod UID to a bounded owner setup gate.
93+ pub setup_pending : bool ,
94+ }
95+
96+ impl PodOptions {
97+ /// Preserve original intent serialization when no options are set.
98+ pub fn is_default ( & self ) -> bool {
99+ self == & Self :: default ( )
100+ }
101+ }
102+
103+ #[ derive( Debug , Clone , PartialEq ) ]
65104pub struct ProviderConfig {
66105 /// kubeconfig context; `None` uses the current context.
67106 pub context : Option < String > ,
@@ -71,6 +110,8 @@ pub struct ProviderConfig {
71110 /// `None` when `inactivity_seconds` was 0 — refused in v1, see [`parse`].
72111 pub inactivity_seconds : Option < u64 > ,
73112 pub service_account : Option < String > ,
113+ /// Optional Pod placement, storage, and lifetime controls.
114+ pub pod_options : PodOptions ,
74115}
75116
76117/// Read an optional non-empty string field. Rejects non-string scalars rather
@@ -165,13 +206,35 @@ pub fn parse(cfg: &serde_json::Value) -> Result<ProviderConfig, String> {
165206 Some ( n) => Some ( n) ,
166207 } ;
167208
209+ let pod_options: PodOptions = match cfg. get ( "pod_options" ) {
210+ None => PodOptions :: default ( ) ,
211+ Some ( value) => serde_json:: from_value ( value. clone ( ) )
212+ . map_err ( |e| format ! ( "provider_config.pod_options: {e}" ) ) ?,
213+ } ;
214+ if pod_options. active_deadline_seconds . is_some_and ( |n| n <= 0 ) {
215+ return Err ( "provider_config.pod_options.active_deadline_seconds must be positive" . into ( ) ) ;
216+ }
217+ for value in [
218+ & pod_options. workspace_size_limit ,
219+ & pod_options. ephemeral_storage_request ,
220+ & pod_options. ephemeral_storage_limit ,
221+ ]
222+ . into_iter ( )
223+ . flatten ( )
224+ {
225+ if value. trim ( ) . is_empty ( ) {
226+ return Err ( "provider_config.pod_options storage quantities must not be empty" . into ( ) ) ;
227+ }
228+ }
229+
168230 Ok ( ProviderConfig {
169231 context : optional_string ( cfg, "context" ) ?,
170232 namespace,
171233 image,
172234 resources,
173235 inactivity_seconds,
174236 service_account : optional_string ( cfg, "service_account" ) ?,
237+ pod_options,
175238 } )
176239}
177240
@@ -232,10 +295,35 @@ pub fn config_schema() -> serde_json::Value {
232295 "description" : "The agent exits after this long with no work, and can be started again at any time." ,
233296 "default" : DEFAULT_INACTIVITY_SECONDS
234297 } ,
298+ "pod_options" : {
299+ "type" : "object" ,
300+ "title" : "Pod placement and bounds" ,
301+ "description" : "Optional structured provider configuration; omit to preserve the original Pod shape." ,
302+ "additionalProperties" : false ,
303+ "properties" : {
304+ "node_selector" : { "type" : "object" , "additionalProperties" : { "type" : "string" } } ,
305+ "tolerations" : { "type" : "array" , "items" : { "type" : "object" } } ,
306+ "workspace_size_limit" : { "type" : "string" , "minLength" : 1 } ,
307+ "ephemeral_storage_request" : { "type" : "string" , "minLength" : 1 } ,
308+ "ephemeral_storage_limit" : { "type" : "string" , "minLength" : 1 } ,
309+ "active_deadline_seconds" : { "type" : "integer" , "minimum" : 1 } ,
310+ "setup_pending" : { "type" : "boolean" , "default" : false }
311+ }
312+ } ,
235313 "service_account" : {
236314 "type" : "string" ,
237315 "title" : "Service account" ,
238316 "description" : "Scheduling/RBAC identity only. No API token is mounted."
317+ } ,
318+ "identity_policy" : {
319+ "type" : "object" ,
320+ "description" : "Optional approved agent and owner public keys, cryptographically checked before cluster access. Also enables local --check-identity preflight." ,
321+ "additionalProperties" : false ,
322+ "required" : [ "agent_pubkey" , "owner_pubkey" ] ,
323+ "properties" : {
324+ "agent_pubkey" : { "type" : "string" , "pattern" : "^[0-9a-f]{64}$" } ,
325+ "owner_pubkey" : { "type" : "string" , "pattern" : "^[0-9a-f]{64}$" }
326+ }
239327 }
240328 } ,
241329 "required" : [ "namespace" , "image" ]
@@ -254,6 +342,22 @@ mod tests {
254342 serde_json:: json!( { "namespace" : "buzz-agents-abc123" , "image" : digest_ref( ) } )
255343 }
256344
345+ #[ test]
346+ fn refuses_invalid_pod_options ( ) {
347+ for bad in [
348+ serde_json:: json!( { "active_deadline_seconds" : 0 } ) ,
349+ serde_json:: json!( { "active_deadline_seconds" : -1 } ) ,
350+ serde_json:: json!( { "workspace_size_limit" : " " } ) ,
351+ serde_json:: json!( { "unknown" : true } ) ,
352+ serde_json:: json!( { "node_selector" : "amd64" } ) ,
353+ ] {
354+ let mut cfg = minimal ( ) ;
355+ cfg[ "pod_options" ] = bad;
356+ assert ! ( parse( & cfg) . unwrap_err( ) . contains( "pod_options" ) ) ;
357+ }
358+ assert ! ( parse( & minimal( ) ) . unwrap( ) . pod_options. is_default( ) ) ;
359+ }
360+
257361 #[ test]
258362 fn applies_spec_defaults ( ) {
259363 let c = parse ( & minimal ( ) ) . unwrap ( ) ;
@@ -423,10 +527,10 @@ mod tests {
423527 ) ;
424528 }
425529
426- /// Nine fields exactly (§`provider_config` v1 fields). The cap is 20; the
530+ /// Eleven fields (§`provider_config` v1 fields). The cap is 20; the
427531 /// count is pinned so a field added without a spec change is caught here.
428532 #[ test]
429- fn schema_declares_exactly_the_nine_v1_fields ( ) {
533+ fn schema_declares_scalar_fields_and_optional_pod_controls ( ) {
430534 let schema = config_schema ( ) ;
431535 let props = schema[ "properties" ] . as_object ( ) . unwrap ( ) ;
432536 let mut keys: Vec < & str > = props. keys ( ) . map ( String :: as_str) . collect ( ) ;
@@ -437,11 +541,13 @@ mod tests {
437541 "context" ,
438542 "cpu_limit" ,
439543 "cpu_request" ,
544+ "identity_policy" ,
440545 "image" ,
441546 "inactivity_seconds" ,
442547 "memory_limit" ,
443548 "memory_request" ,
444549 "namespace" ,
550+ "pod_options" ,
445551 "service_account"
446552 ]
447553 ) ;
0 commit comments