Skip to content

Commit

Permalink
Check kubeinformer error
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <[email protected]>
  • Loading branch information
saswatamcode committed Oct 18, 2023
1 parent f7668a0 commit 7bdec65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 12 additions & 6 deletions loaders/dashboards/pkg/controller/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func RunGrafanaDashboardController(stop <-chan struct{}) {
klog.Fatal("Failed to build kubeclient", "error", err)
}

go newKubeInformer(kubeClient.CoreV1()).Run(stop)
informer, err := newKubeInformer(kubeClient.CoreV1())
if err != nil {
klog.Fatal("Failed to get informer", "error", err)
}

go informer.Run(stop)
<-stop
}

Expand All @@ -79,7 +84,7 @@ func isDesiredDashboardConfigmap(obj interface{}) bool {
return false
}

func newKubeInformer(coreClient corev1client.CoreV1Interface) cache.SharedIndexInformer {
func newKubeInformer(coreClient corev1client.CoreV1Interface) (cache.SharedIndexInformer, error) {
// get watched namespace
watchedNS := os.Getenv("POD_NAMESPACE")
watchlist := &cache.ListWatch{
Expand All @@ -97,9 +102,7 @@ func newKubeInformer(coreClient corev1client.CoreV1Interface) cache.SharedIndexI
cache.Indexers{},
)

// TODO(saswatamcode): Check error here.
//nolint:errcheck
kubeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
_, err := kubeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
if !isDesiredDashboardConfigmap(obj) {
return
Expand All @@ -125,8 +128,11 @@ func newKubeInformer(coreClient corev1client.CoreV1Interface) cache.SharedIndexI
deleteDashboard(obj)
},
})
if err != nil {
return nil, err
}

return kubeInformer
return kubeInformer, nil
}

func hasCustomFolder(folderTitle string) float64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func createFakeServer(t *testing.T) {
}

func TestGrafanaDashboardController(t *testing.T) {

coreClient := fake.NewSimpleClientset().CoreV1()
stop := make(chan struct{})

Expand All @@ -100,7 +99,10 @@ func TestGrafanaDashboardController(t *testing.T) {

os.Setenv("POD_NAMESPACE", "ns2")

informer := newKubeInformer(coreClient)
informer, err := newKubeInformer(coreClient)
if err != nil {
t.Fatalf("failed to create informer with %v", err)
}
go informer.Run(stop)

cm, err := createDashboard()
Expand Down

0 comments on commit 7bdec65

Please sign in to comment.