Skip to content

Commit

Permalink
Merge pull request #3586 from googs1025/aggregate_err
Browse files Browse the repository at this point in the history
aggregate err when checking options
  • Loading branch information
volcano-sh-bot authored Aug 6, 2024
2 parents 0fa8102 + 12793d3 commit 4607119
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/component-base/config"
componentbaseconfigvalidation "k8s.io/component-base/config/validation"
Expand Down Expand Up @@ -120,14 +121,23 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet, knownControllers []string) {
"'-' to disable controllers, e.g. \"-job-controller,-queue-controller\" to disable job and queue controllers.", knownControllers))
}

// CheckOptionOrDie checks the option and returns error if it's invalid
// CheckOptionOrDie checks all options and returns all errors if they are invalid.
// If there are any invalid options, it aggregates all the errors and returns them.
func (s *ServerOption) CheckOptionOrDie() error {
// check controllers option
var allErrors []error

// Check controllers option
if err := s.checkControllers(); err != nil {
return err
allErrors = append(allErrors, err)
}

// Check leader election flag when LeaderElection is enabled.
leaderElectionErr := componentbaseconfigvalidation.ValidateLeaderElectionConfiguration(
&s.LeaderElection, field.NewPath("leaderElection")).ToAggregate()
if leaderElectionErr != nil {
allErrors = append(allErrors, leaderElectionErr)
}
// check leader election flag when LeaderElection is enabled.
return componentbaseconfigvalidation.ValidateLeaderElectionConfiguration(&s.LeaderElection, field.NewPath("leaderElection")).ToAggregate()
return errors.NewAggregate(allErrors)
}

// checkControllers checks the controllers option and returns error if it's invalid
Expand Down

0 comments on commit 4607119

Please sign in to comment.