Skip to content

Commit e0130a4

Browse files
authored
Allow stripping manifest from the CR status (#18)
1 parent c7be7f8 commit e0130a4

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

pkg/reconciler/reconciler.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ type Reconciler struct {
8181
markFailedAfter time.Duration
8282
maxHistory int
8383

84+
stripManifestFromStatus bool
85+
8486
annotSetupOnce sync.Once
8587
annotations map[string]struct{}
8688
installAnnotations map[string]annotation.Install
@@ -265,6 +267,17 @@ func SkipDependentWatches(skip bool) Option {
265267
}
266268
}
267269

270+
// StripManifestFromStatus is an Option that configures whether the manifest
271+
// should be removed from the automatically populated status.
272+
// This is recommended if the manifest might return sensitive data (i.e.,
273+
// secrets).
274+
func StripManifestFromStatus(strip bool) Option {
275+
return func(r *Reconciler) error {
276+
r.stripManifestFromStatus = strip
277+
return nil
278+
}
279+
}
280+
268281
// WithMaxConcurrentReconciles is an Option that configures the number of
269282
// concurrent reconciles that the controller will run.
270283
//
@@ -528,7 +541,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.
528541
if errors.Is(err, driver.ErrReleaseNotFound) {
529542
u.UpdateStatus(updater.EnsureCondition(conditions.Deployed(corev1.ConditionFalse, "", "")))
530543
} else if err == nil {
531-
ensureDeployedRelease(&u, rel)
544+
r.ensureDeployedRelease(&u, rel)
532545
}
533546
u.UpdateStatus(updater.EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))
534547

@@ -615,7 +628,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.
615628
}
616629
}
617630

618-
ensureDeployedRelease(&u, rel)
631+
r.ensureDeployedRelease(&u, rel)
619632
u.UpdateStatus(
620633
updater.EnsureCondition(conditions.ReleaseFailed(corev1.ConditionFalse, "", "")),
621634
updater.EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")),
@@ -943,7 +956,7 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
943956
return nil
944957
}
945958

946-
func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
959+
func (r *Reconciler) ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
947960
reason := conditions.ReasonInstallSuccessful
948961
message := "release was successfully installed"
949962
if rel.Version > 1 {
@@ -953,6 +966,13 @@ func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
953966
if rel.Info != nil && len(rel.Info.Notes) > 0 {
954967
message = rel.Info.Notes
955968
}
969+
970+
if r.stripManifestFromStatus {
971+
relCopy := *rel
972+
relCopy.Manifest = ""
973+
rel = &relCopy
974+
}
975+
956976
u.Update(updater.EnsureFinalizer(uninstallFinalizer))
957977
u.UpdateStatus(
958978
updater.EnsureCondition(conditions.Deployed(corev1.ConditionTrue, reason, message)),

pkg/reconciler/reconciler_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ var _ = Describe("Reconciler", func() {
154154
Expect(r.skipDependentWatches).To(Equal(true))
155155
})
156156
})
157+
var _ = Describe("StripManifestFromStatus", func() {
158+
It("should set to false", func() {
159+
Expect(StripManifestFromStatus(false)(r)).To(Succeed())
160+
Expect(r.stripManifestFromStatus).To(Equal(false))
161+
})
162+
It("should set to true", func() {
163+
Expect(StripManifestFromStatus(true)(r)).To(Succeed())
164+
Expect(r.stripManifestFromStatus).To(Equal(true))
165+
})
166+
})
157167
var _ = Describe("WithMaxConcurrentReconciles", func() {
158168
It("should set the reconciler max concurrent reconciled", func() {
159169
Expect(WithMaxConcurrentReconciles(1)(r)).To(Succeed())

0 commit comments

Comments
 (0)