Skip to content

Commit

Permalink
Refactor validateSriovOperatorConfig
Browse files Browse the repository at this point in the history
Early exit from the function to make the validation
logic more evident and allow further improvements.

Signed-off-by: Andrea Panattoni <[email protected]>
  • Loading branch information
zeeke committed Jun 28, 2023
1 parent e84d536 commit 8ea81c0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ func validateSriovOperatorConfig(cr *sriovnetworkv1.SriovOperatorConfig, operati
glog.V(2).Infof("validateSriovOperatorConfig: %v", cr)
var warnings []string

if cr.GetName() == constants.DefaultConfigName {
if operation == v1.Delete {
return false, warnings, fmt.Errorf("default SriovOperatorConfig shouldn't be deleted")
}
if cr.GetName() != constants.DefaultConfigName {
return false, warnings, fmt.Errorf("only default SriovOperatorConfig is used")
}

if cr.Spec.DisableDrain {
warnings = append(warnings, "Node draining is disabled for applying SriovNetworkNodePolicy, it may result in workload interruption.")
}
return true, warnings, nil
if operation == v1.Delete {
return false, warnings, fmt.Errorf("default SriovOperatorConfig shouldn't be deleted")
}

if cr.Spec.DisableDrain {
warnings = append(warnings, "Node draining is disabled for applying SriovNetworkNodePolicy, it may result in workload interruption.")
}
return false, warnings, fmt.Errorf("only default SriovOperatorConfig is used")

return true, warnings, nil
}

func validateSriovNetworkNodePolicy(cr *sriovnetworkv1.SriovNetworkNodePolicy, operation v1.Operation) (bool, []string, error) {
Expand Down

0 comments on commit 8ea81c0

Please sign in to comment.