Skip to content

Commit

Permalink
fix: nil reference panic for missing kubeconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed Jun 10, 2024
1 parent 32e8c95 commit 180600d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scrapers/kubernetes/events_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ func WatchResources(ctx api.ScrapeContext, config v1.Kubernetes) error {
WatchResourceBuffer.Store(config.Hash(), buffer)

var err error
var kubeconfig string
if config.Kubeconfig != nil {
ctx, _, err = applyKubeconfig(ctx, *config.Kubeconfig)
if err != nil {
return fmt.Errorf("failed to apply custom kube config(%s): %w", config.Kubeconfig, err)
}
kubeconfig, err = ctx.GetEnvValueFromCache(*config.Kubeconfig, ctx.GetNamespace())
if err != nil {
return fmt.Errorf("failed to get kubeconfig from env: %w", err)
}

} else {
_, err = kube.DefaultRestConfig()
if err != nil {
Expand All @@ -70,7 +76,7 @@ func WatchResources(ctx api.ScrapeContext, config v1.Kubernetes) error {
}

for _, watchResource := range lo.Uniq(config.Watch) {
if err := globalSharedInformerManager.Register(ctx, config.Kubeconfig.ValueStatic, watchResource, buffer, db.SoftDeleteConfigItem); err != nil {
if err := globalSharedInformerManager.Register(ctx, kubeconfig, watchResource, buffer, db.SoftDeleteConfigItem); err != nil {
return fmt.Errorf("failed to register informer: %w", err)
}
}
Expand Down

0 comments on commit 180600d

Please sign in to comment.