Record last handled reconcile at annotation
This commit is contained in:
parent
1b20d255a8
commit
45bfe6dfe5
|
|
@ -135,6 +135,11 @@ type KustomizationStatus struct {
|
||||||
// +optional
|
// +optional
|
||||||
LastAttemptedRevision string `json:"lastAttemptedRevision,omitempty"`
|
LastAttemptedRevision string `json:"lastAttemptedRevision,omitempty"`
|
||||||
|
|
||||||
|
// LastHandledReconcileAt is the last manual reconciliation request (by
|
||||||
|
// annotating the Kustomization) handled by the reconciler.
|
||||||
|
// +optional
|
||||||
|
LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"`
|
||||||
|
|
||||||
// The last successfully applied revision metadata.
|
// The last successfully applied revision metadata.
|
||||||
// +optional
|
// +optional
|
||||||
Snapshot *Snapshot `json:"snapshot,omitempty"`
|
Snapshot *Snapshot `json:"snapshot,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,10 @@ spec:
|
||||||
description: LastAttemptedRevision is the revision of the last reconciliation
|
description: LastAttemptedRevision is the revision of the last reconciliation
|
||||||
attempt.
|
attempt.
|
||||||
type: string
|
type: string
|
||||||
|
lastHandledReconcileAt:
|
||||||
|
description: LastHandledReconcileAt is the last manual reconciliation
|
||||||
|
request (by annotating the Kustomization) handled by the reconciler.
|
||||||
|
type: string
|
||||||
observedGeneration:
|
observedGeneration:
|
||||||
description: ObservedGeneration is the last reconciled generation.
|
description: ObservedGeneration is the last reconciled generation.
|
||||||
format: int64
|
format: int64
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ import (
|
||||||
"sigs.k8s.io/kustomize/api/krusty"
|
"sigs.k8s.io/kustomize/api/krusty"
|
||||||
kustypes "sigs.k8s.io/kustomize/api/types"
|
kustypes "sigs.k8s.io/kustomize/api/types"
|
||||||
|
|
||||||
"github.com/fluxcd/pkg/lockedfile"
|
|
||||||
"github.com/fluxcd/pkg/recorder"
|
"github.com/fluxcd/pkg/recorder"
|
||||||
"github.com/fluxcd/pkg/runtime/predicates"
|
"github.com/fluxcd/pkg/runtime/predicates"
|
||||||
"github.com/fluxcd/pkg/untar"
|
"github.com/fluxcd/pkg/untar"
|
||||||
|
|
@ -214,18 +213,10 @@ func (r *KustomizationReconciler) SetupWithManager(mgr ctrl.Manager, opts Kustom
|
||||||
func (r *KustomizationReconciler) reconcile(
|
func (r *KustomizationReconciler) reconcile(
|
||||||
kustomization kustomizev1.Kustomization,
|
kustomization kustomizev1.Kustomization,
|
||||||
source sourcev1.Source) (kustomizev1.Kustomization, error) {
|
source sourcev1.Source) (kustomizev1.Kustomization, error) {
|
||||||
// acquire lock
|
// record the value of the reconciliation request, if any
|
||||||
unlock, err := r.lock(fmt.Sprintf("%s-%s", kustomization.GetName(), kustomization.GetNamespace()))
|
if v, ok := kustomization.GetAnnotations()[consts.ReconcileAtAnnotation]; ok {
|
||||||
if err != nil {
|
kustomization.Status.LastHandledReconcileAt = v
|
||||||
err = fmt.Errorf("lockfile error: %w", err)
|
|
||||||
return kustomizev1.KustomizationNotReady(
|
|
||||||
kustomization,
|
|
||||||
source.GetArtifact().Revision,
|
|
||||||
sourcev1.StorageOperationFailedReason,
|
|
||||||
err.Error(),
|
|
||||||
), err
|
|
||||||
}
|
}
|
||||||
defer unlock()
|
|
||||||
|
|
||||||
// create tmp dir
|
// create tmp dir
|
||||||
tmpDir, err := ioutil.TempDir("", kustomization.Name)
|
tmpDir, err := ioutil.TempDir("", kustomization.Name)
|
||||||
|
|
@ -646,12 +637,6 @@ func (r *KustomizationReconciler) checkHealth(kustomization kustomizev1.Kustomiz
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *KustomizationReconciler) lock(name string) (unlock func(), err error) {
|
|
||||||
lockFile := path.Join(os.TempDir(), name+".lock")
|
|
||||||
mutex := lockedfile.MutexAt(lockFile)
|
|
||||||
return mutex.Lock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *KustomizationReconciler) parseApplyOutput(in []byte) map[string]string {
|
func (r *KustomizationReconciler) parseApplyOutput(in []byte) map[string]string {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
input := strings.Split(string(in), "\n")
|
input := strings.Split(string(in), "\n")
|
||||||
|
|
|
||||||
|
|
@ -763,6 +763,19 @@ string
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
<code>lastHandledReconcileAt</code><br>
|
||||||
|
<em>
|
||||||
|
string
|
||||||
|
</em>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<em>(Optional)</em>
|
||||||
|
<p>LastHandledReconcileAt is the last manual reconciliation request (by
|
||||||
|
annotating the Kustomization) handled by the reconciler.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
<code>snapshot</code><br>
|
<code>snapshot</code><br>
|
||||||
<em>
|
<em>
|
||||||
<a href="#kustomize.toolkit.fluxcd.io/v1alpha1.Snapshot">
|
<a href="#kustomize.toolkit.fluxcd.io/v1alpha1.Snapshot">
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,11 @@ type KustomizationStatus struct {
|
||||||
// +optional
|
// +optional
|
||||||
LastAttemptedRevision string `json:"lastAttemptedRevision,omitempty"`
|
LastAttemptedRevision string `json:"lastAttemptedRevision,omitempty"`
|
||||||
|
|
||||||
|
// LastHandledReconcileAt is the last manual reconciliation request (by
|
||||||
|
// annotating the Kustomization) handled by the reconciler.
|
||||||
|
// +optional
|
||||||
|
LastHandledReconcileAt string `json:"lastHandledReconcileAt,omitempty"`
|
||||||
|
|
||||||
// The last successfully applied revision metadata.
|
// The last successfully applied revision metadata.
|
||||||
// +optional
|
// +optional
|
||||||
Snapshot *Snapshot `json:"snapshot"`
|
Snapshot *Snapshot `json:"snapshot"`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue