fix: Fix broken trackLogs functionality in Kubedog tracker (#2630)

* fix: Fix broken `trackLogs` functionality in Kubedog tracker

When using helmfile with the following setup

```
releases:
  - name: my-app
    chart: ./mychart
    trackMode: kubedog
    trackLogs: true
    trackFailOnError: true
```

We don't actually see any logs from the container being printed.

This is because when building the options for the Kubedog tracker, we never
specify `SaveLogsOnlyForNumberOfReplicas` which means this defaults to 0.

Looking at the logic in `pkg/tracker/deployment/tracker.go` we see

```
ignoreLogs := job.ignoreLogs || job.savingLogsReplicas >= job.SaveLogsOnlyForNumberOfReplicas
```

With job.SaveLogsOnlyForNumberOfReplicas always defaulting to 0, this will always ignore logs

This change sets it to a reasonable default of tracking logs from up to 10 pods.

Signed-off-by: Graeme Gillies <ggillies@gitlab.com>

* fix formatting

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Graeme Gillies <ggillies@gitlab.com>

* feat: Refactor out building tracker opts into it's own function, add tests

Signed-off-by: Graeme Gillies <ggillies@gitlab.com>

---------

Signed-off-by: Graeme Gillies <ggillies@gitlab.com>
Co-authored-by: Graeme Gillies <ggillies@gitlab.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Graeme Gillies
2026-06-11 17:17:28 +08:00
committed by GitHub
co-authored by Copilot Autofix powered by AI Graeme Gillies
parent f4686027ff
commit 94e14f3b4e
2 changed files with 56 additions and 6 deletions
+27 -6
View File
@@ -201,6 +201,32 @@ type trackTarget struct {
namespace string
}
// defaultSaveLogsReplicas is the number of pods per resource for which kubedog
// will stream logs when log tracking is enabled. kubedog ignores logs unless
// SaveLogsOnlyForNumberOfReplicas is positive (see ignoreLogs in
// pkg/tracker/deployment/tracker.go), so leaving it at 0 silently suppresses
// all log output even when trackLogs is true.
const defaultSaveLogsReplicas = 10
// buildTrackerOptions constructs the kubedog tracker options from the tracker's
// configured TrackOptions. It is factored out of TrackResources so the option
// mapping (in particular enabling log streaming) can be unit tested without a
// live cluster.
func (t *Tracker) buildTrackerOptions(ctx context.Context) tracker.Options {
opts := tracker.Options{
ParentContext: ctx,
Timeout: t.trackOptions.Timeout,
LogsFromTime: time.Now().Add(-t.trackOptions.LogsSince),
IgnoreLogs: !t.trackOptions.Logs,
}
if t.trackOptions.Logs {
opts.SaveLogsOnlyForNumberOfReplicas = defaultSaveLogsReplicas
}
return opts
}
func (t *Tracker) TrackResources(ctx context.Context, resources []*resource.Resource) error {
if len(resources) == 0 {
t.logger.Info("No resources to track")
@@ -231,12 +257,7 @@ func (t *Tracker) TrackResources(ctx context.Context, resources []*resource.Reso
informer.ConcurrentInformerFactoryOptions{},
)
opts := tracker.Options{
ParentContext: ctx,
Timeout: t.trackOptions.Timeout,
LogsFromTime: time.Now().Add(-t.trackOptions.LogsSince),
IgnoreLogs: !t.trackOptions.Logs,
}
opts := t.buildTrackerOptions(ctx)
var wg sync.WaitGroup
errCh := make(chan error, len(targets))