Skip to content

Commit

Permalink
fix: no events are emitted as broadcaster has no sink configured
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmetzner committed Oct 31, 2024
1 parent dfc77b2 commit 20e070a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions hcloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
hrobot "github.com/syself/hrobot-go"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/scheme"
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/record"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -126,19 +127,26 @@ func newCloud(_ io.Reader) (cloudprovider.Interface, error) {

klog.Infof("Hetzner Cloud k8s cloud controller %s started\n", providerVersion)

eventBroadcaster := record.NewBroadcaster()
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "hcloud-cloud-controller-manager"})

return &cloud{
client: client,
robotClient: robotClient,
cfg: cfg,
networkID: networkID,
recorder: recorder,
}, nil
}

func (c *cloud) Initialize(_ cloudprovider.ControllerClientBuilder, _ <-chan struct{}) {
func (c *cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, stop <-chan struct{}) {
client, _ := clientBuilder.Client("hccm-event-broadcaster")

eventBroadcaster := record.NewBroadcaster()
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "hcloud-cloud-controller-manager"})
eventBroadcaster.StartRecordingToSink(&v1.EventSinkImpl{Interface: client.CoreV1().Events("")})

c.recorder = recorder
go func() {
<-stop
eventBroadcaster.Shutdown()
}()
}

func (c *cloud) Instances() (cloudprovider.Instances, bool) {
Expand Down

0 comments on commit 20e070a

Please sign in to comment.