|
1 |
| -# When using pod@namespace+context, rsync passes args as: {us} -l pod namespace+context |
2 |
| -# We need to split the pod@namespace+context into pod, namespace and context |
3 |
| -# For backward compatibility, we use + as the separator between namespace and context and add handling when context is not provided |
4 |
| -shift |
5 |
| -pod=$1 |
6 |
| -shift |
7 |
| -echo "pod: $pod" >&2 |
8 |
| -encoded_namespace_context=$1 |
9 |
| -# Revert the encoded namespace+context to the original string. |
10 |
| -namespace_context=$(echo "$encoded_namespace_context" | sed 's|%40|@|g' | sed 's|%3A|:|g' | sed 's|%2B|+|g' | sed 's|%2F|/|g') |
11 |
| -echo "namespace_context: $namespace_context" >&2 |
12 |
| -namespace=$(echo $namespace_context | cut -d+ -f1) |
13 |
| -echo "namespace: $namespace" >&2 |
14 |
| -context=$(echo $namespace_context | grep '+' >/dev/null && echo $namespace_context | cut -d+ -f2- || echo "") |
15 |
| -echo "context: $context" >&2 |
16 |
| -context_lower=$(echo "$context" | tr '[:upper:]' '[:lower:]') |
17 |
| -shift |
| 1 | +if [ "$1" = "-l" ]; then |
| 2 | + # -l pod namespace+context syntax |
| 3 | + shift |
| 4 | + pod=$1 |
| 5 | + shift |
| 6 | + echo "pod: $pod" >&2 |
| 7 | + encoded_namespace_context=$1 |
| 8 | + # Revert the encoded namespace+context to the original string. |
| 9 | + namespace_context=$(echo "$encoded_namespace_context" | sed 's|%40|@|g' | sed 's|%3A|:|g' | sed 's|%2B|+|g' | sed 's|%2F|/|g') |
| 10 | + echo "namespace_context: $namespace_context" >&2 |
| 11 | + namespace=$(echo $namespace_context | cut -d+ -f1) |
| 12 | + echo "namespace: $namespace" >&2 |
| 13 | + context=$(echo $namespace_context | grep '+' >/dev/null && echo $namespace_context | cut -d+ -f2- || echo "") |
| 14 | + echo "context: $context" >&2 |
| 15 | + context_lower=$(echo "$context" | tr '[:upper:]' '[:lower:]') |
| 16 | + shift |
| 17 | +else |
| 18 | + # pod@namespace+context syntax |
| 19 | + encoded_pod_namespace_context=$1 |
| 20 | + pod_namespace_context=$(echo "$encoded_pod_namespace_context" | sed 's|%40|@|g' | sed 's|%3A|:|g' | sed 's|%2B|+|g' | sed 's|%2F|/|g') |
| 21 | + echo "pod_namespace_context: $pod_namespace_context" >&2 |
| 22 | + pod=$(echo $pod_namespace_context | cut -d@ -f1) |
| 23 | + echo "pod: $pod" >&2 |
| 24 | + namespace_context=$(echo $pod_namespace_context | cut -d@ -f2-) |
| 25 | + echo "namespace_context: $namespace_context" >&2 |
| 26 | + namespace=$(echo $namespace_context | cut -d+ -f1) |
| 27 | + echo "namespace: $namespace" >&2 |
| 28 | + context=$(echo $namespace_context | grep '+' >/dev/null && echo $namespace_context | cut -d+ -f2- || echo "") |
| 29 | + echo "context: $context" >&2 |
| 30 | + context_lower=$(echo "$context" | tr '[:upper:]' '[:lower:]') |
| 31 | + shift |
| 32 | +fi |
| 33 | + |
18 | 34 | if [ -z "$context" ] || [ "$context_lower" = "none" ]; then
|
19 | 35 | # If context is none, it means we are using incluster auth. In this case,
|
20 | 36 | # use need to set KUBECONFIG to /dev/null to avoid using kubeconfig file.
|
|
0 commit comments