CI/CD Pipeline Overview
The kubernetes-client/csharp
library utilizes a robust Continuous Integration and Continuous Delivery (CI/CD) pipeline to ensure code quality, automated testing, and seamless releases. This section outlines the core components and processes involved in the CI/CD workflow.
Building the Library
The library is built using the .NET
framework. The build process is orchestrated by the dotnet
CLI, as defined in the kubernetes-client.proj
file.
Testing the Library
The CI/CD pipeline employs XUnit as the unit testing framework, as documented in README.md
and doc/index.md
.
Unit Tests
To run unit tests locally, follow these steps:
cd csharp/tests
dotnet restore
dotnet test
Code coverage is configured in the CodeCoverage.runsettings
file and includes coverage for the KubernetesClient
library as well as dependent libraries like xunit
, moq
, System.Reactive
, BouncyCastle.Crypto
, and IdentityModel.OidcClient
.
Deployment
The CI/CD pipeline leverages automated processes for deployment:
NuGet Package Publishing:
The src/nuget.proj
file defines the configuration for publishing NuGet packages. The pipeline automatically builds and publishes new releases to the NuGet repository.
Continuous Integration
Continuous integration is achieved through automated builds and tests triggered by code commits to the repository. This ensures that every change is validated and integrated with the main codebase, minimizing potential integration issues.
Continuous Delivery
Continuous delivery automates the release process. Once code passes all tests and is deemed ready for release, the CI/CD pipeline triggers the automatic publishing of NuGet packages. This streamlines releases and minimizes manual intervention.
Example Usage
The csharp
repository includes several examples showcasing how to utilize the library. You can find examples for common tasks like:
- Simple API Interaction:
examples/simple
- AOT Compilation:
examples/aot
- Metrics Collection:
examples/metrics
- Resource Patching:
examples/patch
- Deployment Restart:
examples/restart
For instance, to run the simple example:
git clone https://github.com/kubernetes-client/csharp
cd csharp/examples/simple
dotnet run
This provides a basic example of using the library to interact with a Kubernetes cluster.
The repository also provides an example of using a script to generate Open API documentation from the source code:
cd
${GEN_DIR}/openapi/csharp.sh ${REPO_DIR}/src/KubernetesClient ${REPO_DIR}/csharp.settings
This script takes the source code directory (${REPO_DIR}/src/KubernetesClient
) and a settings file (${REPO_DIR}/csharp.settings
) to generate Open API documentation.
Note: GEN_DIR
and REPO_DIR
are variables that need to be defined in your environment.
Top-Level Directory Explanations
.devcontainer/ - This directory contains files for developing and running the project in a container using Visual Studio Code’s Remote-Containers extension.
examples/ - This directory contains example projects and usage scenarios for the Kubernetes client library.
examples/cp/ - This subdirectory contains examples of copying files to and from Kubernetes clusters.
examples/restart/ - This subdirectory contains examples of restarting Kubernetes pods.
examples/workerServiceDependencyInjection/ - This subdirectory contains an example of using dependency injection in a worker service using the Kubernetes client library.
src/ - This directory contains the source code for the project.
src/KubernetesClient/ - This subdirectory contains the main Kubernetes client library source code.
src/LibKubernetesGenerator/ - This subdirectory contains code for generating C# code from OpenAPI definitions.
tests/ - This directory contains test code for the project.
tests/E2E.Tests/ - This subdirectory contains end-to-end tests for the non-AOT code.
tests/KubernetesClient.Tests/ - This subdirectory contains tests for the main implementation of the Kubernetes client library.
tests/KubernetesClient.Tests/assets/ - This subdirectory contains test assets.
tests/KubernetesClient.Tests/Mock/ - This subdirectory contains tests using mocks.