Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c60fe9

Browse files
committed
Support providing cluster info to the exec provider
1 parent4da83df commit8c60fe9

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

‎kubernetes/base/config/exec_provider.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ExecProvider(object):
3131
* caching
3232
"""
3333

34-
def__init__(self,exec_config,cwd):
34+
def__init__(self,exec_config,cwd,cluster=None):
3535
"""
3636
exec_config must be of type ConfigNode because we depend on
3737
safe_get(self, key) to correctly handle optional exec provider
@@ -53,7 +53,10 @@ def __init__(self, exec_config, cwd):
5353
value=item['value']
5454
additional_vars[name]=value
5555
self.env.update(additional_vars)
56-
56+
ifexec_config.safe_get('provideClusterInfo'):
57+
self.cluster=cluster
58+
else:
59+
self.cluster=None
5760
self.cwd=cwdorNone
5861

5962
defrun(self,previous_response=None):
@@ -67,6 +70,9 @@ def run(self, previous_response=None):
6770
}
6871
ifprevious_response:
6972
kubernetes_exec_info['spec']['response']=previous_response
73+
ifself.cluster:
74+
kubernetes_exec_info['spec']['cluster']=self.cluster
75+
7076
self.env['KUBERNETES_EXEC_INFO']=json.dumps(kubernetes_exec_info)
7177
process=subprocess.Popen(
7278
self.args,

‎kubernetes/base/config/exec_provider_test.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
importjson
1516
importos
1617
importunittest
1718

@@ -31,6 +32,13 @@ def setUp(self):
3132
'apiVersion':'client.authentication.k8s.io/v1beta1',
3233
'env':None
3334
})
35+
self.input_with_cluster=ConfigNode('test', {
36+
'command':'aws-iam-authenticator',
37+
'args': ['token','-i','dummy'],
38+
'apiVersion':'client.authentication.k8s.io/v1beta1',
39+
'provideClusterInfo':True,
40+
'env':None
41+
})
3442
self.output_ok="""
3543
{
3644
"apiVersion": "client.authentication.k8s.io/v1beta1",
@@ -162,6 +170,19 @@ def test_ok_no_console_attached(self, mock):
162170
self.assertTrue(isinstance(result,dict))
163171
self.assertTrue('token'inresult)
164172

173+
@mock.patch('subprocess.Popen')
174+
deftest_with_cluster_info(self,mock):
175+
instance=mock.return_value
176+
instance.wait.return_value=0
177+
instance.communicate.return_value= (self.output_ok,'')
178+
ep=ExecProvider(self.input_with_cluster,None, {'server':'name.company.com'})
179+
result=ep.run()
180+
self.assertTrue(isinstance(result,dict))
181+
self.assertTrue('token'inresult)
182+
183+
obj=json.loads(mock.call_args.kwargs['env']['KUBERNETES_EXEC_INFO'])
184+
self.assertEqual(obj['spec']['cluster']['server'],'name.company.com')
185+
165186

166187
if__name__=='__main__':
167188
unittest.main()

‎kubernetes/base/config/kube_config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def _load_from_exec_plugin(self):
487487
return
488488
try:
489489
base_path=self._get_base_path(self._cluster.path)
490-
status=ExecProvider(self._user['exec'],base_path).run()
490+
status=ExecProvider(self._user['exec'],base_path,self._cluster).run()
491491
if'token'instatus:
492492
self.token="Bearer %s"%status['token']
493493
elif'clientCertificateData'instatus:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp