This document provides a comprehensive step-by-step guide for running tests in the fluxcd/flux2-multi-tenancy project. The tests validate Kubernetes manifests and ensure the setup is correct through CI workflows.

Prerequisites

Ensure the following tools are installed and configured in your environment:

  • kubeconform for validating Kubernetes manifests
  • kustomize for building Kustomize overlays
  • yq for YAML processing
  • Kubernetes cluster access via kubectl
  • Git for repository interactions

Step-by-Step Testing Guide

1. Validate Kustomize Overlays

Navigate to the root directory of the project and run the validation script which checks the Kustomize overlays against kubeconform.

# Execute the validation script
sh scripts/validate.sh

This script utilizes kustomize to build overlays and kubeconform to validate them. In your script, you will see:

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

2. Validate YAML Files

The next step involves validating the YAML files present in the project. You can modify the validate.sh script for additional checks if necessary. Here’s the code segment that validates YAML files:

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

3. Validate Cluster Configuration

Ensure that the cluster configurations are also validated. Use the following command:

# Assume ./clusters contains your cluster configurations
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

4. Verify Git and Helm Sources

Once the validations are complete, ensure the Git and Helm sources are correctly configured in the tenant repository. You can check the status using the following commands:

To verify the cloned tenant Git repository:

flux -n apps get sources git

To check the Helm repository index:

flux -n apps get sources helm

5. Wait for Demo Application Installation

It is crucial to verify that the demo app has been installed successfully in your Kubernetes environment. Use the watch command to monitor:

watch flux -n apps get helmreleases

You should see the output confirming the release reconciliation. For example:

NAME    	READY	MESSAGE                         	REVISION	SUSPENDED
podinfo	True 	Release reconciliation succeeded	5.0.3   	False

Conclusion

By following these steps, you will effectively run tests for the fluxcd/flux2-multi-tenancy project. Ensure each step passes successfully before proceeding to integrate code changes into the main branch. Adhering to this workflow helps maintain the integrity of the project while managing multiple tenants.

Sources: README.md, scripts/validate.sh