Skip to content

Commit 712a89d

Browse files
misbernerludydoo
authored andcommitted
Allow stripping manifest from the CR status (#18)
1 parent 0850d05 commit 712a89d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

pkg/reconciler/reconciler.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type Reconciler struct {
8888
skipPrimaryGVKSchemeRegistration bool
8989
controllerSetupFuncs []ControllerSetupFunc
9090

91+
stripManifestFromStatus bool
92+
9193
annotSetupOnce sync.Once
9294
annotations map[string]struct{}
9395
installAnnotations map[string]annotation.Install
@@ -278,6 +280,17 @@ func SkipDependentWatches(skip bool) Option {
278280
}
279281
}
280282

283+
// StripManifestFromStatus is an Option that configures whether the manifest
284+
// should be removed from the automatically populated status.
285+
// This is recommended if the manifest might return sensitive data (i.e.,
286+
// secrets).
287+
func StripManifestFromStatus(strip bool) Option {
288+
return func(r *Reconciler) error {
289+
r.stripManifestFromStatus = strip
290+
return nil
291+
}
292+
}
293+
281294
// SkipPrimaryGVKSchemeRegistration is an Option that allows to disable the default behaviour of
282295
// registering unstructured.Unstructured as underlying type for the GVK scheme.
283296
//
@@ -648,7 +661,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.
648661
if errors.Is(err, driver.ErrReleaseNotFound) {
649662
u.UpdateStatus(updater.EnsureCondition(conditions.Deployed(corev1.ConditionFalse, "", "")))
650663
} else if err == nil {
651-
ensureDeployedRelease(&u, rel)
664+
r.ensureDeployedRelease(&u, rel)
652665
}
653666
u.UpdateStatus(updater.EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))
654667

@@ -738,7 +751,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.
738751
}
739752
}
740753

741-
ensureDeployedRelease(&u, rel)
754+
r.ensureDeployedRelease(&u, rel)
742755
u.UpdateStatus(
743756
updater.EnsureCondition(conditions.ReleaseFailed(corev1.ConditionFalse, "", "")),
744757
updater.EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")),
@@ -1097,7 +1110,7 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
10971110
return nil
10981111
}
10991112

1100-
func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
1113+
func (r *Reconciler) ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
11011114
reason := conditions.ReasonInstallSuccessful
11021115
message := "release was successfully installed"
11031116
if rel.Version > 1 {
@@ -1107,6 +1120,14 @@ func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
11071120
if rel.Info != nil && len(rel.Info.Notes) > 0 {
11081121
message = rel.Info.Notes
11091122
}
1123+
1124+
if r.stripManifestFromStatus {
1125+
relCopy := *rel
1126+
relCopy.Manifest = ""
1127+
rel = &relCopy
1128+
}
1129+
1130+
u.Update(updater.EnsureFinalizer(uninstallFinalizer))
11101131
u.UpdateStatus(
11111132
updater.EnsureCondition(conditions.Deployed(corev1.ConditionTrue, reason, message)),
11121133
updater.EnsureDeployedRelease(rel),

pkg/reconciler/reconciler_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ var _ = Describe("Reconciler", func() {
193193
Expect(r.skipDependentWatches).To(Equal(true))
194194
})
195195
})
196+
var _ = Describe("StripManifestFromStatus", func() {
197+
It("should set to false", func() {
198+
Expect(StripManifestFromStatus(false)(r)).To(Succeed())
199+
Expect(r.stripManifestFromStatus).To(Equal(false))
200+
})
201+
It("should set to true", func() {
202+
Expect(StripManifestFromStatus(true)(r)).To(Succeed())
203+
Expect(r.stripManifestFromStatus).To(Equal(true))
204+
})
205+
})
196206
var _ = Describe("WithMaxConcurrentReconciles", func() {
197207
It("should set the reconciler max concurrent reconciled", func() {
198208
Expect(WithMaxConcurrentReconciles(1)(r)).To(Succeed())

0 commit comments

Comments
 (0)