Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nil reference panic for missing kubeconfig #621

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading