Record last applied revision

- add LastAppliedRevision field to Status
- set LastAppliedRevision after a successful sync
- add Status section spec
This commit is contained in:
stefanprodan 2020-04-24 00:44:32 +03:00
parent f8aae94975
commit 696658dcc9
6 changed files with 93 additions and 9 deletions

View File

@ -96,9 +96,14 @@ type WorkloadReference struct {
type KustomizationStatus struct {
// +optional
Conditions []Condition `json:"conditions,omitempty"`
// The last successfully applied revision.
// The revision format for Git sources is <branch|tag>/<commit-sha>.
// +optional
LastAppliedRevision string `json:"lastAppliedRevision,omitempty"`
}
func KustomizationReady(kustomization Kustomization, reason, message string) Kustomization {
func KustomizationReady(kustomization Kustomization, revision, reason, message string) Kustomization {
kustomization.Status.Conditions = []Condition{
{
Type: ReadyCondition,
@ -108,6 +113,7 @@ func KustomizationReady(kustomization Kustomization, reason, message string) Kus
Message: message,
},
}
kustomization.Status.LastAppliedRevision = revision
return kustomization
}

View File

@ -166,6 +166,10 @@ spec:
- type
type: object
type: array
lastAppliedRevision:
description: The last successfully applied revision. The revision format
for Git sources is <branch|tag>/<commit-sha>.
type: string
type: object
type: object
version: v1alpha1

View File

@ -253,6 +253,7 @@ func (r *KustomizationReconciler) sync(
return kustomizev1.KustomizationReady(
kustomization,
source.GetArtifact().Revision,
kustomizev1.ApplySucceedReason,
"kustomization was successfully applied",
), nil

View File

@ -39,15 +39,13 @@ that describes a pipeline such as:
- **alert** if something went wrong
- **notify** if the cluster state changed
![pipeline](../diagrams/kustomize-controller-pipeline.png)
The controller the runs these pipelines relies on
The controller that runs these pipelines relies on
[source-controller](https://github.com/fluxcd/source-controller)
for providing the raw manifests from Git repositories or any
other sources that source-controller could support in the future.
other source that source-controller could support in the future.
If a Git repository contains no Kustomize manifests, the controller will
generate the `kustomization.yaml` automatically and label
If a Git repository contains no Kustomize manifests, the controller can
generate the `kustomization.yaml` file automatically and label
the objects for garbage collection (GC).
A pipeline runs on-a-schedule and ca be triggered manually by a
@ -56,8 +54,8 @@ cluster admin or automatically by a source event such as a Git revision change.
When a pipeline is removed from the cluster, the controller's GC terminates
all the objects previously created by that pipeline.
A pipeline can be suspended, while in suspension the controller will
stop the scheduler and will ignore any source events.
A pipeline can be suspended, while in suspension the controller
stops the scheduler and ignores any source events.
Deleting a suspended pipeline does not trigger garbage collection.
Alerting can be configured with a Kubernetes custom resource

View File

@ -12,6 +12,7 @@ of Kubernetes objects generated with Kustomize.
+ [Garbage collection](kustomization.md#garbage-collection)
+ [Health assessment](kustomization.md#health-assessment)
+ [Kustomization dependencies](kustomization.md#kustomization-dependencies)
+ [Status](kustomization.md#status)
- [Profile CRD](profile.md)
+ [Alerting configuration](profile.md#alerting)

View File

@ -69,6 +69,11 @@ The status sub-resource describes the result of the last kustomization execution
type KustomizationStatus struct {
// +optional
Conditions []Condition `json:"conditions,omitempty"`
// The last successfully applied revision.
// The revision format for Git sources is <branch|tag>/<commit-sha>.
// +optional
LastAppliedRevision string `json:"lastAppliedRevision,omitempty"`
}
```
@ -322,3 +327,72 @@ spec:
> **Note** that circular dependencies between kustomizations must be avoided, otherwise the
> interdependent kustomizations will never be applied on the cluster.
## Status
When the controller completes a kustomization apply, reports the result in the `status` sub-resource.
A successful reconciliation sets the ready condition to `true` and updates the revision field:
```yaml
status:
conditions:
- lastTransitionTime: "2020-04-23T19:28:48Z"
message: kustomization was successfully applied
reason: ApplySucceed
status: "True"
type: Ready
lastAppliedRevision: master/a1afe267b54f38b46b487f6e938a6fd508278c07
```
You can wait for the kustomize controller to complete a reconciliation with:
```bash
kubectl wait kustomization/backend --for=condition=ready
```
The controller logs the Kubernetes objects:
```json
{
"level": "info",
"ts": 1587195448.071468,
"logger": "controllers.Kustomization",
"msg": "Kustomization applied in 1.436096591s",
"kustomization": "default/backend",
"output": {
"service/backend": "created",
"deployment.apps/backend": "created",
"horizontalpodautoscaler.autoscaling/backend": "created"
}
}
```
A failed reconciliation sets the ready condition to `false`:
```yaml
status:
conditions:
- lastTransitionTime: "2020-04-23T19:29:48Z"
message: 'server-side validation failed'
reason: ValidationFailed
status: "False"
type: Ready
lastAppliedRevision: master/a1afe267b54f38b46b487f6e938a6fd508278c07
```
> **Note** that the last applied revision is updated only on a successful reconciliation.
When a reconciliation fails, the controller logs the error:
```json
{
"level": "error",
"ts": 1587195448.071468,
"logger": "controllers.Kustomization",
"msg": "server-side validation failed",
"kustomization": "default/backend",
"error": "The Service 'backend' is invalid: spec.type: Unsupported value: 'Ingress'"
}
```