diff --git a/internal/pkg/rpaas/k8s.go b/internal/pkg/rpaas/k8s.go index 690bb34af..9c4b696c2 100644 --- a/internal/pkg/rpaas/k8s.go +++ b/internal/pkg/rpaas/k8s.go @@ -1290,9 +1290,8 @@ func (m *k8sRpaasManager) validateFlavors(ctx context.Context, instance *v1alpha return &ValidationError{Msg: fmt.Sprintf("flavor %q can used only in the creation of instance", f)} } - incompatibleFlavor := checkIncompatibleFlavors(flavorObj.Spec.IncompatibleFlavors, flavors) - if incompatibleFlavor != "" { - return &ValidationError{Msg: fmt.Sprintf("flavor %q is incompatible with %q flavor", f, incompatibleFlavor)} + if validationError := checkForIncompatibleFlavors(flavorObj.Spec.IncompatibleFlavors, flavors, f); validationError != nil { + return validationError } } @@ -1326,16 +1325,18 @@ func diffFlavors(existing, updated []string) (added, removed []string) { return } -func checkIncompatibleFlavors(incompatibleFlavors, allFlavors []string) string { +func checkForIncompatibleFlavors(incompatibleFlavors, allFlavors []string, checkedFlavor string) error { if len(incompatibleFlavors) > 0 { for _, incompatibleFlavor := range incompatibleFlavors { if contains(allFlavors, incompatibleFlavor) { - return incompatibleFlavor + return &ValidationError{ + Msg: fmt.Sprintf("flavor %q is incompatible with %q flavor", checkedFlavor, incompatibleFlavor), + } } } } - return "" + return nil } func isBlockTypeAllowed(bt v1alpha1.BlockType) bool {