Skip to content

Commit

Permalink
Optionally disable native cert-signing support for KafkaUser
Browse files Browse the repository at this point in the history
This is useful in environments where certsigningrequests resources
cannot be watched due to RBAC restrictions
  • Loading branch information
amuraru committed Sep 9, 2021
1 parent 4c20ca6 commit b951d19
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ spec:
- --enable-leader-election
- --cert-manager-namespace={{ .Values.certManager.namespace }}
- --cert-manager-enabled={{ .Values.certManager.enabled }}
{{- if not .Values.certSigning.enabled }}
- --disable-cert-signing-support
{{- end }}
{{- if not .Values.webhook.enabled }}
- --disable-webhooks
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions charts/kafka-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ certManager:
namespace: "cert-manager"
enabled: false

certSigning:
enabled: true

alertManager:
enable: true

Expand Down
13 changes: 7 additions & 6 deletions controllers/kafkauser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ import (
var userFinalizer = "finalizer.kafkausers.kafka.banzaicloud.io"

// SetupKafkaUserWithManager registers KafkaUser controller to the manager
func SetupKafkaUserWithManager(mgr ctrl.Manager, certManagerNamespace bool, log logr.Logger) *ctrl.Builder {
func SetupKafkaUserWithManager(mgr ctrl.Manager, certSigningEnabled bool, certManagerNamespace bool, log logr.Logger) *ctrl.Builder {
builder := ctrl.NewControllerManagedBy(mgr).
For(&v1alpha1.KafkaUser{}).Named("KafkaUser")
builder.Watches(
&source.Kind{Type: &certsigningreqv1.CertificateSigningRequest{}},
handler.EnqueueRequestsFromMapFunc(certificateSigningRequestMapper),
ctrlBuilder.WithPredicates(certificateSigningRequestFilter(log)))

if certSigningEnabled {
builder.Watches(
&source.Kind{Type: &certsigningreqv1.CertificateSigningRequest{}},
handler.EnqueueRequestsFromMapFunc(certificateSigningRequestMapper),
ctrlBuilder.WithPredicates(certificateSigningRequestFilter(log)))
}
if certManagerNamespace {
builder.Owns(&certv1.Certificate{})
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/tests/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ var _ = BeforeSuite(func() {
Log: ctrl.Log.WithName("controllers").WithName("KafkaUser"),
}

err = controllers.SetupKafkaUserWithManager(mgr, true, kafkaUserReconciler.Log).Complete(&kafkaUserReconciler)
err = controllers.SetupKafkaUserWithManager(mgr, true, true, kafkaUserReconciler.Log).Complete(&kafkaUserReconciler)
Expect(err).NotTo(HaveOccurred())

kafkaClusterCCReconciler := controllers.CruiseControlTaskReconciler{
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func main() {
webhookDisabled bool
developmentLogging bool
verboseLogging bool
certSigningDisabled bool
certManagerEnabled bool
maxKafkaTopicConcurrentReconciles int
)
Expand All @@ -95,6 +96,7 @@ func main() {
flag.BoolVar(&developmentLogging, "development", false, "Enable development logging")
flag.BoolVar(&verboseLogging, "verbose", false, "Enable verbose logging")
flag.BoolVar(&certManagerEnabled, "cert-manager-enabled", false, "Enable cert-manager integration")
flag.BoolVar(&certSigningDisabled, "disable-cert-signing-support", false, "Disable native certificate signing integration")
flag.IntVar(&maxKafkaTopicConcurrentReconciles, "max-kafka-topic-concurrent-reconciles", 10, "Define max amount of concurrent KafkaTopic reconciles")
flag.Parse()

Expand Down Expand Up @@ -164,7 +166,7 @@ func main() {
Log: ctrl.Log.WithName("controllers").WithName("KafkaUser"),
}

if err = controllers.SetupKafkaUserWithManager(mgr, certManagerEnabled, kafkaUserReconciler.Log).Complete(kafkaUserReconciler); err != nil {
if err = controllers.SetupKafkaUserWithManager(mgr, !certSigningDisabled, certManagerEnabled, kafkaUserReconciler.Log).Complete(kafkaUserReconciler); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "KafkaUser")
os.Exit(1)
}
Expand Down

0 comments on commit b951d19

Please sign in to comment.