File tree Expand file tree Collapse file tree
juju/client/proxy/kubernetes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Copyright 2023 Canonical Ltd.
22# Licensed under the Apache V2, see LICENCE file for details.
3-
3+ import os
44import tempfile
5+ import logging
56
67from juju .client .proxy .proxy import Proxy , ProxyNotConnectedError
78from kubernetes import client
89from kubernetes .stream import portforward
910
11+ log = logging .getLogger ('juju.client.connection' )
12+
1013
1114class KubernetesProxy (Proxy ):
1215 def __init__ (
@@ -33,7 +36,7 @@ def __init__(
3336 raise ValueError ("Invalid port number: {}" .format (remote_port ))
3437
3538 if ca_cert :
36- self .temp_ca_file = tempfile .NamedTemporaryFile ()
39+ self .temp_ca_file = tempfile .NamedTemporaryFile (delete = False )
3740 self .temp_ca_file .write (bytes (ca_cert , 'utf-8' ))
3841 self .temp_ca_file .flush ()
3942 config .ssl_ca_cert = self .temp_ca_file .name
@@ -60,6 +63,10 @@ def connect(self):
6063
6164 def __del__ (self ):
6265 self .close ()
66+ try :
67+ os .unlink (self .temp_ca_file .name )
68+ except FileNotFoundError :
69+ log .debug (f"file { self .temp_ca_file .name } not found" )
6370
6471 def close (self ):
6572 try :
You can’t perform that action at this time.
0 commit comments