refactor(validation): improve errors joining

This commit is contained in:
Piotr Icikowski 2024-03-02 15:45:00 +01:00 committed by Piotr Icikowski
parent 373c803c00
commit ea92b2979c

View File

@ -35,44 +35,28 @@ func New(options ...Option) (Kubeprobes, error) {
}
func (kp *kubeprobes) validate() error {
errs := []error{}
var err error
if kp.pathLive == "" {
errs = append(
errs,
fmt.Errorf("liveness probe path must not be empty"),
)
err = errors.Join(err, fmt.Errorf("liveness probe path must not be empty"))
}
if kp.pathReady == "" {
errs = append(
errs,
fmt.Errorf("readiness probe path must not be empty"),
)
err = errors.Join(err, fmt.Errorf("readiness probe path must not be empty"))
}
if !strings.HasPrefix(kp.pathLive, "/") {
errs = append(
errs,
fmt.Errorf("liveness probe path must start with slash (current: %q)", kp.pathLive),
)
err = errors.Join(err, fmt.Errorf("liveness probe path must start with slash (current: %q)", kp.pathLive))
}
if !strings.HasPrefix(kp.pathReady, "/") {
errs = append(
errs,
fmt.Errorf("readiness probe path must start with slash (current: %q)", kp.pathReady),
)
err = errors.Join(err, fmt.Errorf("readiness probe path must start with slash (current: %q)", kp.pathReady))
}
if kp.pathLive == kp.pathReady {
errs = append(
errs,
fmt.Errorf("liveness and readiness probes have the same values (both %q)", kp.pathLive),
)
err = errors.Join(err, fmt.Errorf("liveness and readiness probes have the same values (both %q)", kp.pathLive))
}
return errors.Join(errs...)
return err
}
func (kp *kubeprobes) handleLiveness(w http.ResponseWriter, _ *http.Request) {