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.
À propos de l'auteur
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.
Plus de résultats similaires
Take your automation to the next level with Ansible Content Collections for Windows, Splunk, AIOps, MCP, and more
Automating the modern network: A Q1 network automation recap
Technically Speaking | Taming AI agents with observability
Transforming Your Identity Management | Code Comments
Parcourir par canal
Automatisation
Les dernières nouveautés en matière d'automatisation informatique pour les technologies, les équipes et les environnements
Intelligence artificielle
Actualité sur les plateformes qui permettent aux clients d'exécuter des charges de travail d'IA sur tout type d'environnement
Cloud hybride ouvert
Découvrez comment créer un avenir flexible grâce au cloud hybride
Sécurité
Les dernières actualités sur la façon dont nous réduisons les risques dans tous les environnements et technologies
Edge computing
Actualité sur les plateformes qui simplifient les opérations en périphérie
Infrastructure
Les dernières nouveautés sur la plateforme Linux d'entreprise leader au monde
Applications
À l’intérieur de nos solutions aux défis d’application les plus difficiles
Virtualisation
L'avenir de la virtualisation d'entreprise pour vos charges de travail sur site ou sur le cloud