@@ -6,41 +6,46 @@ use stackable_operator::{
66 } ,
77} ;
88
9- use crate :: data:: container ;
9+ use crate :: data:: containers ;
1010
1111/// Copy the environment from the "listener-operator-deployer" container in `source`
12- /// to the container "listener-operator" in `target`.
13- /// The `target` must be a DaemonSet object otherwise this is a no-op.
12+ /// to *all* containers in target.
13+ /// The target must be a DaemonSet or Deployment, otherwise this function is a no-op.
14+ /// This function allows OLM Subscription objects to configure the environment
15+ /// of operator containers.
1416pub ( super ) fn maybe_copy_env (
1517 source : & Deployment ,
1618 target : & mut DynamicObject ,
1719 target_gvk : & GroupVersionKind ,
1820) -> anyhow:: Result < ( ) > {
19- if target_gvk. kind == "DaemonSet" {
21+ let target_kind_set = [ "DaemonSet" , "Deployment" ] ;
22+ if target_kind_set. contains ( & target_gvk. kind . as_str ( ) ) {
2023 if let Some ( env) = deployer_env_var ( source) {
21- match container ( target, "listener-operator" ) ? {
22- serde_json:: Value :: Object ( c) => {
23- let json_env = env
24- . iter ( )
25- . map ( |e| serde_json:: json!( e) )
26- . collect :: < Vec < serde_json:: Value > > ( ) ;
27-
28- match c. get_mut ( "env" ) {
29- Some ( env) => match env {
30- v @ serde_json:: Value :: Null => {
31- * v = serde_json:: json!( json_env) ;
24+ for container in containers ( target) ? {
25+ match container {
26+ serde_json:: Value :: Object ( c) => {
27+ let json_env = env
28+ . iter ( )
29+ . map ( |e| serde_json:: json!( e) )
30+ . collect :: < Vec < serde_json:: Value > > ( ) ;
31+
32+ match c. get_mut ( "env" ) {
33+ Some ( env) => match env {
34+ v @ serde_json:: Value :: Null => {
35+ * v = serde_json:: json!( json_env) ;
36+ }
37+ serde_json:: Value :: Array ( container_env) => {
38+ container_env. extend_from_slice ( & json_env)
39+ }
40+ _ => anyhow:: bail!( "env is not null or an array" ) ,
41+ } ,
42+ None => {
43+ c. insert ( "env" . to_string ( ) , serde_json:: json!( json_env) ) ;
3244 }
33- serde_json:: Value :: Array ( container_env) => {
34- container_env. extend_from_slice ( & json_env)
35- }
36- _ => anyhow:: bail!( "env is not null or an array" ) ,
37- } ,
38- None => {
39- c. insert ( "env" . to_string ( ) , serde_json:: json!( json_env) ) ;
4045 }
4146 }
47+ _ => anyhow:: bail!( "no containers found in object {}" , target. name_any( ) ) ,
4248 }
43- _ => anyhow:: bail!( "no containers found in object {}" , target. name_any( ) ) ,
4449 }
4550 }
4651 }
@@ -151,7 +156,9 @@ spec:
151156 } ,
152157 ] ) ;
153158 assert_eq ! (
154- container( & mut daemonset, "listener-operator" ) ?
159+ containers( & mut daemonset) ?
160+ . first( )
161+ . expect( "daemonset has no containers" )
155162 . get( "env" )
156163 . unwrap( ) ,
157164 & expected
0 commit comments