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.io
with 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
curl
command - 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-tests
repository:$ 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
kubeconfig
file. Ask your OpenShift 4 cluster administrator for the file. When you have thekubeconfig
file 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.
About the author
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.
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit