Aggregate errors
Signed-off-by: Howard Lau <howardlau1999@hotmail.com>
This commit is contained in:
parent
f0d0622b15
commit
9d134da582
|
@ -19,9 +19,10 @@ package v1
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/errors"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
"sigs.k8s.io/controller-runtime/pkg/webhook"
|
||||||
|
@ -57,21 +58,22 @@ var _ webhook.Validator = &Seaweed{}
|
||||||
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
|
||||||
func (r *Seaweed) ValidateCreate() error {
|
func (r *Seaweed) ValidateCreate() error {
|
||||||
seaweedlog.Info("validate create", "name", r.Name)
|
seaweedlog.Info("validate create", "name", r.Name)
|
||||||
|
errs := []error{}
|
||||||
|
|
||||||
// TODO(user): fill in your validation logic upon object creation.
|
// TODO(user): fill in your validation logic upon object creation.
|
||||||
if r.Spec.Master == nil {
|
if r.Spec.Master == nil {
|
||||||
return fmt.Errorf("seaweed[%s/%s] must have master spec", r.Namespace, r.Name)
|
errs = append(errs, fmt.Errorf("seaweed[%s/%s] must have master spec", r.Namespace, r.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Spec.Volume == nil {
|
if r.Spec.Volume == nil {
|
||||||
return fmt.Errorf("seaweed[%s/%s] must have volume spec", r.Namespace, r.Name)
|
errs = append(errs, fmt.Errorf("seaweed[%s/%s] must have volume spec", r.Namespace, r.Name))
|
||||||
|
} else {
|
||||||
|
if r.Spec.Volume.Requests[corev1.ResourceStorage].Equal(resource.MustParse("0")) {
|
||||||
|
errs = append(errs, fmt.Errorf("seaweed[%s/%s] volume storage request cannot be zero", r.Namespace, r.Name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Spec.Volume.Requests[v1.ResourceStorage].Equal(resource.MustParse("0")) {
|
return errors.NewAggregate(errs)
|
||||||
return fmt.Errorf("seaweed[%s/%s] volume storage request cannot be zero", r.Namespace, r.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
|
||||||
|
|
Loading…
Reference in New Issue