Skip to content

Commit

Permalink
feat: log Kubernetes events related to TLS certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpasquier committed Nov 22, 2024
1 parent 2d192ea commit 4a2b7a5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"path/filepath"
"time"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/server/dynamiccertificates"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand Down Expand Up @@ -186,16 +188,24 @@ func New(ctx context.Context, cfg *OperatorConfiguration) (*Operator, error) {
return nil, fmt.Errorf("failed to initialize client CA controller: %w", err)
}

// Only log the events emitted by the certificate controller for now
// because the controller generates invalid events rejected by the
// Kubernetes API when used with DynamicServingContentFromFiles.
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(func(format string, args ...interface{}) {
ctrl.Log.WithName("events").Info(fmt.Sprintf(format, args...))
})

servingCertController = dynamiccertificates.NewDynamicServingCertificateController(
&tls.Config{
ClientAuth: tls.RequireAndVerifyClientCert,
},
clientCAController,
certKeyProvider,
nil,
// Disabling events for now because the controller generates
// invalid events when used with DynamicServingContentFromFiles.
nil,
record.NewEventRecorderAdapter(
eventBroadcaster.NewRecorder(scheme, v1.EventSource{Component: "observability-operator"}),
),
)
if err := servingCertController.RunOnce(); err != nil {
return nil, fmt.Errorf("failed to initialize serving certificate controller: %w", err)
Expand Down

0 comments on commit 4a2b7a5

Please sign in to comment.