You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classK8Pod():
def__init__(self, name, namespace):
self.k8=K8()
#note that K8 is just a wrapper over the kr8s.api #569 #the k8.get_pod gets a pod by partial name listing pods and getting the one with matching partial name so think of it as just a kr8s.objects.Pod objectself.pod=self.k8.get_pod(name, namespace)
defcopy_tar(self, tar_buffer: io.BytesIO, remote_path):
""" Copies a tar archive from a buffer to a specified path on a Kubernetes pod. Args: tar_buffer (io.BytesIO): The buffer containing the tar archive to be copied. remote_path (str): The destination path on the pod where the tar archive should be extracted. Raises: KubectlError: If there is an error during the execution of the tar command on the pod. """exec_command= ["tar", "xvf", "-", "-C", remote_path]
try:
self.pod.exec(exec_command, stdin=tar_buffer, check=True)
exceptExceptionase:
logger.error("Error copying tar to pod: %s", e)
raiseKubectlError(f"Error copying tar to pod {self.pod.name}: {e}") fromedefcopy_file(self, file_path: Path, remote_path: Path):
""" Copies a file to a remote path on a Kubernetes pod. Args: file_path (Path): The local path of the file to be copied. remote_path (Path): The destination path on the Kubernetes pod. Raises: Exception: If there is an error during the file copy process. """try:
tar_buffer=create_tar_archive(file_path, file_path.name)
self.copy_tar(tar_buffer, remote_path)
exceptExceptionase:
logger.error("Error copying file to pod: %s", e)
raiseKubectlError(f"Error copying file to pod {self.pod.name}: {e}") frome
Running Kubectl exec via subprocess works completely fine, the issue it when i migrated to using the kr8s lib
I am basically calling this
2025-02-03 14:54:24,062 - utils.kubernetes_utils - ERROR - Error copying file to pod: Error copying tar to pod init-gitops: Stdin is not supported with protocol v4.channel.k8s.io, only with v5.channel.k8s.io
Traceback (most recent call last):
File "/app/utils/kubernetes_utils.py", line 325, in copy_tar
self.pod.exec(exec_command, stdin=tar_buffer, check=True)
File "/usr/local/lib/python3.11/site-packages/kr8s/objects.py", line 234, in exec
return run_sync(self.async_exec)(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kr8s/_async_utils.py", line 119, in run_sync_inner
return portal.call(wrapped)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kr8s/_async_utils.py", line 91, in call
return self._portal.call(func, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/from_thread.py", line 290, in call
return cast(T_Retval, self.start_task_soon(func, *args).result())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/usr/local/lib/python3.11/site-packages/anyio/from_thread.py", line 221, in _call_func
retval = await retval_or_awaitable
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kr8s/_objects.py", line 1280, in async_exec
async with ex.run() as process:
File "/usr/local/lib/python3.11/contextlib.py", line 204, in __aenter__
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/kr8s/_exec.py", line 73, in run
raise ExecError(
kr8s._exceptions.ExecError: Stdin is not supported with protocol v4.channel.k8s.io, only with v5.channel.k8s.io
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/utils/kubernetes_utils.py", line 342, in copy_file
self.copy_tar(tar_buffer, remote_path)
File "/app/utils/kubernetes_utils.py", line 328, in copy_tar
raise KubectlError(f"Error copying tar to pod {self.pod.name}: {e}") from e
utils.kubernetes_utils.KubectlError: Error copying tar to pod init-gitops: Stdin is not supported with protocol v4.channel.k8s.io, only with v5.channel.k8s.io
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/app/./main.py", line 654, in <module>
project_automator.run()
File "/app/./main.py", line 438, in run
initgitops_handler.prepare_initgitops_pod()
File "/app/scripts/pods/init_gitops_pod.py", line 98, in prepare_initgitops_pod
self.copy_files(files)
File "/app/scripts/pods/pod_handler.py", line 73, in copy_files
self.pod.copy_file(Path(src).resolve(), Path(dest))
File "/app/utils/kubernetes_utils.py", line 345, in copy_file
raise KubectlError(f"Error copying file to pod {self.pod.name}: {e}") from e
utils.kubernetes_utils.KubectlError: Error copying file to pod init-gitops: Error copying tar to pod init-gitops: Stdin is not supported with protocol v4.channel.k8s.io, only with v5.channel.k8s.io
The text was updated successfully, but these errors were encountered:
Which project are you reporting a bug for?
kr8s
What happened?
This is the main function i am calling
Running Kubectl exec via subprocess works completely fine, the issue it when i migrated to using the kr8s lib
I am basically calling this
Anything else?
The text was updated successfully, but these errors were encountered: