Skip to content

Commit

Permalink
Fix the wrong field in the api error for provisoner validation (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-zhe-huang authored Feb 10, 2022
1 parent 9df15a2 commit b19740e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions pkg/apis/provisioning/v1alpha5/provisioner_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,21 @@ func (c *Constraints) validateTaints() (errs *apis.FieldError) {
// This function is used by the provisioner validation webhook to verify the provisioner requirements.
// When this function is called, the provisioner's requirments do not include the requirements from labels.
// Provisioner requirements only support well known labels.
func (c *Constraints) validateRequirements() (errors *apis.FieldError) {
var errs error
func (c *Constraints) validateRequirements() (errs *apis.FieldError) {
var err error
for _, requirement := range c.Requirements.Requirements {
// Ensure requirements are well known
if !WellKnownLabels.Has(requirement.Key) {
errs = multierr.Append(errs, fmt.Errorf("key %s is not in wellknown labels %s", requirement.Key, WellKnownLabels.UnsortedList()))
err = multierr.Append(err, fmt.Errorf("key %s is not in well known labels %s", requirement.Key, WellKnownLabels.UnsortedList()))
}
// Ensure requirements operator is allowed
if !SupportedProvisionerOps.Has(string(requirement.Operator)) {
errs = multierr.Append(errs, fmt.Errorf("key %s has an unsupported operator %s, provisioner only supports %s", requirement.Key, requirement.Operator, SupportedProvisionerOps.UnsortedList()))
err = multierr.Append(err, fmt.Errorf("key %s has an unsupported operator %s, provisioner only supports %s", requirement.Key, requirement.Operator, SupportedProvisionerOps.UnsortedList()))
}
}
errs = multierr.Append(errs, c.Requirements.Validate())
if errs != nil {
errors = errors.Also(apis.ErrInvalidValue(errs, "validateRequirements"))
err = multierr.Append(err, c.Requirements.Validate())
if err != nil {
errs = errs.Also(apis.ErrInvalidValue(err, "requirements"))
}
return errors
return errs
}
4 changes: 2 additions & 2 deletions pkg/controllers/provisioning/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (c *Controller) Apply(ctx context.Context, provisioner *v1alpha5.Provisione
provisioner.Spec.Requirements = provisioner.Spec.Requirements.
Add(requirements(instanceTypes)...).
Add(v1alpha5.NewLabelRequirements(provisioner.Spec.Labels).Requirements...)
if errs := provisioner.Spec.Requirements.Validate(); errs != nil {
return fmt.Errorf("incompatible with the instance types, %w", errs)
if err := provisioner.Spec.Requirements.Validate(); err != nil {
return fmt.Errorf("requirements are not compatible with cloud provider, %w", err)
}
// Update the provisioner if anything has changed
if c.hasChanged(ctx, provisioner) {
Expand Down

0 comments on commit b19740e

Please sign in to comment.