Skip to content

Commit

Permalink
fix: dynamic client error in k8s fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Dec 16, 2024
1 parent 7a9258d commit 8245f0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 9 additions & 8 deletions scrapers/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ func scheduleScraperJob(sc api.ScrapeContext) error {
}

for _, config := range sc.ScrapeConfig().Spec.Kubernetes {
// Update scrape context with provided kubeconfig
if config.Kubeconfig != nil {
c, err := sc.WithKubeconfig(*config.Kubeconfig)
if err != nil {
return fmt.Errorf("failed to apply custom kubeconfig: %w", err)
}
sc.Context = *c
}

if sc.PropertyOn(false, "watch.disable") {
config.Watch = []v1.KubernetesResourceToWatch{}
} else if len(config.Watch) == 0 {
Expand All @@ -242,14 +251,6 @@ func scheduleScraperJob(sc api.ScrapeContext) error {
return fmt.Errorf("failed to watch kubernetes resources: %v", err)
}

if config.Kubeconfig != nil {
c, err := sc.WithKubeconfig(*config.Kubeconfig)
if err != nil {
return fmt.Errorf("failed to apply custom kubeconfig: %w", err)
}
sc.Context = *c

}
watchConsumerJob := ConsumeKubernetesWatchJobFunc(sc, config, queue)
if err := watchConsumerJob.AddToScheduler(scrapeJobScheduler); err != nil {
return fmt.Errorf("failed to schedule kubernetes watch consumer job: %v", err)
Expand Down
8 changes: 8 additions & 0 deletions scrapers/incremental.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ func ConsumeKubernetesWatchJobFunc(sc api.ScrapeContext, config v1.Kubernetes, q

cc := api.NewScrapeContext(ctx.Context).WithScrapeConfig(sc.ScrapeConfig()).WithJobHistory(ctx.History).AsIncrementalScrape()
cc.Context = cc.Context.WithoutName().WithName(fmt.Sprintf("watch[%s/%s]", cc.GetNamespace(), cc.GetName()))
if config.Kubeconfig != nil {
c, err := cc.WithKubeconfig(*config.Kubeconfig)
if err != nil {
ctx.History.AddErrorf("failed to apply custom kubeconfig: %v", err)
return
}
cc.Context = *c
}

backoff := retry.WithMaxRetries(3, retry.NewExponential(time.Second))
err := retry.Do(ctx, backoff, func(_ctx gocontext.Context) error {
Expand Down

0 comments on commit 8245f0b

Please sign in to comment.