-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ResourceGroup
API
#98
Open
stefanprodan
wants to merge
16
commits into
main
Choose a base branch
from
resource-group
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+3,133
−19
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stefanprodan
added
enhancement
New feature or request
area/api
API related issues and pull requests
labels
Sep 24, 2024
stefanprodan
force-pushed
the
resource-group
branch
6 times, most recently
from
September 26, 2024 11:06
54aaa3c
to
bc20588
Compare
stefanprodan
force-pushed
the
resource-group
branch
2 times, most recently
from
October 4, 2024 11:22
b5209e1
to
1d25e13
Compare
stefanprodan
force-pushed
the
resource-group
branch
2 times, most recently
from
October 22, 2024 15:32
81999fb
to
023b4f1
Compare
stefanprodan
force-pushed
the
resource-group
branch
2 times, most recently
from
December 14, 2024 15:38
b8389fa
to
fcee5c7
Compare
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
Signed-off-by: Stefan Prodan <[email protected]>
stefanprodan
force-pushed
the
resource-group
branch
2 times, most recently
from
January 1, 2025 11:16
5717f54
to
a3e85b9
Compare
Signed-off-by: Stefan Prodan <[email protected]>
stefanprodan
force-pushed
the
resource-group
branch
from
January 1, 2025 11:17
a3e85b9
to
9195fb3
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ResourceGroup is a declarative API for generating a group of Kubernetes objects based on a matrix of input values and a set of templated resources.
The ResourceGroup API offers a high-level abstraction for defining and managing Flux resources and related Kubernetes objects as a single unit. It is designed to reduce the complexity of Kustomize overlays by providing a compact way
of defining different configurations for a set of workloads per tenant and/or environment.
Use cases:
Example
The following example shows a
ResourceGroup
that generates an application instance consisting of a FluxHelmRelease
andOCIRepository
for each tenant with a specific version and replica count.Writing a ResourceGroup spec
As with all other Kubernetes config, a ResourceGroup needs
apiVersion
,kind
, andmetadata
fields. The name of a ResourceGroup object must be a valid DNS subdomain name.A ResourceGroup also needs a
.spec
section.Inputs configuration
The
.spec.inputs
field is optional and specifies a list of input valuesto be used in the resources templates.
Example inputs:
An input value is a key-value pair of strings, where the key is the input name
which can be referenced in the resource templates using the
<< inputs.name >>
syntax.Resources configuration
The
.spec.resources
field is optional and specifies the list of Kubernetes resourceto be generated and reconciled on the cluster.
Example of plain resources without any templating:
Templating resources
The resources can be templated using the
<< inputs.name >>
syntax. The templating engineis based on Go text template. The
<< >>
delimiters are used instead of{{ }}
to avoidconflicts with Helm templating and allow ResourceGroups to be included in Helm charts.
Example of templated resources:
The above example will generate a
Namespace
,ServiceAccount
andRoleBinding
for each tenantwith the specified role.
Templating functions
The templating engine supports slim-sprig functions.
It is recommended to use the
quote
function when templating strings to avoid issues withspecial characters e.g.
<< inputs.version | quote >>
.When templating integers, use the
int
function to convert the string to an integere.g.
<< inputs.replicas | int >>
.When templating booleans, use the
bool
function to convert the string to a booleane.g.
<< inputs.enabled | bool >>
.When using integer or boolean inputs as metadata label values, use the
quote
function to convertthe value to a string e.g.
<< inputs.enabled | quote >>
.When using multi-line strings containing YAML, use the
nindent
function to properly format the stringe.g.:
Resource deduplication
The flux-operator deduplicates resources based on the
apiVersion
,kind
,metadata.name
andmetadata.namespace
fields.This allows defining shared resources that are applied only once, regardless of the number of inputs.
Example of a shared Flux source:
In the above example, the
OCIRepository
resource is created only onceand referred by all
HelmRelease
resources.Conditionally resource exclusion
To exclude a resource based on input values, the
fluxcd.controlplane.io/reconcile
annotation can be setto
disabled
on the resource metadata. This will prevent the resource from being reconciled by the operator.Example of excluding a resource based on an input value:
In the above example, the
ServiceAccount
resource is generated only for theteam1
tenant.Common metadata
The
.spec.commonMetadata
field is optional and specifies common metadata to be applied to all resources.It has two optional fields:
labels
: A map used for setting labelson an object. Any existing label will be overridden if it matches with a key in
this map.
annotations
: A map used for setting annotationson an object. Any existing annotation will be overridden if it matches with a key
in this map.
Example common metadata:
In the above example, all resources generated by the ResourceGroup
will not be pruned by the garbage collection process as the
fluxcd.controlplane.io/prune
annotation is set to
disabled
.Dependency management
.spec.dependsOn
is an optional list used to refer to Kubernetesobjects that the ResourceGroup depends on. If specified, then the ResourceGroup
is reconciled after the referred objects exist in the cluster.
A dependency is a reference to a Kubernetes object with the following fields:
apiVersion
: The API version of the referred object (required).kind
: The kind of the referred object (required).name
: The name of the referred object (required).namespace
: The namespace of the referred object (optional).ready
: A boolean indicating if the referred object must have theReady
status condition set toTrue
(optional, default isfalse
).readyExpr
: A CEL expression that evaluates to a boolean indicating if the referred object is ready (optional).Example of conditional reconciliation based on the existence of CustomResourceDefinitions
and the readiness of a ResourceGroup:
Note that is recommended to define dependencies on CustomResourceDefinitions if the ResourceGroup
deploys Flux HelmReleases which contain custom resources.
When the dependencies are not met, the flux-operator will reevaluate the requirements
every five seconds and reconcile the ResourceGroup when the dependencies are satisfied.
Failed dependencies are reported in the ResourceGroup
Ready
status condition,in log messages and Kubernetes events.
CEL readiness expressions
The
readyExpr
field allows for more complex readiness checks andcan be used for gating the reconciliation of a ResourceGroup based on the evaluation
of the CEL expression.
The expression is evaluated in the context of the referred object and has access to all the fields of the object,
including the status conditions and the status subfields. The expression must evaluate to a boolean value, any syntax
or runtime errors will be reported in the ResourceGroup status conditions.
Example readiness expression:
For testing the CEL expressions, you can use the CEL playground.
Reconciliation configuration
The reconciliation of behaviour of a ResourceGroup can be configured using the following annotations:
fluxcd.controlplane.io/reconcile
: Enable or disable the reconciliation loop. Default isenabled
, set todisabled
to pause the reconciliation.fluxcd.controlplane.io/reconcileEvery
: Set the reconciliation interval used for drift detection and correction. Default is1h
.fluxcd.controlplane.io/reconcileTimeout
: Set the reconciliation timeout including health checks. Default is5m
.Health check configuration
The
.spec.wait
field is optional and instructs the flux-operator to performa health check on all applied resources and waits for them to become ready. The health
check is enabled by default and can be disabled by setting the
.spec.wait
field tofalse
.The health check is performed for the following resources types:
PersistentVolumeClaim, Service, Ingress, CustomResourceDefinition.
By default, the wait timeout is
5m
and can be changed with thefluxcd.controlplane.io/reconcileTimeout
annotation, set on the ResourceGroup object.Role-based access control
The
.spec.serviceAccountName
field is optional and specifies the name of theKubernetes ServiceAccount used by the flux-operator to reconcile the ResourceGroup.
The ServiceAccount must exist in the same namespace as the ResourceGroup
and must have the necessary permissions to create, update and delete
the resources defined in the ResourceGroup.
On multi-tenant clusters, it is recommended to use a dedicated ServiceAccount per tenant namespace
with the minimum required permissions. To enforce a ServiceAccount for all ResourceGroups,
the
--default-service-account=flux-operator
flag can be set in the flux-operator container arguments.With this flag set, only the ResourceGroups created in the same namespace as the flux-operator
will run with cluster-admin permissions.
Garbage collection
The operator performs garbage collection of the resources previously generated by a ResourceGroup
that are no longer present in the current revision. Garbage collection is also performed
when a ResourceGroup object is deleted, triggering a removal of all Kubernetes
objects previously applied on the cluster.
The garbage collection process removes stale resources in stages, first it deletes the Flux
custom resources and waits for the Flux Kustomizations and HelmReleases to be finalized by
the controllers. After the Flux resources are removed (max wait is one minute), the operator
proceeds with the deletion of the remaining Kubernetes objects. This ensures that the
Flux controllers have a chance to clean up the resources they manage before the operator
deletes the Kubernetes ServiceAccount and RoleBinding used by Flux impersonation.
After the garbage collection process is completed, the operator issues a Kubernetes event
containing the list of removed resources and the duration of the cleanup.
The garbage collection is enabled by default and can be disabled for certain resources
by setting the
fluxcd.controlplane.io/prune
annotation todisabled
. To fully disablethe garbage collection for a ResourceGroup, the annotation must be set on all resources
using the
.spec.commonMetadata
field.