Skip to main content

Follow k8saas Code Quality Process

Context

k8saas publishes some code in Thales using the InnerSource Process. The k8saas engineering is able to validate contribution from Thales. To do so, some code quality mechanisms have been put in place.

The purpose of this documentation is to list and describe them

Writing Python code for k8saas

CI/CD quality steps

Tools installation

Refer to https://gitlab.thalesdigital.io/platform-team-canada/k8saas-innersource/docker-images/pre-commit/-/blob/master/README.md

Pre-commit docker image

This project build a docker image that contains all tools required for the pre-commit checks

Code Quality gitlab ci stages

This file contains common gitlab ci stages.

  • code-quality-run-pre-commit

    Latest .pre-commit-config.yaml file This stage runs pre-commit on the project files. The build fails if errors are found.

  • code-quality-check-coverage-regression

    This stage validates that there is no code coverage regression of the current branch compared to the master branch. This stage is currently only applicable for project with pipeline job named test-python.

  • code-quality-check-coverage-limit

    This stage validates that the code coverage is never under the minimal limit of 80%. This stage is currently only applicable for project with pipeline job named test-python.

HOWTO to use ci/cd quality steps in your gitlab project

This section shows how integrate code quality stages into project's gitlab-ci.yml

  1. Copy latest .pre-commit-config.yaml at project root If the current project contains extra pre-commit tools, see section Update pre-commits to integrate these tools for all projects.

Known Limitations

  • Access token: Code quality stages require gitlab api access. Gitlab api access requires access token which is currently only available at the project level and not at the group level. The only way found to create an common access token to provide gitlab api read access was to create an access token associated to an user. The down side of this approach is that the accesses of the access token are not limited to a group of projects but it has the same accesses then the user.

  • Require .pre-commit-config.yaml: Each project has to be updated with the latest .pre-commit-config.yaml to benefit of the latest tools added in pre-commit and their upgrades.

Update pre-commits

How to update precommit file

  1. Edit .pre-commit-config.yaml to update/add new pre-commit tools
  2. Update projects with the latest .pre-commit-config.yaml

How to update precommit docker image

  1. Edit Dockerfile to install require tools.
  2. Tag the project with the a new version
  3. Update docker image in code-quality.xml to the new version