Skip to content

Commit acc6134

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 acc6134

11 files changed

Lines changed: 67 additions & 7 deletions

File tree

api/v2/helmrelease_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,12 @@ 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+
// +optional
1024+
LastAttemptedReleaseActionDuration *metav1.Duration `json:"lastAttemptedReleaseActionDuration,omitempty"`
1025+
10201026
// Failures is the reconciliation failure count against the latest desired
10211027
// state. It is reset after a successful reconciliation.
10221028
// +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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,21 @@ 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+
<em>(Optional)</em>
1693+
<p>LastAttemptedReleaseActionDuration is the duration of the last
1694+
release action performed for this HelmRelease.</p>
1695+
</td>
1696+
</tr>
1697+
<tr>
1698+
<td>
16841699
<code>failures</code><br>
16851700
<em>
16861701
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ import (
2020
"context"
2121
"fmt"
2222
"strings"
23+
"time"
2324

24-
"github.com/fluxcd/pkg/runtime/logger"
2525
corev1 "k8s.io/api/core/v1"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/client-go/tools/record"
2728
ctrl "sigs.k8s.io/controller-runtime"
2829

30+
"github.com/fluxcd/pkg/chartutil"
2931
"github.com/fluxcd/pkg/runtime/conditions"
32+
"github.com/fluxcd/pkg/runtime/logger"
3033

3134
v2 "github.com/fluxcd/helm-controller/api/v2"
3235
"github.com/fluxcd/helm-controller/internal/action"
3336
"github.com/fluxcd/helm-controller/internal/digest"
34-
"github.com/fluxcd/pkg/chartutil"
3537
)
3638

3739
// Install is an ActionReconciler which attempts to install a Helm release
@@ -72,6 +74,7 @@ func (r *Install) Reconcile(ctx context.Context, req *Request) error {
7274
logBuf = action.NewLogBuffer(action.NewDebugLog(ctrl.LoggerFrom(ctx).V(logger.DebugLevel)), 10)
7375
obsReleases = make(observedReleases)
7476
cfg = r.configFactory.Build(logBuf.Log, observeRelease(obsReleases))
77+
startTime = time.Now()
7578
)
7679

7780
defer summarize(req)
@@ -91,6 +94,9 @@ func (r *Install) Reconcile(ctx context.Context, req *Request) error {
9194
// Run the Helm install action.
9295
_, err := action.Install(ctx, cfg, req.Object, req.Chart, req.Values)
9396

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

internal/reconcile/install_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ import (
3838

3939
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
4040
"github.com/fluxcd/pkg/apis/meta"
41-
"github.com/fluxcd/pkg/runtime/conditions"
42-
4341
"github.com/fluxcd/pkg/chartutil"
42+
"github.com/fluxcd/pkg/runtime/conditions"
4443

4544
v2 "github.com/fluxcd/helm-controller/api/v2"
4645
"github.com/fluxcd/helm-controller/internal/action"
@@ -299,6 +298,8 @@ func TestInstall_Reconcile(t *testing.T) {
299298
g.Expect(obj.Status.Failures).To(Equal(tt.expectFailures))
300299
g.Expect(obj.Status.InstallFailures).To(Equal(tt.expectInstallFailures))
301300
g.Expect(obj.Status.UpgradeFailures).To(Equal(tt.expectUpgradeFailures))
301+
g.Expect(obj.Status.LastAttemptedReleaseAction).To(Equal(v2.ReleaseActionInstall))
302+
g.Expect(obj.Status.LastAttemptedReleaseActionDuration).ToNot(BeNil())
302303
})
303304
}
304305
}

internal/reconcile/upgrade.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ 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

30+
"github.com/fluxcd/pkg/chartutil"
2831
"github.com/fluxcd/pkg/runtime/conditions"
2932
"github.com/fluxcd/pkg/runtime/logger"
3033

3134
v2 "github.com/fluxcd/helm-controller/api/v2"
3235
"github.com/fluxcd/helm-controller/internal/action"
3336
"github.com/fluxcd/helm-controller/internal/digest"
34-
"github.com/fluxcd/pkg/chartutil"
3537
)
3638

3739
// Upgrade is an ActionReconciler which attempts to upgrade a Helm release
@@ -68,6 +70,7 @@ func (r *Upgrade) Reconcile(ctx context.Context, req *Request) error {
6870
logBuf = action.NewLogBuffer(action.NewDebugLog(ctrl.LoggerFrom(ctx).V(logger.DebugLevel)), 10)
6971
obsReleases = make(observedReleases)
7072
cfg = r.configFactory.Build(logBuf.Log, observeRelease(obsReleases))
73+
startTime = time.Now()
7174
)
7275

7376
defer summarize(req)
@@ -82,6 +85,9 @@ func (r *Upgrade) Reconcile(ctx context.Context, req *Request) error {
8285
// Run the Helm upgrade action.
8386
_, err := action.Upgrade(ctx, cfg, req.Object, req.Chart, req.Values)
8487

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

0 commit comments

Comments
 (0)