Running Red Hat Best Practices for Kubernetes test suite with dci-openshift-app-agent
Back to all posts

Introduction

The dci-openshift-app-agent supports the execution of multiple test suites to validate containers, virtual functions, Helm charts, and operators. These suites are built as Ansible roles, helping the partners on getting prepared for the Red Hat certifications or actually running the certification process on the workloads deployed via DCI.

One of the test suites included on dci-openshift-app-agent is the Red Hat Best Practices for Kubernetes test suite (also called certsuite), to simplify this set of testing tools. Thanks to this integration, it is possible to run the certification tools on a daily basis with the automation capabilities provided by DCI, validating that the tested workloads are ready for certification.

This blog post is useful for people getting familiar with the usage of the certsuite using dci-openshift-app-agent as a tool to automate the whole process. We are going to focus mainly in 3 areas:

  1. The code structure of the dci-openshift-app-agent, in terms of the integration of the certsuite, will be reviewed, focusing on the k8s_best_practices_certsuite role.
  2. A practical example already defined on dci-openshift-app-agent, called tnf_test_example, will be presented, in order to see how to define a workload, based on containers and operators, that will be deployed on a running OpenShift cluster with DCI in order to be tested by the certsuite.
  3. We will review the configuration needed to deploy the tnf_test_example and have it tested using the certsuite all via the dci-openshift-app-agent.

The targeted audience for this blog post is people that are used to using the certsuite and dci-openshift-app-agent. For a more general overview, please see the following presentation (note it is based on former CNF Cert Suite, aka tnf, v3.2.0, so variables are different, but the philosophy is mostly the same). Also, please refer to the documentation for tools like dci-openshift-app-agent, the certsuite, etc. to get more particular details about them.

Note that this blog post is based on certsuite v5.2.2. Please check regularly the k8s_best_practices_certsuite role documentation to see what's new for the latest certsuite stable release, because the information you will see in this blog post may be different for different releases than v5.2.2.

Code structure: the k8s_best_practices_certsuite role

This Ansible role, included on dci-openshift-app-agent, encapsulates the logic for the certsuite, based on the following assumptions regarding the certification suite:

Tasks executed

After deploying the workloads to be tested by the certsuite, in the DCI Red Hat tests phase, the main k8s_best_practices_certsuite role is executed if do_certsuite flag is set to true, following these steps sequentially on different stages:

Variables to have in mind

The tasks executed on the k8s_best_practices_certsuite role rely on variables that allow DCI users to provide the configuration needed by dci-openshift-app-agent to run the certsuite properly.

The configuration does not include the deployment of the workloads (containers, operators, etc.), those steps are done in the dci-openshift-app-agent hooks. Then, these configurations for the certsuite act on top of the workloads deployed in the hooks.

The main variables to have in mind, whose default values are these for some generic variables, and these for some specific variables related to the certification suite, are the following:

1 The logic for this requires an implementation. See examples in the following section.

Example: the tnf_test_example use case

Before executing the certsuite, it is needed to deploy the workloads and to label the pods and operators to test with the auto-discovery labels required by the certsuite. This can be done manually or programmatically. An example of this can be found in tnf_test_example.

This example deploys a couple of pods in two different namespaces, to be used with the CNF Test Suite in a multi-namespace scenario. It also allows the possibility of deploying an operator and a Helm chart to also test them with the certsuite.

The Deployment specification of this pod, obtained from this repository, is a suitable one for passing all the test suites from the certsuite.

Hooks implemented

Here are the steps on each hook for this example:

Variables to have in mind

To deploy this example, it is needed to define the following variables in your pipelines:

Running a DCI job

In this section, we will cover an example of execution of a DCI job launching tnf_test_example with the certsuite, also commenting some troubleshooting tips that you should have into account, extracted from this presentation about how to debug the certsuite with DCI (based on former CNF Cert Suite v4.0.0, but the logic behind this is mostly the same).

What do you need to configure?

There are two main parts to be configured:

Job checklist

When running a job launching the certsuite, you need to confirm that:

Up to this point, what happens if...

Example of a correct DCI job running tnf_test_example with the certsuite

In order to execute an example of a DCI job, managed by dci-openshift-app-agent, making use of the tnf_test_example and running the certsuite, just follow these steps:

  1. Confirm you have a cluster up and running:

    $ export KUBECONFIG=/var/lib/dci-openshift-app-agent/kubeconfig
    $ oc version
    Client Version: 4.11.0-0.nightly-2022-04-24-135651
    Kustomize Version: v4.5.4
    Server Version: 4.11.0-0.nightly-2022-04-24-135651
    Kubernetes Version: v1.23.3+d464c70
    
    $ oc get nodes
    NAME       STATUS   ROLES           AGE   VERSION
    master-0   Ready    master,worker   12h   v1.23.3+54654d2
    master-1   Ready    master,worker   12h   v1.23.3+54654d2
    master-2   Ready    master,worker   12h   v1.23.3+54654d2
    
  2. Run a DCI job using dci-pipeline, with the following pipeline (note this is an example, you should adapt it to your environment):

    ---
    -   name: tnf-test-cnf
        stage: cnf
        prev_stages: [ocp-upgrade, ocp]
        ansible_playbook: /usr/share/dci-openshift-app-agent/dci-openshift-app-agent.yml
        ansible_cfg: /var/lib/dci/pipelines/ansible.cfg
        ansible_inventory: /path/to/your/inventory
        dci_credentials: /etc/dci-openshift-app-agent/dci_credentials.yml
        configuration: "@QUEUE"
        ansible_extravars:
            dci_teardown_on_success: true
            dci_teardown_on_failure: true
            dci_cache_dir: /var/lib/dci-pipeline
            dci_config_dir: /var/lib/dci-openshift-app-agent/samples/tnf_test_example
            do_certsuite: true
            kbpc_test_labels: "common,telco,extended"
            kbpc_test_config:
                -   namespace: "test-cnf"
                    targetpodlabels: [environment=test]
                    targetoperatorlabels: [operators.coreos.com/mongodb-enterprise.test-cnf=]
                    target_crds:
                        -   nameSuffix: "crdexamples.redhat-best-practices-for-k8s.com"
                            scalable: false
                    exclude_connectivity_regexp: ""
                -   namespace: "production-cnf"
                    targetpodlabels: [environment=production]
                    targetoperatorlabels: []
                    target_crds:
                        -   nameSuffix: "crdexamples.redhat-best-practices-for-k8s.com"
                            scalable: false
                    exclude_connectivity_regexp: ""
            kbpc_non_intrusive_only: false
            kbpc_log_level: debug
            kbpc_accepted_kernel_taints:
                -    module: "tls"
            kbpc_services_ignore_list:
                -   operator-webhook
                -   tnf-test-example-samplechart
        use_previous_topic: true
        components:
            -   tnf_test_example
        inputs:
            kubeconfig: kubeconfig_path
        success_tag: tnf-test-cnf-ok
    

Please check the DCI pipeline blog post for more information regarding pipelines.

  1. Check the status of the DCI job until it finishes.
  2. Check the results.

Finally, you should have a DCI job like this one (based on certsuite v5.2.2), which was executed in a disconnected environment. There, you can observe the results obtained. Mainly, you have to take care of the following:

Conclusions

This blog post has summarized the details to keep in mind when automating the certsuite through the dci-openshift-app-agent on top of an OpenShift cluster.

For this purpose, we provide a full definition of the k8s_best_practices_certsuite role with the help of a workload composed by a deployment created in two different namespaces and an operator running in one of the testing namespaces.

Finally, the work finishes with an example of a DCI job that executes the certification over the workload, showing the main aspects to consider when checking the logs and the job status.