Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions juju/client/proxy/kubernetes/proxy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.

import os
import tempfile
import logging

from juju.client.proxy.proxy import Proxy, ProxyNotConnectedError
from kubernetes import client
from kubernetes.stream import portforward

log = logging.getLogger('juju.client.connection')


class KubernetesProxy(Proxy):
def __init__(
Expand All @@ -33,7 +36,7 @@ def __init__(
raise ValueError("Invalid port number: {}".format(remote_port))

if ca_cert:
self.temp_ca_file = tempfile.NamedTemporaryFile()
self.temp_ca_file = tempfile.NamedTemporaryFile(delete=False)
self.temp_ca_file.write(bytes(ca_cert, 'utf-8'))
self.temp_ca_file.flush()
config.ssl_ca_cert = self.temp_ca_file.name
Expand All @@ -60,6 +63,10 @@ def connect(self):

def __del__(self):
self.close()
try:
os.unlink(self.temp_ca_file.name)
except FileNotFoundError:
log.debug(f"file {self.temp_ca_file.name} not found")

def close(self):
try:
Expand Down