Skip to content

Commit dec85ba

Browse files
misbernerporridge
authored andcommitted
Allow stripping manifest from the CR status.
1 parent 6261f25 commit dec85ba

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
@@ -84,6 +84,8 @@ type Reconciler struct {
8484
skipPrimaryGVKSchemeRegistration bool
8585
controllerSetupFuncs []ControllerSetupFunc
8686

87+
stripManifestFromStatus bool
88+
8789
annotSetupOnce sync.Once
8890
annotations map[string]struct{}
8991
installAnnotations map[string]annotation.Install
@@ -274,6 +276,17 @@ func SkipDependentWatches(skip bool) Option {
274276
}
275277
}
276278

279+
// StripManifestFromStatus is an Option that configures whether the manifest
280+
// should be removed from the automatically populated status.
281+
// This is recommended if the manifest might return sensitive data (i.e.,
282+
// secrets).
283+
func StripManifestFromStatus(strip bool) Option {
284+
return func(r *Reconciler) error {
285+
r.stripManifestFromStatus = strip
286+
return nil
287+
}
288+
}
289+
277290
// SkipPrimaryGVKSchemeRegistration is an Option that allows to disable the default behaviour of
278291
// registering unstructured.Unstructured as underlying type for the GVK scheme.
279292
//
@@ -618,7 +631,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
618631
if errors.Is(err, driver.ErrReleaseNotFound) {
619632
u.UpdateStatus(updater.EnsureCondition(conditions.Deployed(corev1.ConditionFalse, "", "")))
620633
} else if err == nil {
621-
ensureDeployedRelease(&u, rel)
634+
r.ensureDeployedRelease(&u, rel)
622635
}
623636
u.UpdateStatus(updater.EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))
624637

@@ -684,7 +697,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
684697
}
685698
}
686699

687-
ensureDeployedRelease(&u, rel)
700+
r.ensureDeployedRelease(&u, rel)
688701
u.UpdateStatus(
689702
updater.EnsureCondition(conditions.ReleaseFailed(corev1.ConditionFalse, "", "")),
690703
updater.EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")),
@@ -1021,7 +1034,7 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
10211034
return nil
10221035
}
10231036

1024-
func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
1037+
func (r *Reconciler) ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
10251038
reason := conditions.ReasonInstallSuccessful
10261039
message := "release was successfully installed"
10271040
if rel.Version > 1 {
@@ -1031,6 +1044,13 @@ func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
10311044
if rel.Info != nil && len(rel.Info.Notes) > 0 {
10321045
message = rel.Info.Notes
10331046
}
1047+
1048+
if r.stripManifestFromStatus {
1049+
relCopy := *rel
1050+
relCopy.Manifest = ""
1051+
rel = &relCopy
1052+
}
1053+
10341054
u.UpdateStatus(
10351055
updater.EnsureCondition(conditions.Deployed(corev1.ConditionTrue, reason, message)),
10361056
updater.EnsureDeployedRelease(rel),

pkg/reconciler/reconciler_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ var _ = Describe("Reconciler", func() {
200200
Expect(r.skipDependentWatches).To(BeTrue())
201201
})
202202
})
203+
_ = Describe("StripManifestFromStatus", func() {
204+
It("should set to false", func() {
205+
Expect(StripManifestFromStatus(false)(r)).To(Succeed())
206+
Expect(r.stripManifestFromStatus).To(BeFalse())
207+
})
208+
It("should set to true", func() {
209+
Expect(StripManifestFromStatus(true)(r)).To(Succeed())
210+
Expect(r.stripManifestFromStatus).To(BeTrue())
211+
})
212+
})
203213
_ = Describe("WithMaxConcurrentReconciles", func() {
204214
It("should set the reconciler max concurrent reconciled", func() {
205215
Expect(WithMaxConcurrentReconciles(1)(r)).To(Succeed())

0 commit comments

Comments
 (0)