-
Notifications
You must be signed in to change notification settings - Fork 42
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
Allow to run with other than local cluster #91
Conversation
test-lib-openshift.sh
Outdated
# Returns 0 if already logged in docker | ||
# Uses global REGISRTY_ADDRESS environment variable for arbitrary registry address. | ||
function ct_os_docker_logged() { | ||
grep -q -e ${REGISRTY_ADDRESS:-172.30.1.1:5000} ~/.docker/config.json |
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 that this will work on temporary machine which is deleted after test run. On longer running machines no docker logout
is run.
For example on my machine I still have "172.30.1.1:5000"
in .docker/config.json
- even when no oc cluster is running.
What about checking REGISTRY_ADDRESS
if it contains non-default value. And in that case skip docker login
.
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.
Sounds fine to me, thanks for the suggestion.
I have some more changes in a queue, still tuning, so, please, do not merge yet. |
d1170b9
to
a579837
Compare
I believe I finished the changes, so it should be ready for a review. Except additions, there is one incompatible change worth mentioning: since I checked the existing images and adding the |
test-lib-openshift.sh
Outdated
# Deletes all objects within the project. | ||
# Handy when we have one project and want to run more tests. | ||
function ct_delete_all_objects() { | ||
for x in bc builds is dc svc po routes secrets ; do |
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.
Only these types? or everything? - see oc types
or https://docs.openshift.com/enterprise/3.0/cli_reference/basic_cli_operations.html#object-types
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.
Thanks, will extend this list.
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.
Current list is:
https://docs.openshift.com/container-platform/3.9/cli_reference/basic_cli_operations.html#object-types
Thanks for the oc types
tip :).
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.
Actually I did not include events, since it produced too many errors that I'm not able to remove them (external cluster). I think it's ok to keep events as a garbage after the test run.
@@ -460,7 +494,19 @@ function ct_os_test_s2i_app_func() { | |||
|
|||
ct_os_new_project | |||
# Create a specific imagestream tag for the image so that oc cannot use anything else | |||
ct_os_upload_image "${image_name}" "${image_tagged}" | |||
if [ "${CT_SKIP_UPLOAD_IMAGE:-false}" == 'true' ] ; 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.
Do we have usage for both cases? Wouldn't oc import-image
fits our current usage in tests too? @pkubatrh What do you think?
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 whether import-image works with the local docker -- if it would, then it would make it easier. @pvalena might know maybe, have you tried that?
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.
AFAIR It should work, if you already have the image locally. But then you have to setup the connection to remote registry
in your OpenShift instance and use it for the import.
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.
Looking at it more --from=docker.io/openshift/ruby-20-centos7
should probably work even with the IP of the host
. But I tried the access to host (via some IP), so it may be blocked internally by some OpenShift routing system.
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.
But if you only have the image in the local registry, that is not visible to the remote cluster, this won't work.
# -------------------- | ||
# Runs a command CMD inside a special command pod | ||
# Arguments: cmd - shell command with args to run in a pod | ||
function ct_os_cmd_image_run() { |
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 automatic calling ct_os_deploy_cmd_image
on first ct_os_cmd_image_run
invocation?
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.
ct_os_deploy_cmd_image
requires an image name to be used, so we would either need to specify image for each ct_os_cmd_image_run
call, or run a default (python) image for those cases. I don't have a strong opinion about which variant is better, or whether the current solution is enough.. Feel free to express your preference.
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.
You are right. Maybe better to require explicit call to deploy image.
c59778f
to
dde6cc0
Compare
I'd skip the deep review, and giving +1. |
test-lib-openshift.sh
Outdated
spec: | ||
containers: | ||
- name: command-container | ||
image: ${image_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.
This should be in quotes if I'm not mistaken.
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.
Thx, will use quotes.
test-lib-openshift.sh
Outdated
SECONDS=0 | ||
echo -n "Waiting for command POD ." | ||
while [ $SECONDS -lt 60 ] ; do | ||
ct_os_cmd_image_run "echo 24" &>/dev/null && echo "DONE" && return 0 |
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.
How about using capturing the stdout and using grep -q
to check for an actual command execution.
sout="$(bash -c 'echo $((11*11))')";
grep -q '^121$' <<< "$sout" && echo OK
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.
Good idea :)
test-lib-openshift.sh
Outdated
ct_os_get_image_from_pod() { | ||
local pod_prefix=$1 ; shift | ||
local pod_name=$(ct_os_get_pod_name $pod_prefix) | ||
oc get "po/${pod_name}" -o yaml | grep '^ image: ' | head -n 1 | sed -e 's|^ image: ||' |
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.
You can use (IMO) simplified and resilient:
oc get "po/${pod_name}" -o yaml | sed -ne 's/^\s*image:\s*\(.*\)\s*$/\1/ p' | head -1
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.
Ok, will try.
while true ; do | ||
output=$(ct_os_cmd_image_run "$check_command_exp") | ||
ret=$? | ||
echo "${output}" | grep -qe "${expected_content_match}" || ret=1 |
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.
Checking for correct output of ct_os_cmd_image_run
for 60 in loop seconds seem quite duplicated (I've counted 3) in this PR- maybe you could use a helper function?
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'd add for some next improvements, it is used differently each time, so I don't consider this a big deal for 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.
I could probably create a PR for that.
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.
Great. If you'd be blocked by this one, feel free to merge it, I didn't want to do it before pto and leave it unfixed in other repos (the -p NAME=perl-testing
thing mentioned above.. but otherwise this pr is kinda merge-able.
Otherwise LGTM- but I've not tested it. |
@hhorak Please rebase. Otherwise, +1. |
…luster Allow to not run local cluster, if already logged into any (remote/local) cluster. Allow to use external docker registry and allow skipping image upload and new project creation. Add posibility to import images and use explicit image for default cmd (that is used for testing). New environment variables: * CT_SKIP_NEW_PROJECT: if set to true, no new project is created * CT_SKIP_UPLOAD_IMAGE: if set to true, image is not uploaded to the cluster * CT_NAMESPACE: possibility to re-define the namespace for images New functions: * ct_os_test_cmd_internal: runs a check cmd for verification of the service in the container that is internal in the cluster * ct_os_test_response_internal: checks a response using curl from the container that is internal in the cluster * ct_os_cmd_image_run: run a cmd in the container that is internal in the cluster * ct_os_deploy_cmd_image: deploys a helper container, that is used for commands that needs to run internally in the cluster * ct_os_get_image_from_pod: helper function for getting image name with a register from an existing pod Incompatible change: -p NAME is not set for all templates in ct_os_test_template_app_func, so templates which need it, must set it explicitly as a parameter Other changes: * some calls (curl etc.) are done from within the cluster by default, from a different (helper) container. That's necessary for clusters that do not expose services outside.
feae0b2
to
49fccdd
Compare
Let's do it, rebasing and merging. |
Do not run local cluster, if already logged into any (remote/local) cluster --
oc whoami
should work here, to determine whether we're logged in to the cluster already, but maybe there is a better solution.Also do not login to a docker registry, if the address (now newly configurable) is defined.