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
Adding test-federation-cmd.sh to test kubectl with federation apiserver #38844
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,12 @@ readonly red=$(tput setaf 1) | |
readonly green=$(tput setaf 2) | ||
|
||
kube::test::clear_all() { | ||
kubectl delete "${kube_flags[@]}" rc,pods --all --grace-period=0 --force | ||
if kube::test::if_supports_resource "rc" ; then | ||
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. Use variables here as well? |
||
kubectl delete "${kube_flags[@]}" rc --all --grace-period=0 --force | ||
fi | ||
if kube::test::if_supports_resource "pods" ; then | ||
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. and here? |
||
kubectl delete "${kube_flags[@]}" pods --all --grace-period=0 --force | ||
fi | ||
} | ||
|
||
# Force exact match of a returned result for a object query. Wrap this with || to support multiple | ||
|
@@ -223,3 +228,21 @@ kube::test::if_has_string() { | |
return 1 | ||
fi | ||
} | ||
|
||
# Returns true if the required resource is part of supported resources. | ||
# Expects env vars: | ||
# SUPPORTED_RESOURCES: Array of all resources supported by the apiserver. "*" | ||
# means it supports all resources. For ex: ("*") or ("rc" "*") both mean that | ||
# all resources are supported. | ||
# $1: Name of the resource to be tested. | ||
kube::test::if_supports_resource() { | ||
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. From the build log, almost every check What worries me is that 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. Good catch. Fixed the issue and also added a check to ensure that runTests does not complete without running any tests. It does not check that all tests were run but verifies that atleast a few were run. |
||
SUPPORTED_RESOURCES=${SUPPORTED_RESOURCES:-""} | ||
REQUIRED_RESOURCE=${1:-""} | ||
|
||
for r in "${SUPPORTED_RESOURCES[@]}"; do | ||
if [[ "${r}" == "*" || "${r}" == "${REQUIRED_RESOURCE}" ]]; then | ||
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. Shouldn't 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. its expected that SUPPORTED_RESOURCE will be an explicit list of supported resources or just "*" which is the default value which means that all resources are supported. 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. Yeah, but is that expectation asserted somewhere? What's the defined behavior when the input is my example above? 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. The expected behavior is that if supported resources array contains "*" then it supports all resources. In your example, if SUPPORTED_RESOURCES=(rc rs *), then the function will return true for all resources. 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. Ok fair enough. Please document that somewhere, with examples. Documenting it in function docstring is fine. 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. Done. Updated the documentation for the method. |
||
return 0 | ||
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. return true 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. following the convention of other methods here. 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. Ignore this. I am not sure what I was thinking. Bash doesn't allow returning non-numeric exit codes. |
||
fi | ||
done | ||
return 1 | ||
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. return false 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 |
||
} |
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 think it is fine to drop
if_
from the function name. It is quite obvious given the rest of the 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.
Following the convention of other kube::test functions. Ex: kube::test::if_has_string
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.
Ack.