Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow stripping manifest from the CR status #18

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type Reconciler struct {
markFailedAfter time.Duration
maxHistory int

stripManifestFromStatus bool

annotSetupOnce sync.Once
annotations map[string]struct{}
installAnnotations map[string]annotation.Install
Expand Down Expand Up @@ -265,6 +267,17 @@ func SkipDependentWatches(skip bool) Option {
}
}

// StripManifestFromStatus is an Option that configures whether the manifest
// should be removed from the automatically populated status.
// This is recommended if the manifest might return sensitive data (i.e.,
// secrets).
func StripManifestFromStatus(strip bool) Option {
return func(r *Reconciler) error {
r.stripManifestFromStatus = strip
return nil
}
}

// WithMaxConcurrentReconciles is an Option that configures the number of
// concurrent reconciles that the controller will run.
//
Expand Down Expand Up @@ -528,7 +541,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.
if errors.Is(err, driver.ErrReleaseNotFound) {
u.UpdateStatus(updater.EnsureCondition(conditions.Deployed(corev1.ConditionFalse, "", "")))
} else if err == nil {
ensureDeployedRelease(&u, rel)
r.ensureDeployedRelease(&u, rel)
}
u.UpdateStatus(updater.EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", "")))

Expand Down Expand Up @@ -615,7 +628,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.
}
}

ensureDeployedRelease(&u, rel)
r.ensureDeployedRelease(&u, rel)
u.UpdateStatus(
updater.EnsureCondition(conditions.ReleaseFailed(corev1.ConditionFalse, "", "")),
updater.EnsureCondition(conditions.Irreconcilable(corev1.ConditionFalse, "", "")),
Expand Down Expand Up @@ -943,7 +956,7 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
return nil
}

func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
func (r *Reconciler) ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
reason := conditions.ReasonInstallSuccessful
message := "release was successfully installed"
if rel.Version > 1 {
Expand All @@ -953,6 +966,13 @@ func ensureDeployedRelease(u *updater.Updater, rel *release.Release) {
if rel.Info != nil && len(rel.Info.Notes) > 0 {
message = rel.Info.Notes
}

if r.stripManifestFromStatus {
relCopy := *rel
relCopy.Manifest = ""
rel = &relCopy
}

u.Update(updater.EnsureFinalizer(uninstallFinalizer))
u.UpdateStatus(
updater.EnsureCondition(conditions.Deployed(corev1.ConditionTrue, reason, message)),
Expand Down
10 changes: 10 additions & 0 deletions pkg/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ var _ = Describe("Reconciler", func() {
Expect(r.skipDependentWatches).To(Equal(true))
})
})
var _ = Describe("StripManifestFromStatus", func() {
It("should set to false", func() {
Expect(StripManifestFromStatus(false)(r)).To(Succeed())
Expect(r.stripManifestFromStatus).To(Equal(false))
})
It("should set to true", func() {
Expect(StripManifestFromStatus(true)(r)).To(Succeed())
Expect(r.stripManifestFromStatus).To(Equal(true))
})
})
var _ = Describe("WithMaxConcurrentReconciles", func() {
It("should set the reconciler max concurrent reconciled", func() {
Expect(WithMaxConcurrentReconciles(1)(r)).To(Succeed())
Expand Down