Are you developing or maintaining containers to run in OpenShift 4 environments? If so, you will want to test the container to be sure that it is working correctly.
Red Hat provides standalone containers that are designed to work in OpenShift 4 environments, but you still have to be sure the container is running. It is good to test containers within the continuous integration (CI) process. Red Hat provides processes to prepare OpenShift environments for its customers, so they just need to deliver a test case that ensures each container is working correctly. You don't have to be a Red Hat customer, however, to create a test. Here's how you can do it, whether you're a Red Hat customer or working on your own.
Create a test
To test the container under an OpenShift 4 environment, you must provide information about where to download the container, how to deploy it, and how to test it. In this example, I'm using a RHEL with PostgreSQL 10 container.
For example, you can specify the test like this:
---
registry_redhat_io: "rhscl/postgresql-10-rhel7"
tag_name: "postgresql:10-el7"
deployment: "oc new-app postgresql:10-el7~https://github.com/sclorg/postgresql-container.git \
--name new-postgresql \
--context-dir examples/extending-image/ \
-e POSTGRESQL_USER=user \
-e POSTGRESQL_DATABASE=db \
-e POSTGRESQL_PASSWORD=password"
pod_name: "new-postgresql"
add_route: true
test_exec_command: "./files/check_postgresql_container.sh"
expected_exec_result: "FINE"
check_curl_output: “SOMETHING from curl output”
scl_url: "postgresql-container"
is_name: "postgresql"
Here is what each field means:
- registry_redhat_io: The image in
registry.redhat.iowith the namespace (in this case,rhscl) - tag_name: Specifies the image's
tag_name - deployment: The command for how the image is deployed into the OpenShift 4 environment
- pod_name: The name of the pod in the OpenShift namespace
- add_route: Specifies if the route should be exposed or not (by default, it is not)
- test_exec_command: The file that performs the test
- expected_exec_result: The expected result of the test from
test_exec_command "SOMETHING" - check_curl_output: Part of the content from the output of the
curlcommand - scl_url: Specifies the repository name in the case of SCL.org containers
- is_name: Specifies the container's imagestream
Add a test to the general OpenShift 4 test suite
I used an Ansible test suite from the Software Collections project that can handle OpenShift requirements such as running containers. A simple way to access the test suite is to file a pull request in the GitHub repository.
If you do not want to share the test, you can still add and run it with our test suite.
The steps are:
- Clone the
ansible-testsrepository:$ git clone https://github.com/sclorg/ansible-tests - Change to the cloned repository:
$ cd ansible-tests - Add your testing suite into the vars directory. PostgreSQL 10 is already present.
- Add your container test suite to this file.
[ Learn How to check deployment health on Red Hat OpenShift. ]
As soon as you create the testing file that you do not want to share, you must add it to a directory.
Run a test
If you have already installed an OpenShift 4 cluster, then testing your container is easy. Use the following steps.
- Download the latest version of the OpenShift 4 client for your system from the mirror.
- Next, extract the file using
tar:$ tar -xzvf <FILE> - Download the kubeconfig file. To connect to the OpenShift 4 cluster, you must get the
kubeconfigfile. Ask your OpenShift 4 cluster administrator for the file. When you have thekubeconfigfile available on your system, run:$ export KUBECONFIG=<path_to_kubeconfig>/kubeconfig - Run your test in your OpenShift 4 environment.
- Switch to the cloned repository:
$ cd ansible-tests - Finally, execute the test:
$ make ocp4-tests EXT_TEST=<your_name>
- Switch to the cloned repository:
Test your container
You can add tests for your container by following the steps in this article. By running your tests in an OpenShift 4 cluster, you don't have to worry about the cluster's installation and configuration if an administrator sets it up for you. If you want to learn more about OpenShift, visit Red Hat's Hybrid Cloud blog.
Sobre el autor
Petr is a Senior Software Engineer at Red Hat. He is a contributor to various projects that focus on containers, OpenShift 4, and CI/CD delivery.
His motto is: Whatever we can automate and where we can save time for users, let's do it.
Más como éste
Data-driven automation with Red Hat Ansible Automation Platform
Accelerating NetOps transformation with Ansible Automation Platform
Technically Speaking | Taming AI agents with observability
You Can’t Automate The Difficult Decisions | Code Comments
Navegar por canal
Automatización
Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos
Inteligencia artificial
Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar
Nube híbrida abierta
Vea como construimos un futuro flexible con la nube híbrida
Seguridad
Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías
Edge computing
Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge
Infraestructura
Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo
Aplicaciones
Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones
Virtualización
El futuro de la virtualización empresarial para tus cargas de trabajo locales o en la nube