Skip to content

Commit

Permalink
Add knobs for tls support on controllers
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Wessendorf <[email protected]>
  • Loading branch information
matzew committed Dec 17, 2024
1 parent 2a07961 commit d3306df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
16 changes: 11 additions & 5 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (
// Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters).
// _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

"knative.dev/eventing/pkg/apis/feature"
"knative.dev/eventing/pkg/client/certmanager/injection/informers/acme/v1/challenge"
v1certificate "knative.dev/eventing/pkg/client/certmanager/injection/informers/certmanager/v1/certificate"

"knative.dev/eventing/pkg/client/certmanager/injection/informers/certmanager/v1/certificaterequest"
"knative.dev/eventing/pkg/client/certmanager/injection/informers/certmanager/v1/clusterissuer"
"knative.dev/eventing/pkg/client/certmanager/injection/informers/certmanager/v1/issuer"
"knative.dev/pkg/injection"

"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/logging"

filteredFactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
"knative.dev/pkg/signals"
Expand Down Expand Up @@ -64,9 +64,15 @@ func main() {
"app.kubernetes.io/name",
)

for _, inf := range []injection.InformerInjector{challenge.WithInformer, v1certificate.WithInformer, certificaterequest.WithInformer, clusterissuer.WithInformer, issuer.WithInformer} {
injection.Default.RegisterInformer(inf)
}
var featureStore *feature.Store
featureStore = feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(name string, value interface{}) {
featureFlags := value.(feature.Flags)
if !featureFlags.IsDisabledTransportEncryption() && featureStore != nil {
for _, inf := range []injection.InformerInjector{challenge.WithInformer, v1certificate.WithInformer, certificaterequest.WithInformer, clusterissuer.WithInformer, issuer.WithInformer} {
injection.Default.RegisterInformer(inf)
}
}
})

sharedmain.MainWithContext(ctx, "controller",
// Messaging
Expand Down
22 changes: 13 additions & 9 deletions pkg/reconciler/integration/sink/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package sink
import (
"context"

cmclient "knative.dev/eventing/pkg/client/certmanager/injection/client"
cmcertinformer "knative.dev/eventing/pkg/client/certmanager/injection/informers/certmanager/v1/certificate"
pkgreconciler "knative.dev/pkg/reconciler"

"k8s.io/client-go/tools/cache"
Expand All @@ -30,9 +32,6 @@ import (
deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment"
"knative.dev/pkg/client/injection/kube/informers/core/v1/service"

cmclient "knative.dev/eventing/pkg/client/certmanager/injection/client"
cmcertinformer "knative.dev/eventing/pkg/client/certmanager/injection/informers/certmanager/v1/certificate"

integrationsinkreconciler "knative.dev/eventing/pkg/client/injection/reconciler/sinks/v1alpha1/integrationsink"
kubeclient "knative.dev/pkg/client/injection/kube/client"
secretinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/secret/filtered"
Expand All @@ -51,8 +50,6 @@ func NewController(
eventPolicyInformer := eventpolicy.Get(ctx)
deploymentInformer := deploymentinformer.Get(ctx)

cmCertificateInformer := cmcertinformer.Get(ctx)

serviceInformer := service.Get(ctx)

r := &Reconciler{
Expand All @@ -61,12 +58,12 @@ func NewController(
deploymentLister: deploymentInformer.Lister(),
serviceLister: serviceInformer.Lister(),

secretLister: secretInformer.Lister(),
eventPolicyLister: eventPolicyInformer.Lister(),
cmCertificateLister: cmCertificateInformer.Lister(),
certManagerClient: cmclient.Get(ctx),
secretLister: secretInformer.Lister(),
eventPolicyLister: eventPolicyInformer.Lister(),
}

// featureFlags := feature.FromContext(ctx)

var globalResync func(obj interface{})

featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(name string, value interface{}) {
Expand All @@ -76,6 +73,13 @@ func NewController(
})
featureStore.WatchConfigs(cmw)

// If not enabled, it is disable, strict or Permissive
if featureStore.Load().IsPermissiveTransportEncryption() || featureStore.Load().IsStrictTransportEncryption() {
cmCertificateInformer := cmcertinformer.Get(ctx)
r.cmCertificateLister = cmCertificateInformer.Lister()
r.certManagerClient = cmclient.Get(ctx)
}

impl := integrationsinkreconciler.NewImpl(ctx, r, func(impl *controller.Impl) controller.Options {
return controller.Options{
ConfigStore: featureStore,
Expand Down

0 comments on commit d3306df

Please sign in to comment.