Skip to content

Commit

Permalink
[k8s] Fix rsync for context name with : and / (#4065)
Browse files Browse the repository at this point in the history
* [kubernetes] Fix context name with colon

* comment

* remove additional /

* Move the encoding to kubernetes only
  • Loading branch information
Michaelvll authored Oct 11, 2024
1 parent 292febc commit d0d221f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion sky/utils/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,17 @@ def get_remote_home_dir() -> str:
# Build command.
helper_path = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'kubernetes', 'rsync_helper.sh')
namespace_context = f'{self.namespace}+{self.context}'
# Avoid rsync interpreting :, /, and + in namespace_context as the
# default delimiter for options and arguments.
# rsync_helper.sh will parse the namespace_context by reverting the
# encoding and pass it to kubectl exec.
encoded_namespace_context = namespace_context.replace(
':', '%3A').replace('/', '%2F').replace('+', '%2B')
self._rsync(
source,
target,
node_destination=f'{self.pod_name}@{self.namespace}+{self.context}',
node_destination=f'{self.pod_name}@{encoded_namespace_context}',
up=up,
rsh_option=helper_path,
log_path=log_path,
Expand Down
8 changes: 7 additions & 1 deletion sky/utils/kubernetes/rsync_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
shift
pod=$1
shift
namespace_context=$1
echo "pod: $pod" >&2
encoded_namespace_context=$1
# Revert the encoded namespace+context to the original string.
namespace_context=$(echo "$encoded_namespace_context" | sed 's|%3A|:|g' | sed 's|%2B|+|g' | sed 's|%2F|/|g')
echo "namespace_context: $namespace_context" >&2
namespace=$(echo $namespace_context | cut -d+ -f1)
echo "namespace: $namespace" >&2
context=$(echo $namespace_context | grep '+' >/dev/null && echo $namespace_context | cut -d+ -f2- || echo "")
echo "context: $context" >&2
context_lower=$(echo "$context" | tr '[:upper:]' '[:lower:]')
shift
if [ -z "$context" ] || [ "$context_lower" = "none" ]; then
Expand Down

0 comments on commit d0d221f

Please sign in to comment.