@@ -183,6 +183,38 @@ def test_with_cluster_info(self, mock):
183183 obj = json .loads (mock .call_args .kwargs ['env' ]['KUBERNETES_EXEC_INFO' ])
184184 self .assertEqual (obj ['spec' ]['cluster' ]['server' ], 'name.company.com' )
185185
186+ @mock .patch ("subprocess.Popen" )
187+ def test_with_cluster_info_from_exec_extension (self , mock ):
188+ instance = mock .return_value
189+ instance .wait .return_value = 0
190+ instance .communicate .return_value = (self .output_ok , "" )
191+ ep = ExecProvider (
192+ self .input_with_cluster ,
193+ None ,
194+ ConfigNode (
195+ "cluster" ,
196+ {
197+ "server" : "name.company.com" ,
198+ "extensions" : [
199+ {
200+ "name" : "client.authentication.k8s.io/exec" ,
201+ "extension" : {
202+ "namespace" : "myproject" ,
203+ "name" : "mycluster" ,
204+ },
205+ },
206+ ],
207+ },
208+ ),
209+ )
210+ result = ep .run ()
211+ self .assertTrue (isinstance (result , dict ))
212+ self .assertTrue ("token" in result )
213+
214+ obj = json .loads (mock .call_args .kwargs ["env" ]["KUBERNETES_EXEC_INFO" ])
215+ self .assertEqual (obj ["spec" ]["cluster" ]["server" ], "name.company.com" )
216+ self .assertEqual (obj ["spec" ]["cluster" ]["config" ]["namespace" ], "myproject" )
217+ self .assertEqual (obj ["spec" ]["cluster" ]["config" ]["name" ], "mycluster" )
186218
187219if __name__ == '__main__' :
188220 unittest .main ()
0 commit comments