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:

  1. Clone the ansible-tests repository:
    $ git clone https://github.com/sclorg/ansible-tests
  2. Change to the cloned repository:
    $ cd ansible-tests
  3. Add your testing suite into the vars directory.  PostgreSQL 10 is already present.
  4. 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.

  1. Download the latest version of the OpenShift 4 client for your system from the mirror.
  2. Next, extract the file using tar:
    $ tar -xzvf <FILE>
  3. 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 the kubeconfig file available on your system, run:
    $ export KUBECONFIG=<path_to_kubeconfig>/kubeconfig
  4. Run your test in your OpenShift 4 environment.
    1. Switch to the cloned repository:
      $ cd ansible-tests
    2. Finally, execute the test:
      $ make ocp4-tests EXT_TEST=<your_name>

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.


저자 소개

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.

UI_Icon-Red_Hat-Close-A-Black-RGB

채널별 검색

automation icon

오토메이션

기술, 팀, 인프라를 위한 IT 자동화 최신 동향

AI icon

인공지능

고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트

open hybrid cloud icon

오픈 하이브리드 클라우드

하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요

security icon

보안

환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보

edge icon

엣지 컴퓨팅

엣지에서의 운영을 단순화하는 플랫폼 업데이트

Infrastructure icon

인프라

세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보

application development icon

애플리케이션

복잡한 애플리케이션에 대한 솔루션 더 보기

Virtualization icon

가상화

온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래