This documentation describes the CI/CD workflow employed by the kubernetes-client/python project. Currently, if no explicit CI/CD is set up, it is advised to establish standard processes or utilize available CI systems.

Setting Up CI/CD Workflow

The CI/CD workflow for the project primarily revolves around the release management process, which incorporates the creation of branches, versioning, generating packages, and automated deployment.

Creating a Release Branch

  1. Branch Creation: To create a release branch from master, after merging a new snapshot, you can execute:

    git checkout -b release-x.y master
    
  2. Updating Release Branch: To update an existing branch with the master branch (only for the latest pre-release):

    export RELEASE_BRANCH=release-x.y
    git checkout $RELEASE_BRANCH
    git fetch upstream
    git rebase upstream/$RELEASE_BRANCH
    git pull -X theirs upstream master
    

Versioning and Release Management

The process involves multiple stages of versioning, which include snapshots, alpha (a1), beta (b1), and stable releases.

Preparing the Environment

To facilitate the release process, begin by generating a GitHub personal access token:

export GITHUB_TOKEN=<your_github_personal_access_token>
export MINOR_VERSION=x
export PATCH_VERSION=y  # (not required for snapshot)

Creating Releases

Depending on the desired release type, execute the relevant commands:

  • Snapshot Release:

    KUBERNETES_BRANCH=release-1.${MINOR_VERSION} CLIENT_VERSION=${MINOR_VERSION}.0.0+snapshot DEVELOPMENT_STATUS="3 - Alpha" scripts/release.sh
    
  • Alpha Release:

    KUBERNETES_BRANCH=release-1.${MINOR_VERSION} CLIENT_VERSION=${MINOR_VERSION}.${PATCH_VERSION}.0a1 DEVELOPMENT_STATUS="3 - Alpha" scripts/release.sh
    
  • Beta Release:

    KUBERNETES_BRANCH=release-1.${MINOR_VERSION} CLIENT_VERSION=${MINOR_VERSION}.${PATCH_VERSION}.0b1 DEVELOPMENT_STATUS="4 - Beta" scripts/release.sh
    
  • Stable Release:

    KUBERNETES_BRANCH=release-1.${MINOR_VERSION} CLIENT_VERSION=${MINOR_VERSION}.${PATCH_VERSION}.0 DEVELOPMENT_STATUS="5 - Production/Stable" scripts/release.sh
    

Creating Distribution Packages

Generate the distribution packages:

python setup.py sdist
python setup.py bdist_wheel --universal
ls dist/

You should see two files in the dist folder: "kubernetes*.whl" and "kubernetes*.tar.gz".

Upload the packages to PyPI once verified:

twine upload dist/*

Publishing Releases on GitHub

To create a GitHub release:

  1. Navigate to the releases section of the repository.
  2. Click the Draft a new release button.
  3. Name the tag the same as CLIENT_VERSION.
  4. Change the target branch to “release-x.y”.
  5. If the release is a pre-release, check the This is a pre-release option.

Example of the Release Process

The release process, illustrated through a sample script (scripts/release.sh), ensures that proper versioning and quality checks are adhered to:

#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail

# Verify git status
if git_status=$(git status --porcelain --untracked=no 2>/dev/null) && [[ -n "${git_status}" ]]; then
  echo "!!! Dirty tree. Clean up and try again."
  exit 1
fi

This mechanism ensures that no uncommitted changes proceed with the release, maintaining a clean and structured workflow.

Conclusion

Establishing a robust CI/CD pipeline for the kubernetes-client/python project involves meticulous branch management, version control, package distribution, and subsequent release activities. While the workflow described here provides foundational steps, additional automation through CI tools (like Jenkins, GitHub Actions, or GitLab CI) can further enhance the efficiency of the development lifecycle. Consider integrating those tools for a more comprehensive CI/CD solution.

For further details, refer to the relevant sections in the project’s release documentation.