This documentation provides a detailed step-by-step guide for running tests on the fluxcd/flux2-kustomize-helm-example
project. Ensure that you have the necessary prerequisites in place as outlined below.
Prerequisites
Kubernetes Cluster: Ensure that you have access to a Kubernetes cluster version 1.28 or newer. For local testing, Kubernetes Kind is recommended.
GitHub Personal Access Token: You need a GitHub account with a personal access token that has the permission to create repositories.
Flux CLI: Install the Flux CLI on macOS or Linux. Use one of the following methods:
Using Homebrew:
brew install fluxcd/tap/flux
Or by downloading precompiled binaries:
curl -s https://fluxcd.io/install.sh | sudo bash
Setting Up Your Environment
Fork the Repository: Start by forking the
fluxcd/flux2-kustomize-helm-example
repository into your personal GitHub account.Set Environment Variables: Export your GitHub access token, username, and repository name:
export GITHUB_TOKEN=<your_token> export GITHUB_USER=<your_username> export GITHUB_REPO=<your_forked_repo_name>
Verify Kubernetes Cluster Prerequisites: Use the following command to check the prerequisites for your staging cluster:
flux check --pre
Bootstrap Flux in Your Cluster: Set the Kubernetes context to your staging cluster and run:
flux bootstrap github \ --context=staging \ --owner=${GITHUB_USER} \ --repository=${GITHUB_REPO} \ --branch=main \ --personal \ --path=clusters/staging
This command will commit the manifests for the Flux components in the
clusters/staging/flux-system
directory.
Running Tests
1. Validating Kubernetes Manifests and Kustomize Overlays
The project includes a validation script validate.sh
that runs necessary checks.
To execute this script, you can run:
sh scripts/validate.sh
2. Understanding the Validation Script
Here is a breakdown of the validation process performed in scripts/validate.sh
:
Kustomization Validation: This script will validate Kustomize overlays by checking each kustomization file:
echo "INFO - Validating kustomize overlays" find . -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file; do echo "INFO - Validating kustomization ${file/%$kustomize_config}" kustomize build "${file/%$kustomize_config}" "${kustomize_flags[@]}" | \ kubeconform "${kubeconform_flags[@]}" "${kubeconform_config[@]}" if [[ ${PIPESTATUS[0]} != 0 ]]; then exit 1 fi done
Download Flux OpenAPI Schemas: This step ensures that the cluster is using the correct CRD schemas:
echo "INFO - Downloading Flux OpenAPI schemas" mkdir -p /tmp/flux-crd-schemas/master-standalone-strict curl -sL https://github.com/fluxcd/flux2/releases/latest/download/crd-schemas.tar.gz | tar zxf - -C /tmp/flux-crd-schemas/master-standalone-strict
YAML File Validation: The script validates all YAML files within the repository:
find . -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file; do echo "INFO - Validating $file" yq e 'true' "$file" > /dev/null done
Cluster-Specific Validations: The validation script will also check for compliant YAML configurations in the
clusters
folder:echo "INFO - Validating clusters" find ./clusters -maxdepth 2 -type f -name '*.yaml' -print0 | while IFS= read -r -d $'\0' file; do kubeconform "${kubeconform_flags[@]}" "${kubeconform_config[@]}" "${file}" if [[ ${PIPESTATUS[0]} != 0 ]]; then exit 1 fi done
3. End-to-End (E2E) Tests
The E2E tests for the project initialize a Kubernetes cluster in CI and execute test workflows. To run E2E tests, ensure that your CI is configured correctly or execute within an appropriate CI workflow that includes this step.
Follow the guidelines provided to set up your CI environment accordingly.
With these steps, you should be ready to run tests for the fluxcd/flux2-kustomize-helm-example
project. Ensure to review logs and outputs at each stage to capture any issues encountered during the tests.