kubeprobes/kubeprobes_options.go
Piotr Icikowski 9dd25ff024
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
feat(probes)!: rewrite probes logic with named probes
- `ProbeFunction` is now an interface for easier use
- `ProbeFunction`s can be auto-updated with specified update interval
- `StatefulProbes` changed into `ManualProbes` and implement `ProbeFunction` interface
- `ManualProbes` allows for marking probe as unhealthy with custom cause
- handlers now return JSON response with failed probes
- handler's response can be set to verbose via `Kubeprobes` option or via `?v` request param

BREAKING CHANGE: type definitions were replaced with more robust implementation.
2024-03-03 00:00:57 +01:00

48 lines
1.2 KiB
Go

package kubeprobes
// Option represents a [Kubeprobes] constructor option.
type Option interface {
apply(kp *kubeprobes)
}
type option func(*kubeprobes)
func (o option) apply(kp *kubeprobes) {
o(kp)
}
// WithLivenessProbes adds given probe functions to the set of liveness probes.
func WithLivenessProbes(probes ...ProbeFunction) Option {
return option(func(kp *kubeprobes) {
kp.livenessProbes = append(kp.livenessProbes, probes...)
})
}
// WithLivenessPath sets custom path for liveness probe (default is "/live").
func WithLivenessPath(path string) Option {
return option(func(kp *kubeprobes) {
kp.pathLive = path
})
}
// WithReadinessProbes adds given probe functions to the set of readiness probes.
func WithReadinessProbes(probes ...ProbeFunction) Option {
return option(func(kp *kubeprobes) {
kp.readinessProbes = append(kp.readinessProbes, probes...)
})
}
// WithReadinessPath sets custom path for readiness probe (default is "/ready").
func WithReadinessPath(path string) Option {
return option(func(kp *kubeprobes) {
kp.pathReady = path
})
}
// WithVerboseOutput enables verbose output for every request.
func WithVerboseOutput() Option {
return option(func(kp *kubeprobes) {
kp.verbose = true
})
}