-
Notifications
You must be signed in to change notification settings - Fork 28
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
core: make alternate image flag unpositioned for debug mode #49
Conversation
3ceea9c
to
a8d28f2
Compare
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.
@parth-gr could you use vsCode extention like shell-format
shellcheck
for bash formatting? I see space and other lint.
Also, I'll let @BlaineEXE review the flags changes. |
kubectl-rook-ceph.sh
Outdated
alternate_image="${3:-""}" | ||
function run_start_debug(){ | ||
parse_flags parse_image_flag "$@" | ||
if [ -n "$ALTERNATE_IMAGE" ];then |
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.
What about this? I'm finding the if constructs hard to read, and I'm not sure the code seems like it will work as intended. This also ensures with end_of_command_parsing
that there aren't extraneous arguments also.
DEBUG_DEPLOYMENT_NAME=""
function parse_extra_start_debug_flags() {
[[ -z "${1:-""}" ]] && fail_error "Missing mon or osd deployment name"
DEBUG_DEPLOYMENT_NAME="$1"
parse_flags parse_image_flag "${REMAINING_ARGS[@]}"
end_of_command_parsing "${REMAINING_ARGS[@]}" # end of command tree
}
function run_start_debug() {
parse_flags parse_image_flag "$@"
parse_extra_start_debug_flags "${REMAINING_ARGS[@]}"
[[ -z "${DEBUG_DEPLOYMENT_NAME:-""}" ]] && fail_error "Failed to parse mon or osd deployment name"
# ... etc. ...
}
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.
The current code works completely fine
[rider@localhost kubectl-rook-ceph]$ ./kubectl-rook-ceph.sh debug start --alternate-image imagename deploymentName
Deployment Name: deploymentName
Alternate Image Name:imagename
[rider@localhost kubectl-rook-ceph]$
[rider@localhost kubectl-rook-ceph]$ ./kubectl-rook-ceph.sh debug start deploymentName --alternate-image imagename
Deployment Name: deploymentName
Alternate Image Name:imagename
[rider@localhost kubectl-rook-ceph]$
[rider@localhost kubectl-rook-ceph]$
[rider@localhost kubectl-rook-ceph]$ ./kubectl-rook-ceph.sh debug start deploymentName
Deployment Name: deploymentName
Alternate Image Name:
[rider@localhost kubectl-rook-ceph]$
[rider@localhost kubectl-rook-ceph]$ ./kubectl-rook-ceph.sh debug start --alternate-image imagename
Error: Missing mon or osd deployment name
[rider@localhost kubectl-rook-ceph]$ ./kubectl-rook-ceph.sh debug start deploymentName --alternate-image
./kubectl-rook-ceph.sh: line 136: $1: unbound variable
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.
The above code and end_of_command_parsing
cannot be used, the command needs to be shifted when deployment name is at starting as the "${REMAINING_ARGS[@]}" will still contain the deployment name, so it need array shifting and all
And also for end_of_command_parsing
we need shift if the deployment name is at the last as the "${REMAINING_ARGS[@]} will still contain the deployment name
And also it needs another Debug_deploymernt global variable to make use
If you just want to shift this code into a function I can do it.
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.
We should be using end_of_command_parsing
to flag issues where users give too many commands.
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.
Also, the script should never error because of an unbound variable.
Even if this code works, I am having trouble reading the code's intent, which usually means maintaining the code in the future will be more difficult. I think breaking it into a function and treating DEPLOYMENT_NAME as an argument (which it is) will make things more clear. And on that note as well, comments to explain what is happening will help too.
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 played with this a bit and found that using a function does seem confusing. I have a further suggestion to help keep the code readable. It doesn't rely on conditionals of side-effects, so it is more straightforward to understand, and the comments should help as well. Plus, it uses end_of_command_parsing to accurately determine if a user has supplied too many commands.
ALTERNATE_IMAGE=""
function run_start_debug(){
parse_flags parse_image_flag "$@" # parse flags before the deployment name
deployment_name="${REMAINING_ARGS[0]}" # get deployment name
REMAINING_ARGS=("${REMAINING_ARGS[@]:1}") # remove deploy name from remaining args
parse_flags parse_image_flag "${REMAINING_ARGS[@]}" # parse flags after the deployment name
end_of_command_parsing "${REMAINING_ARGS[@]}"
verify_debug_deployment "$deployment_name"
# copy the deployment spec before scaling it down
deployment_spec=$(KUBECTL_NS_CLUSTER get deployments "$deployment_name" -o json | jq -r ".spec")
# ... etc. ...
This will also make it easier to add new flags in the future. Using conditionals on the assumption that there is only one flag will break if we add another flag to make this tool more configurable in the future.
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 don't see the changes I mentioned just above
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.
Sorry, I missed this comment,
addressed it
kubectl-rook-ceph.sh
Outdated
function run_start_debug(){ | ||
parse_flags parse_image_flag "$@" | ||
if [ -n "$ALTERNATE_IMAGE" ];then | ||
[[ -z "${REMAINING_ARGS:-""}" ]] && fail_error "Missing mon or osd deployment name" |
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'm not sure if this is what you intend here, but REMAINING_ARGS
is an array. "${REMAINING_ARGS}"
will implicitly return only the first item of the array. Generally, implicit behavior makes code harder to read, and I suggest using "${REMAINING_ARGS[0]:-""}"
to make it more explicit that the intent is to check only the first array item.
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.
Done
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.
approving my changes has been addressed
kubectl-rook-ceph.sh
Outdated
alternate_image="${3:-""}" | ||
function run_start_debug(){ | ||
parse_flags parse_image_flag "$@" | ||
if [ -n "$ALTERNATE_IMAGE" ];then |
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 don't see the changes I mentioned just above
Closes: rook#44 Signed-off-by: parth-gr <paarora@redhat.com>
Signed-off-by: parth-gr <paarora@redhat.com>
Closes: #44
Signed-off-by: parth-gr paarora@redhat.com