ResourceSet
dynamic inputs for preview environments automation
#140
Labels
ResourceSet
dynamic inputs for preview environments automation
#140
With the introduction of the ResourceSet API, the Flux Operator can generate a set of Kubernetes resources based on a static input list defined by users in the
ResourceSet
spec. There are use-cases when the inputs are not known ahead of time and can't be set in a static manner. One such use-case is deploying app code and/or config changes made in a GitHub Pull Request or GitLab Merge Request. To accommodate this use-case, the Flux Operator should allow users to define inputs in a dynamic manner using a CRD namedResourceSetInputProvider
. Based on this CRD the operator would call an external system (e.g. GitHub, GitLab, AzureDevOps APIs) and transform the response for use asResouceSet
inputs.Example
We'll use GitHub and the
podinfo
demo app to demonstrate how the new API should work, but theResourceSetInputProvider
could support GitLab, Azure DevOps, Gitea and any other Git service.Preview environments workflow
deploy/flux-preview
Flux Operator Config
To enable the above workflow, we'll define a series of Flux Operator custom resources in the preview cluster.
First we'll create a dedicated namespace called
podinfo-preview
where all the app instances generated from PRs will be deployed. In that namespace, we'll create a Kubernetes Secret containing a GitHub token that grants read access to the podinfo repository and PRs.In the
podinfo-preview
namespace, we'll create aResourceSetInputProvider
that tells Flux Operator to scan the repository for PRs labeled withdeploy/flux-preview
:To not wait 10 minutes for the operator to detect changes in PRs, we can trigger the scan every time there is any activity on Pull Requests by creating a Flux
Receiver
for GitHub to call:Finally, to deploy podinfo from PRs we'll create a
ResouceSet
that takes its inputs from theResourceSetInputProvider
:The above
ResouceSet
will generate a FluxGitRepository
and aHelmRelease
for each opened PR. The PR number passed as<< inputs.id >>
is used as the name suffix for the Flux objects, and is also used to compose the Ingress host name where the app can be accessed. The latest commit SHA pushed to the PR HEAD is passed as<< inputs.sha >>
, the SHA is used to set the app image tag in the Helm release values. The preview URL, branch name and author are set as annotations on the HelmRelease object to enrich the Flux notifications that the dev team receives.To receive notifications when a PR triggers a Helm release install, upgrade and uninstall (including any deploy erorrs), a Flux
Alert
can be created in thepodinfo-preview
namespace:Note that all the Kubernetes manifests part of this workflow should be stored in the Git repository used to define the preview cluster desired state.
The text was updated successfully, but these errors were encountered: