Skip to content

Commit 33f4ce6

Browse files
committed
Record the last Helm release action duration in status
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
1 parent 28bf064 commit 33f4ce6

11 files changed

Lines changed: 64 additions & 2 deletions

File tree

api/v2/helmrelease_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,11 @@ type HelmReleaseStatus struct {
10171017
// +optional
10181018
LastAttemptedReleaseAction ReleaseAction `json:"lastAttemptedReleaseAction,omitempty"`
10191019

1020+
// LastAttemptedReleaseActionDuration is the duration of the last
1021+
// release action performed for this HelmRelease.
1022+
// +kubebuilder:validation:Type=string
1023+
LastAttemptedReleaseActionDuration *metav1.Duration `json:"lastAttemptedReleaseActionDuration,omitempty"`
1024+
10201025
// Failures is the reconciliation failure count against the latest desired
10211026
// state. It is reset after a successful reconciliation.
10221027
// +optional

api/v2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,11 @@ spec:
11831183
- install
11841184
- upgrade
11851185
type: string
1186+
lastAttemptedReleaseActionDuration:
1187+
description: |-
1188+
LastAttemptedReleaseActionDuration is the duration of the last
1189+
release action performed for this HelmRelease.
1190+
type: string
11861191
lastAttemptedRevision:
11871192
description: |-
11881193
LastAttemptedRevision is the Source revision of the last reconciliation

docs/api/v2/helm.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,20 @@ HelmRelease. It is used to determine the active remediation strategy.</p>
16811681
</tr>
16821682
<tr>
16831683
<td>
1684+
<code>lastAttemptedReleaseActionDuration</code><br>
1685+
<em>
1686+
<a href="https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Duration">
1687+
Kubernetes meta/v1.Duration
1688+
</a>
1689+
</em>
1690+
</td>
1691+
<td>
1692+
<p>LastAttemptedReleaseActionDuration is the duration of the last
1693+
release action performed for this HelmRelease.</p>
1694+
</td>
1695+
</tr>
1696+
<tr>
1697+
<td>
16841698
<code>failures</code><br>
16851699
<em>
16861700
int64

docs/spec/v2/helmreleases.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,11 @@ are `install` and `upgrade`.
19861986
This field is used by the controller to determine the active remediation
19871987
strategy for the HelmRelease.
19881988

1989+
### Last Attempted Release Action Duration
1990+
1991+
The helm-controller reports the duration of the last Helm release action it
1992+
attempted to perform in the `.status.lastAttemptedReleaseActionDuration` field.
1993+
19891994
### Last Handled Reconcile At
19901995

19911996
The helm-controller reports the last `reconcile.fluxcd.io/requestedAt`

internal/controller/helmrelease_controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,8 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
18611861
// to only have the leading 12 chars digest as build metadata (initial tag metadata overwritten)
18621862
g.Expect(obj.Status.LastAttemptedRevision).To(Equal("0.1.0" + "+" + dig))
18631863
g.Expect(obj.Status.LastAttemptedConfigDigest).To(Equal("sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"))
1864+
g.Expect(obj.Status.LastAttemptedReleaseAction).To(Equal(v2.ReleaseActionInstall))
1865+
g.Expect(obj.Status.LastAttemptedReleaseActionDuration).ToNot(BeNil())
18641866
g.Expect(obj.Status.LastAttemptedValuesChecksum).To(BeEmpty())
18651867

18661868
// change the chart revision with a new version (build metadata) to simulate a new digest
@@ -1875,6 +1877,8 @@ func TestHelmReleaseReconciler_reconcileReleaseFromOCIRepositorySource(t *testin
18751877
// to only have the leading 12 chars digest as build metadata (initial tag metadata overwritten)
18761878
g.Expect(obj.Status.LastAttemptedRevision).To(Equal("0.1.0" + "+" + "adebc5e3cbcd"))
18771879
g.Expect(obj.Status.LastAttemptedConfigDigest).To(Equal("sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"))
1880+
g.Expect(obj.Status.LastAttemptedReleaseAction).To(Equal(v2.ReleaseActionUpgrade))
1881+
g.Expect(obj.Status.LastAttemptedReleaseActionDuration).ToNot(BeNil())
18781882
g.Expect(obj.Status.LastAttemptedValuesChecksum).To(BeEmpty())
18791883
})
18801884

internal/reconcile/atomic_release_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,9 @@ func TestAtomicRelease_Reconcile_PostRenderers_Scenarios(t *testing.T) {
12881288

12891289
g.Expect(obj.Status.ObservedPostRenderersDigest).To(Equal(tt.wantDigest))
12901290
g.Expect(obj.Status.LastAttemptedReleaseAction).To(Equal(tt.wantReleaseAction))
1291+
if tt.wantReleaseAction != "" {
1292+
g.Expect(obj.Status.LastAttemptedReleaseActionDuration).ToNot(BeNil())
1293+
}
12911294
})
12921295
}
12931296
}
@@ -2170,6 +2173,9 @@ func TestAtomicRelease_Reconcile_CommonMetadata_Scenarios(t *testing.T) {
21702173

21712174
g.Expect(obj.Status.ObservedCommonMetadataDigest).To(Equal(tt.wantDigest))
21722175
g.Expect(obj.Status.LastAttemptedReleaseAction).To(Equal(tt.wantReleaseAction))
2176+
if tt.wantReleaseAction != "" {
2177+
g.Expect(obj.Status.LastAttemptedReleaseActionDuration).ToNot(BeNil())
2178+
}
21732179
})
21742180
}
21752181
}

internal/reconcile/install.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ import (
2020
"context"
2121
"fmt"
2222
"strings"
23+
"time"
2324

2425
"github.com/fluxcd/pkg/runtime/logger"
2526
corev1 "k8s.io/api/core/v1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2628
"k8s.io/client-go/tools/record"
2729
ctrl "sigs.k8s.io/controller-runtime"
2830

2931
"github.com/fluxcd/pkg/runtime/conditions"
3032

33+
"github.com/fluxcd/pkg/chartutil"
34+
3135
v2 "github.com/fluxcd/helm-controller/api/v2"
3236
"github.com/fluxcd/helm-controller/internal/action"
3337
"github.com/fluxcd/helm-controller/internal/digest"
34-
"github.com/fluxcd/pkg/chartutil"
3538
)
3639

3740
// Install is an ActionReconciler which attempts to install a Helm release
@@ -72,6 +75,7 @@ func (r *Install) Reconcile(ctx context.Context, req *Request) error {
7275
logBuf = action.NewLogBuffer(action.NewDebugLog(ctrl.LoggerFrom(ctx).V(logger.DebugLevel)), 10)
7376
obsReleases = make(observedReleases)
7477
cfg = r.configFactory.Build(logBuf.Log, observeRelease(obsReleases))
78+
startTime = time.Now()
7579
)
7680

7781
defer summarize(req)
@@ -91,6 +95,9 @@ func (r *Install) Reconcile(ctx context.Context, req *Request) error {
9195
// Run the Helm install action.
9296
_, err := action.Install(ctx, cfg, req.Object, req.Chart, req.Values)
9397

98+
// Record the action duration in status.
99+
req.Object.Status.LastAttemptedReleaseActionDuration = &metav1.Duration{Duration: time.Since(startTime)}
100+
94101
// Record the history of releases observed during the install.
95102
obsReleases.recordOnObject(req.Object, mutateOCIDigest)
96103

internal/reconcile/install_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ func TestInstall_Reconcile(t *testing.T) {
299299
g.Expect(obj.Status.Failures).To(Equal(tt.expectFailures))
300300
g.Expect(obj.Status.InstallFailures).To(Equal(tt.expectInstallFailures))
301301
g.Expect(obj.Status.UpgradeFailures).To(Equal(tt.expectUpgradeFailures))
302+
g.Expect(obj.Status.LastAttemptedReleaseAction).To(Equal(v2.ReleaseActionInstall))
303+
g.Expect(obj.Status.LastAttemptedReleaseActionDuration).ToNot(BeNil())
302304
})
303305
}
304306
}

internal/reconcile/upgrade.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ import (
2020
"context"
2121
"fmt"
2222
"strings"
23+
"time"
2324

2425
corev1 "k8s.io/api/core/v1"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2527
"k8s.io/client-go/tools/record"
2628
ctrl "sigs.k8s.io/controller-runtime"
2729

2830
"github.com/fluxcd/pkg/runtime/conditions"
2931
"github.com/fluxcd/pkg/runtime/logger"
3032

33+
"github.com/fluxcd/pkg/chartutil"
34+
3135
v2 "github.com/fluxcd/helm-controller/api/v2"
3236
"github.com/fluxcd/helm-controller/internal/action"
3337
"github.com/fluxcd/helm-controller/internal/digest"
34-
"github.com/fluxcd/pkg/chartutil"
3538
)
3639

3740
// Upgrade is an ActionReconciler which attempts to upgrade a Helm release
@@ -68,6 +71,7 @@ func (r *Upgrade) Reconcile(ctx context.Context, req *Request) error {
6871
logBuf = action.NewLogBuffer(action.NewDebugLog(ctrl.LoggerFrom(ctx).V(logger.DebugLevel)), 10)
6972
obsReleases = make(observedReleases)
7073
cfg = r.configFactory.Build(logBuf.Log, observeRelease(obsReleases))
74+
startTime = time.Now()
7175
)
7276

7377
defer summarize(req)
@@ -82,6 +86,9 @@ func (r *Upgrade) Reconcile(ctx context.Context, req *Request) error {
8286
// Run the Helm upgrade action.
8387
_, err := action.Upgrade(ctx, cfg, req.Object, req.Chart, req.Values)
8488

89+
// Record the action duration in status.
90+
req.Object.Status.LastAttemptedReleaseActionDuration = &metav1.Duration{Duration: time.Since(startTime)}
91+
8592
// Record the history of releases observed during the upgrade.
8693
obsReleases.recordOnObject(req.Object, mutateOCIDigest)
8794

0 commit comments

Comments
 (0)