@@ -16,7 +16,7 @@ use tower_http::trace::TraceLayer;
1616use tracing:: { debug, info, warn} ;
1717
1818use postgres_restore_operator:: {
19- context:: Context ,
19+ context:: { Context , DEFAULT_KOPIA_IMAGE } ,
2020 controllers,
2121 types:: { PostgresPhysicalReplica , PostgresPhysicalRestore } ,
2222} ;
@@ -50,13 +50,28 @@ fn extract_max_concurrent_restores(cm: &ConfigMap) -> usize {
5050 . unwrap_or ( DEFAULT_MAX_CONCURRENT_RESTORES )
5151}
5252
53- async fn read_max_concurrent_restores ( client : & Client , namespace : & str ) -> usize {
53+ fn extract_kopia_image ( cm : & ConfigMap ) -> String {
54+ cm. data
55+ . as_ref ( )
56+ . and_then ( |d| d. get ( "kopiaImage" ) )
57+ . filter ( |v| !v. is_empty ( ) )
58+ . cloned ( )
59+ . unwrap_or_else ( || DEFAULT_KOPIA_IMAGE . to_string ( ) )
60+ }
61+
62+ async fn read_config ( client : & Client , namespace : & str ) -> ( usize , String ) {
5463 let api: Api < ConfigMap > = Api :: namespaced ( client. clone ( ) , namespace) ;
5564 match api. get ( CONFIGMAP_NAME ) . await {
56- Ok ( cm) => extract_max_concurrent_restores ( & cm) ,
65+ Ok ( cm) => (
66+ extract_max_concurrent_restores ( & cm) ,
67+ extract_kopia_image ( & cm) ,
68+ ) ,
5769 Err ( e) => {
58- warn ! ( error = %e, "failed to read ConfigMap {CONFIGMAP_NAME}, defaulting to {DEFAULT_MAX_CONCURRENT_RESTORES}" ) ;
59- DEFAULT_MAX_CONCURRENT_RESTORES
70+ warn ! ( error = %e, "failed to read ConfigMap {CONFIGMAP_NAME}, using defaults" ) ;
71+ (
72+ DEFAULT_MAX_CONCURRENT_RESTORES ,
73+ DEFAULT_KOPIA_IMAGE . to_string ( ) ,
74+ )
6075 }
6176 }
6277}
@@ -77,17 +92,22 @@ async fn main() -> anyhow::Result<()> {
7792 let client = Client :: try_default ( ) . await ?;
7893
7994 let namespace = operator_namespace ( ) ;
80- let max_concurrent_restores = read_max_concurrent_restores ( & client, & namespace) . await ;
95+ let ( max_concurrent_restores, kopia_image ) = read_config ( & client, & namespace) . await ;
8196
8297 info ! (
8398 max_concurrent_restores,
99+ kopia_image,
84100 metrics_addr,
85101 operator_namespace = namespace,
86102 version = env!( "CARGO_PKG_VERSION" ) ,
87103 "starting postgres-restore-operator"
88104 ) ;
89105
90- let ctx = Arc :: new ( Context :: new ( client. clone ( ) , max_concurrent_restores) ) ;
106+ let ctx = Arc :: new ( Context :: new (
107+ client. clone ( ) ,
108+ max_concurrent_restores,
109+ kopia_image,
110+ ) ) ;
91111
92112 // Heartbeat: a background task updates this timestamp every 5s.
93113 // If the runtime is deadlocked, the timestamp goes stale and /livez fails.
@@ -106,6 +126,7 @@ async fn main() -> anyhow::Result<()> {
106126 let config_watcher_config =
107127 Config :: default ( ) . fields ( & format ! ( "metadata.name={CONFIGMAP_NAME}" ) ) ;
108128 let max_concurrent_ref = ctx. max_concurrent_restores . clone ( ) ;
129+ let kopia_image_ref = ctx. kopia_image . clone ( ) ;
109130 tokio:: spawn ( async move {
110131 let stream = watcher:: watcher ( config_api, config_watcher_config) ;
111132 futures:: pin_mut!( stream) ;
@@ -121,6 +142,17 @@ async fn main() -> anyhow::Result<()> {
121142 "max_concurrent_restores updated from ConfigMap"
122143 ) ;
123144 }
145+
146+ let new_image = extract_kopia_image ( & cm) ;
147+ let mut image = kopia_image_ref. write ( ) . unwrap ( ) ;
148+ if * image != new_image {
149+ info ! (
150+ old = %* image,
151+ new = new_image,
152+ "kopia_image updated from ConfigMap"
153+ ) ;
154+ * image = new_image;
155+ }
124156 }
125157 Ok ( watcher:: Event :: Delete ( _) ) => {
126158 let old_val =
@@ -132,6 +164,16 @@ async fn main() -> anyhow::Result<()> {
132164 "ConfigMap deleted, reverted max_concurrent_restores to default"
133165 ) ;
134166 }
167+
168+ let mut image = kopia_image_ref. write ( ) . unwrap ( ) ;
169+ if * image != DEFAULT_KOPIA_IMAGE {
170+ info ! (
171+ old = %* image,
172+ new = DEFAULT_KOPIA_IMAGE ,
173+ "ConfigMap deleted, reverted kopia_image to default"
174+ ) ;
175+ * image = DEFAULT_KOPIA_IMAGE . to_string ( ) ;
176+ }
135177 }
136178 Ok ( watcher:: Event :: Init | watcher:: Event :: InitDone ) => { }
137179 Err ( e) => {
0 commit comments