@@ -25,6 +25,14 @@ use postgres_restore_operator::{
2525 types:: { PostgresPhysicalReplica , PostgresPhysicalRestore } ,
2626} ;
2727
28+ // Use mimalloc instead of the default glibc allocator. Long-running Rust
29+ // services on glibc commonly hold significantly more RSS than their actual
30+ // live heap due to fragmentation and retained chunks; mimalloc keeps RSS
31+ // closer to working-set size, which matters for an operator that runs
32+ // indefinitely and was previously OOMKilled at a tight limit.
33+ #[ global_allocator]
34+ static GLOBAL : mimalloc:: MiMalloc = mimalloc:: MiMalloc ;
35+
2836const DEFAULT_MAX_CONCURRENT_RESTORES : usize = 2 ;
2937const DEFAULT_METRICS_ADDR : & str = "[::]:8080" ;
3038const DEFAULT_METRICS_PORT : u16 = 8080 ;
@@ -324,12 +332,23 @@ async fn main() -> anyhow::Result<()> {
324332 namespace. map ( |ns| ObjectRef :: new ( & replica_name) . within ( & ns) )
325333 } ,
326334 )
327- . watches ( Api :: < Job > :: all ( client. clone ( ) ) , Config :: default ( ) , |job| {
328- let labels = job. metadata . labels . as_ref ( ) ?;
329- let replica_name = labels. get ( "pgro.bes.au/replica" ) ?;
330- let namespace = job. metadata . namespace . as_ref ( ) ?;
331- Some ( ObjectRef :: new ( replica_name) . within ( namespace) )
332- } )
335+ // Scope the Job watch to pgro-owned Jobs. Without a label selector
336+ // kube-rs caches every Job in every namespace (CI runners, batch
337+ // jobs, cert-manager, etc.) in the in-memory store, which scales
338+ // with cluster activity rather than pgro's working set. Limiting
339+ // to Jobs that carry the pgro.bes.au/replica label cuts that to
340+ // only restore Jobs, snapshot-list Jobs, schema-migration Jobs,
341+ // and credential-reset Jobs — all of which the operator builds.
342+ . watches (
343+ Api :: < Job > :: all ( client. clone ( ) ) ,
344+ Config :: default ( ) . labels ( "pgro.bes.au/replica" ) ,
345+ |job| {
346+ let labels = job. metadata . labels . as_ref ( ) ?;
347+ let replica_name = labels. get ( "pgro.bes.au/replica" ) ?;
348+ let namespace = job. metadata . namespace . as_ref ( ) ?;
349+ Some ( ObjectRef :: new ( replica_name) . within ( namespace) )
350+ } ,
351+ )
333352 . run (
334353 controllers:: replica:: reconcile,
335354 controllers:: replica:: error_policy,
0 commit comments