Skip to content

Commit

Permalink
refactor: review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
crgisch authored and wpjunior committed Jan 24, 2024
1 parent 6b7192b commit bd559c0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/pkg/rpaas/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bd559c0

Please sign in to comment.