-
Notifications
You must be signed in to change notification settings - Fork 10
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 ResourceSetInputProvider
API
#143
Conversation
836ca88
to
8c2115e
Compare
3d99d08
to
934ba0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, still need to go through the ResourceSetInputProvider
controller code and everything under internal/gitprovider/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more comments, still need to review the ResourceSetInputProvider controller code and GitHub.
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]>
83bf2b6
to
ea8c100
Compare
ea8c100
to
5c670e2
Compare
Signed-off-by: Stefan Prodan <[email protected]>
5c670e2
to
c9ca8ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! 🚀
This PR introduces the
ResourceSetInputProvider
API with support for two providers:GitHubPullRequest
andGitLabMergeRequest
.For the motivation behind this new API see #140
Closes: #140
ResourceSetInputProvider is a declarative API for generating a set of input values
for use within ResourceSet definitions. The input values are fetched from external
services such as GitHub or GitLab, and can be used to parameterize the resources templates
defined in ResourceSets.
Example
The following example shows a provider that fetches input values from
GitHub Pull Requests labeled with
deploy/flux-preview
:You can run this example by saving the manifest into
flux-appx-prs.yaml
.Apply the ResourceSetInputProvider on the cluster:
Wait for the ResourceSetInputProvider to reconcile:
kubectl wait rsip/flux-appx-prs --for=condition=ready --timeout=5m
Run
kubectl get -o yaml
to see the exported inputs generated in the ResourceSetInputProvider status:Run
kubectl delete
to remove the provider from the cluster:Writing a ResourceSetInputProvider spec
As with all other Kubernetes config, a ResourceSet needs
apiVersion
,kind
,metadata.name
andmetadata.namespace
fields.The name of a ResourceSet object must be a valid DNS subdomain name.
A ResourceSet also needs a
.spec
section.Type
The
.spec.type
field is required and specifies the type of the provider.The following types are supported:
GitHubPullRequest
: fetches input values from opened GitHub Pull Requests.GitLabMergeRequest
: fetches input values from opened GitLab Merge Requests.For both
GitHubPullRequest
andGitLabMergeRequest
types, flux-operator willexport in
.status.exportedInputs
a set of input values for eachPull Request or Merge Request that matches the filter criteria.
The exported inputs structure is:
id
: the ID number of the PR/MR (type string).sha
: the commit SHA of the PR/MR (type string).branch
: the branch name of the PR/MR (type string).author
: the author username of the PR/MR (type string).title
: the title of the PR/MR (type string).URL
The
.spec.url
field is required and specifies the HTTP/S URL of the provider.For Git services, the URL should contain the GitHub repository or the GitLab project address.
Filter
The
.spec.filter
field is optional and specifies the filter criteria for the input values.The following filters are supported:
limit
: limit the number of input values fetched (default is 100).labels
: filter GitHub Pull Requests or GitLab Merge Requests by labels.includeBranch
: regular expression to include branches by name.excludeBranch
: regular expression to exclude branches by name.Example of a filter configuration for GitLab Merge Requests:
Default values
The
.spec.defaultValues
field is optional and specifies the default values for the exported inputs.This field can be used to set values that are common to all the exported inputs.
Example:
Authentication configuration
The
.spec.secretRef
field is optional and specifies the Kubernetes Secret containingthe authentication credentials used for connecting to the external service.
Note that the secret must be created in the same namespace as the ResourceSetInputProvider.
For Git services, the secret should contain the
username
andpassword
keys, with the passwordset to a personal access token that grants access for listing Pull Requests or Merge Requests
and Git branches.
Example secret:
Example secret reference:
TLS certificate configuration
The
.spec.certSecretRef
field is optional and specifies the Kubernetes Secret containing theTLS certificate used for connecting to the external service.
Note that the secret must be created in the same namespace as the ResourceSetInputProvider.
For Git services that use self-signed certificates, the secret should contain the
ca.crt
key.Example secret:
Example certificate reference:
Reconciliation configuration
The reconciliation of behaviour of a ResourceSet 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 calling external services. Default is10m
.fluxcd.controlplane.io/reconcileTimeout
: Set the timeout for calling external services. Default is1m
.ResourceSetInputProvider Status
Conditions
A ResourceSetInputProvider enters various states during its lifecycle, reflected as Kubernetes Conditions.
It can be reconciling while fetching data from external services,
it can be ready, or it can fail during reconciliation.
The ResourceSetInputProvider API is compatible with the kstatus specification,
and reports
Reconciling
andStalled
conditions where applicable toprovide better (timeout) support to solutions polling the ResourceSetInputProvider to
become
Ready
.Reconciling ResourceSetInputProvider
The flux-operator marks a ResourceSetInputProvider as reconciling when it starts
the reconciliation of the same. The Condition added to the ResourceSetInputProvider's
.status.conditions
has the following attributes:type: Reconciling
status: "True"
reason: Progressing
|reason: ProgressingWithRetry
The Condition
message
is updated during the course of the reconciliation toreport the action being performed at any particular moment such as
fetching data from external services.
The
Ready
Condition'sstatus
is also marked asUnknown
.Ready ResourceSetInputProvider
The flux-operator marks a ResourceSetInputProvider as ready when the
data fetching from external services is successful.
When the ResourceSet is "ready", the flux-operator sets a Condition with the
following attributes in the ResourceSet’s
.status.conditions
:type: Ready
status: "True"
reason: ReconciliationSucceeded
Failed ResourceSetInputProvider
The flux-operator may get stuck trying to reconcile and apply a
ResourceSetInputProvider without completing. This can occur due to some of the following factors:
When this happens, the flux-operator sets the
Ready
Condition status to Falseand adds a Condition with the following attributes to the ResourceSet’s
.status.conditions
:type: Ready
status: "False"
reason: ReconciliationFailed
The
message
field of the Condition will contain more information about whythe reconciliation failed.
While the ResourceSetInputProvider has one or more of these Conditions, the flux-operator
will continue to attempt a reconciliation with an
exponential backoff, until it succeeds and the ResourceSetInputProvider is marked as ready.
Exported inputs status
After a successful reconciliation, the ResourceSetInputProvider status contains a list of exported inputs
that can be used in the ResourceSet templates.
Example: