kubeprobes/options.go

68 lines
1.6 KiB
Go
Raw Normal View History

package kubeprobes
type option struct {
fn func(*kubeprobes)
}
func (o *option) apply(kp *kubeprobes) {
o.fn(kp)
}
// WithLivenessProbes adds given probe functions to the set of liveness probes.
func WithLivenessProbes(probes ...ProbeFunction) Option {
return &option{
fn: func(kp *kubeprobes) {
kp.livenessProbes = append(kp.livenessProbes, probes...)
},
}
}
// WithLivenessStatefulProbes adds given [StatefulProbe]s to the set of liveness probes.
func WithLivenessStatefulProbes(probes ...*StatefulProbe) Option {
return &option{
fn: func(kp *kubeprobes) {
for _, p := range probes {
kp.livenessProbes = append(kp.livenessProbes, p.GetProbeFunction())
}
},
}
}
// WithLivenessPath sets custom path for liveness probe (default is "/live").
func WithLivenessPath(path string) Option {
return &option{
fn: func(kp *kubeprobes) {
kp.pathLive = path
},
}
}
// WithReadinessProbes adds given probe functions to the set of readiness probes.
func WithReadinessProbes(probes ...ProbeFunction) Option {
return &option{
fn: func(kp *kubeprobes) {
kp.readinessProbes = append(kp.readinessProbes, probes...)
},
}
}
// WithReadinessProbes adds given [StatefulProbe]s to the set of readiness probes.
func WithReadinessStatefulProbes(probes ...*StatefulProbe) Option {
return &option{
fn: func(kp *kubeprobes) {
for _, p := range probes {
kp.readinessProbes = append(kp.readinessProbes, p.GetProbeFunction())
}
},
}
}
// WithReadinessPath sets custom path for readiness probe (default is "/ready").
func WithReadinessPath(path string) Option {
return &option{
fn: func(kp *kubeprobes) {
kp.pathReady = path
},
}
}