mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-06 08:51:41 +02:00
* add --track-logs-interval flag Signed-off-by: pznamensky <kompastver@gmail.com> * address review nits: logsInterval plumbing and test coverage - kubedog: move defaultLogsInterval next to TrackOptions in options.go, where the field it defaults lives - kubedog: pass logsInterval through newProgressPrinter instead of a post-construction field assignment; zero falls back to the default - kubedog: cover WithLogsInterval and the LogsInterval default in tracker tests - config: document that defaultTrackLogsInterval is shared by sync and apply and mirrors kubedog's default - config: add a negative-interval validation test case Signed-off-by: yxxhero <aiopsclub@163.com> --------- Signed-off-by: pznamensky <kompastver@gmail.com> Signed-off-by: yxxhero <aiopsclub@163.com> Co-authored-by: yxxhero <aiopsclub@163.com>
113 lines
3.1 KiB
Go
113 lines
3.1 KiB
Go
package kubedog
|
|
|
|
import (
|
|
"time"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
|
"github.com/helmfile/helmfile/pkg/resource"
|
|
)
|
|
|
|
// ResourceBaseline records a resource's identity and generation captured
|
|
// before an in-flight change (e.g. helm upgrade). The tracker uses it to
|
|
// distinguish "still observing the pre-change state" from "the change has
|
|
// landed in the cluster" and only then attaches its readiness logic.
|
|
type ResourceBaseline struct {
|
|
UID types.UID
|
|
Generation int64
|
|
Exists bool
|
|
}
|
|
|
|
type TrackMode string
|
|
|
|
const (
|
|
TrackModeHelm TrackMode = "helm"
|
|
TrackModeHelmLegacy TrackMode = "helm-legacy"
|
|
TrackModeKubedog TrackMode = "kubedog"
|
|
)
|
|
|
|
// defaultLogsInterval is how often the printer flushes captured logs when
|
|
// TrackOptions.LogsInterval is not set (zero).
|
|
const defaultLogsInterval = 10 * time.Second
|
|
|
|
type TrackOptions struct {
|
|
Timeout time.Duration
|
|
// Logs enables emitting logs for every pod kubedog observes.
|
|
Logs bool
|
|
// FailedLogsOnly enables capturing logs in the background and emitting
|
|
// them only for pods that enter a failed state (CrashLoopBackOff, Error,
|
|
// ImagePullBackOff, etc.). Has no effect when Logs is true.
|
|
FailedLogsOnly bool
|
|
// LogsInterval controls how often captured logs are printed.
|
|
LogsInterval time.Duration
|
|
LogsSince time.Duration
|
|
Filter *resource.FilterConfig
|
|
QPS float32
|
|
Burst int
|
|
// Baselines holds the pre-change state of each resource keyed by
|
|
// "Kind/Namespace/Name". When set, the tracker delays attaching kubedog
|
|
// to a resource until its UID changes or its generation increments past
|
|
// the recorded baseline — preventing false "ready" verdicts that would
|
|
// otherwise come from observing the old rolled-out state.
|
|
Baselines map[string]ResourceBaseline
|
|
// Color enables ANSI color escapes in the progress printer output.
|
|
// When false the printer emits plain text regardless of TTY detection.
|
|
Color bool
|
|
}
|
|
|
|
func NewTrackOptions() *TrackOptions {
|
|
return &TrackOptions{
|
|
Timeout: 5 * time.Minute,
|
|
LogsInterval: defaultLogsInterval,
|
|
LogsSince: 10 * time.Minute,
|
|
QPS: 100,
|
|
Burst: 200,
|
|
}
|
|
}
|
|
|
|
func (o *TrackOptions) WithTimeout(timeout time.Duration) *TrackOptions {
|
|
o.Timeout = timeout
|
|
return o
|
|
}
|
|
|
|
func (o *TrackOptions) WithLogs(logs bool) *TrackOptions {
|
|
o.Logs = logs
|
|
return o
|
|
}
|
|
|
|
// WithLogsInterval sets how often captured logs are printed.
|
|
func (o *TrackOptions) WithLogsInterval(interval time.Duration) *TrackOptions {
|
|
o.LogsInterval = interval
|
|
return o
|
|
}
|
|
|
|
func (o *TrackOptions) WithFilterConfig(config *resource.FilterConfig) *TrackOptions {
|
|
o.Filter = config
|
|
return o
|
|
}
|
|
|
|
func (o *TrackOptions) WithQPS(qps float32) *TrackOptions {
|
|
o.QPS = qps
|
|
return o
|
|
}
|
|
|
|
func (o *TrackOptions) WithBurst(burst int) *TrackOptions {
|
|
o.Burst = burst
|
|
return o
|
|
}
|
|
|
|
func (o *TrackOptions) WithBaselines(baselines map[string]ResourceBaseline) *TrackOptions {
|
|
o.Baselines = baselines
|
|
return o
|
|
}
|
|
|
|
func (o *TrackOptions) WithColor(color bool) *TrackOptions {
|
|
o.Color = color
|
|
return o
|
|
}
|
|
|
|
func (o *TrackOptions) WithFailedLogsOnly(v bool) *TrackOptions {
|
|
o.FailedLogsOnly = v
|
|
return o
|
|
}
|