Skip to content

Commit 2e2c661

Browse files
feat: change status handling (#124)
* feat: change status handling * test: add tests * chore: remove tests * feat: add correct if * feat: add correct if * feat: add correct if --------- Co-authored-by: Oliver Bähler <[email protected]>
1 parent dc91cb4 commit 2e2c661

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ e2e-install-distro:
267267
@$(MAKE) wait-for-helmreleases
268268

269269
.PHONY: e2e-load-image
270-
e2e-load-image: ko-build-all
271-
kind load docker-image --name $(CLUSTER_NAME) $(FULL_IMG):$(VERSION)
270+
e2e-load-image: kind ko-build-all
271+
$(KIND) load docker-image --name $(CLUSTER_NAME) $(FULL_IMG):$(VERSION)
272272

273273
wait-for-helmreleases:
274274
@ echo "Waiting for all HelmReleases to have observedGeneration >= 0..."

cmd/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ func init() {
3434
func main() {
3535
var metricsAddr string
3636

37-
var enableLeaderElection, enablePprof bool
37+
var enableLeaderElection, enablePprof, enableStatus bool
3838

3939
var probeAddr string
4040

4141
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
4242
flag.StringVar(&probeAddr, "health-probe-bind-address", ":10080", "The address the probe endpoint binds to.")
4343
flag.BoolVar(&enablePprof, "enable-pprof", false, "Enables Pprof endpoint for profiling (not recommend in production)")
44+
flag.BoolVar(&enableStatus, "enable-provider-status", true, "Add all available providers to the status of the SopsSecret resource")
4445
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
4546
"Enable leader election for controller manager. "+
4647
"Enabling this will ensure there is only one active controller manager.")
@@ -78,7 +79,10 @@ func main() {
7879
Log: ctrl.Log.WithName("Controllers").WithName("Secrets"),
7980
Metrics: metricsRecorder,
8081
Scheme: mgr.GetScheme(),
81-
}).SetupWithManager(mgr); err != nil {
82+
}).SetupWithManager(mgr, controllers.SopsSecretReconcilerConfig{
83+
EnableStatus: enableStatus,
84+
ControllerName: "sopssecret",
85+
}); err != nil {
8286
setupLog.Error(err, "unable to create controller", "controller", "SopsSecret")
8387
os.Exit(1)
8488
}

internal/controllers/sopssecret_controller.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,29 @@ import (
3232
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3333
)
3434

35+
type SopsSecretReconcilerConfig struct {
36+
EnableStatus bool
37+
ControllerName string
38+
}
39+
3540
// SopsSecretReconciler reconciles a SopsSecret object.
3641
type SopsSecretReconciler struct {
3742
client.Client
3843
Metrics *metrics.Recorder
3944
Log logr.Logger
4045
Recorder record.EventRecorder
4146
Scheme *runtime.Scheme
47+
Config SopsSecretReconcilerConfig
4248
}
4349

4450
// SetupWithManager sets up the controller with the Manager.
45-
func (r *SopsSecretReconciler) SetupWithManager(mgr ctrl.Manager) error {
51+
func (r *SopsSecretReconciler) SetupWithManager(mgr ctrl.Manager, cfg SopsSecretReconcilerConfig) error {
52+
r.Config = cfg
53+
54+
r.Log.V(7).Info("controller config", "config", r.Config)
55+
4656
return ctrl.NewControllerManagedBy(mgr).
57+
Named(cfg.ControllerName).
4758
For(&sopsv1alpha1.SopsSecret{}).
4859
Watches(&corev1.Secret{},
4960
handler.EnqueueRequestForOwner(mgr.GetScheme(), mgr.GetRESTMapper(), &sopsv1alpha1.SopsSecret{})).
@@ -409,11 +420,17 @@ func (r *SopsSecretReconciler) decryptionProvider(
409420
return nil, nil, err
410421
}
411422

423+
if !r.Config.EnableStatus && len(secret.Status.Providers) > 0 {
424+
secret.Status.Providers = []*api.Origin{}
425+
}
426+
412427
// Gather Secrets from Provider
413428
for _, provider := range matchingProviders {
414-
secret.Status.Providers = append(secret.Status.Providers,
415-
api.NewOrigin(&provider),
416-
)
429+
if r.Config.EnableStatus {
430+
secret.Status.Providers = append(secret.Status.Providers,
431+
api.NewOrigin(&provider),
432+
)
433+
}
417434

418435
for _, sec := range provider.Status.Providers {
419436
if sec.Status == metav1.ConditionTrue {

0 commit comments

Comments
 (0)