Skip to content
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

Merged
merged 3 commits into from
Sep 18, 2018

Conversation

hhorak
Copy link
Member

@hhorak hhorak commented Jun 5, 2018

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.

@hhorak hhorak changed the title Do not run local cluster, if already logged into any (remote/local) cluster Allow to run with other than local cluster Jun 5, 2018
# 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
Copy link
Contributor

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.

Copy link
Member Author

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.

@hhorak hhorak changed the title Allow to run with other than local cluster [WIP] Allow to run with other than local cluster Jun 7, 2018
@hhorak
Copy link
Member Author

hhorak commented Jun 7, 2018

I have some more changes in a queue, still tuning, so, please, do not merge yet.

@hhorak hhorak force-pushed the no-cluster-up-logged branch from d1170b9 to a579837 Compare June 8, 2018 07:47
@hhorak
Copy link
Member Author

hhorak commented Jun 8, 2018

I believe I finished the changes, so it should be ready for a review.

Except additions, there is one incompatible change worth mentioning: since -p NAME is not set in all templates, it is not used in ct_os_test_template_app_func any more, so templates which need it set, must set it explicitly as a parameter. Typically it means to add -p NAME=perl-testing when working with e.g. perl templates, because otherwise the template defines a different name and the functions won't know which pod to work with.

I checked the existing images and adding the -p NAME=<img>-testing fixed this issue in all of them.

@hhorak hhorak changed the title [WIP] Allow to run with other than local cluster Allow to run with other than local cluster Jun 8, 2018
# 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
Copy link
Contributor

@omron93 omron93 Jun 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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
Copy link
Contributor

@omron93 omron93 Jun 8, 2018

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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() {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

@hhorak hhorak force-pushed the no-cluster-up-logged branch from c59778f to dde6cc0 Compare June 8, 2018 15:58
@praiskup
Copy link
Contributor

I'd skip the deep review, and giving +1.

spec:
containers:
- name: command-container
image: ${image_name}
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, will use quotes.

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
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea :)

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: ||'
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@hhorak hhorak Aug 24, 2018

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.

@pvalena
Copy link
Member

pvalena commented Aug 3, 2018

Otherwise LGTM- but I've not tested it.

@omron93
Copy link
Contributor

omron93 commented Aug 28, 2018

@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.
@hhorak hhorak force-pushed the no-cluster-up-logged branch from feae0b2 to 49fccdd Compare September 18, 2018 20:11
@hhorak
Copy link
Member Author

hhorak commented Sep 18, 2018

Let's do it, rebasing and merging.

@hhorak hhorak merged commit 10879d7 into sclorg:master Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants