-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --context support #1
Open
levrik
wants to merge
1
commit into
ljakimczuk:main
Choose a base branch
from
levrik:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ describe() { | |
help() { | ||
echo -e " | ||
Usage: | ||
forward [-n namespace] host [sport:]dport | ||
forward [--context context] [-n namespace] host [sport:]dport | ||
|
||
Examples: | ||
# Forward TCP traffic to the RDS host from your local 5432 port. | ||
|
@@ -27,15 +27,25 @@ Examples: | |
exit 1 | ||
} | ||
|
||
context=$(kubectl config current-context) | ||
namespace="default" | ||
while getopts "hn:" opt; do | ||
while getopts "hn:-:" opt; do | ||
case "$opt" in | ||
h) | ||
describe | ||
help | ||
;; | ||
n) namespace="$OPTARG" | ||
;; | ||
-) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, let's keep it consistent and simplify by using short option. |
||
case "${OPTARG}" in | ||
context) context="${!OPTIND}" | ||
OPTIND=$((OPTIND+1)) | ||
;; | ||
*) OPTIND=$((OPTIND+1)) | ||
;; | ||
esac | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
|
@@ -57,13 +67,13 @@ fi | |
suffix=$(openssl rand -hex 3) | ||
|
||
cleanup() { | ||
kubectl delete pod -n $namespace forwarder-$suffix 2>&1 >/dev/null | ||
kubectl wait --for=delete pod/forwarder-$suffix 2>&1 >/dev/null | ||
kubectl delete pod --context $context -n $namespace forwarder-$suffix 2>&1 >/dev/null | ||
kubectl wait --context $context -n $namespace --for=delete pod/forwarder-$suffix 2>&1 >/dev/null | ||
} | ||
|
||
trap cleanup SIGINT | ||
|
||
cat <<HERE | kubectl -n $namespace create -f 2>&1 >/dev/null - | ||
cat <<HERE | kubectl --context $context -n $namespace create -f 2>&1 >/dev/null - | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
|
@@ -80,5 +90,5 @@ spec: | |
- TCP:${host}:${dport} | ||
HERE | ||
|
||
kubectl wait -n $namespace --for=condition=Ready pod/forwarder-$suffix 2>&1 >/dev/null | ||
kubectl port-forward -n $namespace pod/forwarder-$suffix $sport:$dport | ||
kubectl wait --context $context -n $namespace --for=condition=Ready pod/forwarder-$suffix 2>&1 >/dev/null | ||
kubectl port-forward --context $context -n $namespace pod/forwarder-$suffix $sport:$dport |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this code consistent and use short options. I would suggest
-c context
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to be in line with other built-in
kubectl
commands here. There's just--context
available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, nevertheless using short options is cleaner here imho. We already do it for the
namespace
which is also supported natively by thekubectl
. So, Iwould either:context
to justc
to stay consistent with the current style,kubectl
built-in options, but without creating an explicits support for them here. In this scenario I would leave a note in readme to let users know they could find these options with thekubectl options
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. But it's a bit different with
--namespace
askubectl
also supports-n
as alias for it while-c
isn't an alias for--context
but is used to specify a config file.The latter probably would be the approach here but I don't have time to work on this right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no worries, there is no rush, feel free to come back to it when you have more time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll keep using my fork for now.