8
8
import java .lang .reflect .Method ;
9
9
import java .util .ArrayList ;
10
10
import java .util .HashMap ;
11
+ import java .util .Iterator ;
11
12
import java .util .List ;
12
13
import java .util .ListIterator ;
13
14
import java .util .Map ;
15
+ import java .util .Set ;
14
16
15
17
import io .kubernetes .client .models .V1EnvVar ;
16
18
import io .kubernetes .client .models .V1Pod ;
@@ -100,6 +102,11 @@ protected void doDeepSubstitution(final Map<String, String> substitutionVariable
100
102
for (Pair <Method , Method > item : stringBeans ) {
101
103
item .getRight ().invoke (obj , translate (substitutionVariables , (String ) item .getLeft ().invoke (obj )));
102
104
}
105
+
106
+ List <Pair <Method , Method >> mapBeans = mapBeans (cls );
107
+ for (Pair <Method , Method > item : mapBeans ) {
108
+ item .getRight ().invoke (obj , translate (substitutionVariables , (Map ) item .getLeft ().invoke (obj )));
109
+ }
103
110
}
104
111
} catch (IllegalAccessException | InvocationTargetException e ) {
105
112
LOGGER .severe (MessageKeys .EXCEPTION , e );
@@ -136,15 +143,23 @@ && isModelOrListClass(m.getReturnType())
136
143
}
137
144
138
145
private List <Pair <Method , Method >> stringBeans (Class cls ) {
146
+ return typeBeans (cls , String .class );
147
+ }
148
+
149
+ private List <Pair <Method , Method >> mapBeans (Class cls ) {
150
+ return typeBeans (cls , Map .class );
151
+ }
152
+
153
+ private List <Pair <Method , Method >> typeBeans (Class cls , Class type ) {
139
154
List <Pair <Method , Method >> results = new ArrayList <>();
140
155
Method [] methods = cls .getMethods ();
141
156
if (methods != null ) {
142
157
for (Method m : methods ) {
143
158
if (m .getName ().startsWith ("get" )
144
- && m .getReturnType ().equals (String . class )
159
+ && m .getReturnType ().equals (type )
145
160
&& m .getParameterCount () == 0 ) {
146
161
try {
147
- Method set = cls .getMethod ("set" + m .getName ().substring (3 ), String . class );
162
+ Method set = cls .getMethod ("set" + m .getName ().substring (3 ), type );
148
163
if (set != null ) {
149
164
results .add (new Pair <>(m , set ));
150
165
}
@@ -167,6 +182,26 @@ private String translate(final Map<String, String> substitutionVariables, String
167
182
return result ;
168
183
}
169
184
185
+ private Map <String , Object > translate (final Map <String , String > substitutionVariables , Map <String , Object > rawValue ) {
186
+ if (rawValue == null )
187
+ return null ;
188
+
189
+ Map <String , Object > trans = new HashMap <>();
190
+ for (Map .Entry <String , ?> entry : rawValue .entrySet ()) {
191
+ Object value = entry .getValue ();
192
+ if (value instanceof String ) {
193
+ value = translate (substitutionVariables , (String ) value );
194
+ } else if (value instanceof Map ) {
195
+ value = translate (substitutionVariables , (Map ) value );
196
+ } else {
197
+ doDeepSubstitution (substitutionVariables , value );
198
+ }
199
+ trans .put (translate (substitutionVariables , entry .getKey ()), value );
200
+ }
201
+
202
+ return trans ;
203
+ }
204
+
170
205
protected void addEnvVar (List <V1EnvVar > vars , String name , String value ) {
171
206
vars .add (new V1EnvVar ().name (name ).value (value ));
172
207
}
0 commit comments