This document outlines the configuration options for the development environment of the FluxCD project. It serves as a step-by-step guide for advanced developers looking to set up and configure their local development environment effectively.
Configuration Overview
Golang Module Configuration
The FluxCD project is structured as a Go module, specifically named github.com/fluxcd/flux2/v2
. Use this module name when performing Go-related operations as it impacts the build output.
# Building the project without vendor mode
go build
Note: Always avoid using the -mod=vendor
option to prevent vendor dependencies.
Build Constraints
When running tests in the FluxCD project, specific build constraints may be defined to filter which files are compiled based on the test category. Tests can be categorized into unit
and e2e
(end-to-end).
Running Unit Tests
To run unit tests, you can leverage the go test command like this:
go test -tags=unit ./...
Running End-to-End Tests
To run end-to-end tests, specify the e2e
tag:
go test -tags=e2e ./...
Environment Variables
Flux uses various environment variables for configuration. Below are some essential environment variables you might want to configure.
- FLUX_BINARY: Specifies the location of the Flux CLI binary.
export FLUX_BINARY=../../bin/flux
Set this variable before running tests or bootstrapping to ensure the correct binary is used.
Makefile Commands
The project includes a Makefile with predefined commands for testing and managing the development lifecycle. Here are some of the important commands and their usage.
Testing
Use the test
command to run tests with specific provider arguments:
make test PROVIDER_ARG="-provider azure" GO_TEST_ARGS="--tags azure"
For GCP provider, the command is:
make test PROVIDER_ARG="-provider gcp"
Destroying Resources
To destroy the created resources that were set up for testing, use the destroy
target:
make destroy PROVIDER_ARG="-provider azure"
SOPS Check
Ensure that the sops
binary is installed, as it’s required for managing secrets. You can check for its presence in the Makefile like this:
sops-check:
ifeq ($(shell which sops),)
$(error "no sops in PATH, consider installing")
endif
Kustomization
Flux uses Kustomize for managing Kubernetes resources. The Makefile includes an implicit target for Kustomizations:
all: $(bases)
Refer to specific directories with kustomization.yaml
files to build resources accordingly.
Terraform Configuration
When running integration tests that involve Cloud providers, Terraform is used to set up the infrastructure. Configuration files for Terraform include variables for Azure and GCP.
Example: Azure Variables
In the variables.tf
for Azure, essential variables are defined:
variable "azuredevops_org" {
type = string
description = "Name of Azure DevOps organizations where the repositories will be created"
}
variable "azure_location" {
type = string
description = "Location of the resource group"
default = "eastus"
}
Example: GCP Variables
Similarly, in the GCP variables.tf
, relevant variables are defined:
variable "gcp_project_id" {
type = string
description = "GCP project to create the resources in"
}
variable "gcp_region" {
type = string
default = "us-central1"
description = "GCP region"
}
Example Code Snippet for Installation Options
The installation options are part of the configuration. Here’s an example structure of the options defined in Go:
type Options struct {
BaseURL string
Version string
Namespace string
Components []string
ComponentsExtra []string
NotificationController string
LogLevel string
}
Adjust these options as necessary during the installation process.
Conclusion
The above guide provides in-depth configuration options and examples for working within the FluxCD development environment. Adhering to these configurations will assist in streamlining development processes and ensuring a smooth build and test experience.
For further details, explore the corresponding files and directories in the FluxCD repository.