Skip to content

Commit

Permalink
Merge pull request #916 from youhonglian/add-validate-duration
Browse files Browse the repository at this point in the history
add controller-manager parameter validation
  • Loading branch information
karmada-bot authored Nov 5, 2021
2 parents 9f2835d + 17bdefc commit f7a8a5f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cmd/controller-manager/app/options/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,61 @@ func validateSecurePort(opts *Options) []error {
return errs
}

func validateClusterStatusUpdateDuration(opts *Options) []error {
var errs []error

if opts.ClusterStatusUpdateFrequency.Duration <= 0 {
errs = append(errs, fmt.Errorf("--cluster-status-update-frequency %v must be greater than 0. ", opts.ClusterStatusUpdateFrequency.Duration))
}
return errs
}

func validateClusterLeaseDuration(opts *Options) []error {
var errs []error

if opts.ClusterLeaseDuration.Duration <= 0 {
errs = append(errs, fmt.Errorf("--cluster-lease-duration %v must be greater than 0. ", opts.ClusterLeaseDuration.Duration))
}
return errs
}

func validateClusterMonitorPeriod(opts *Options) []error {
var errs []error

if opts.ClusterMonitorPeriod.Duration <= 0 {
errs = append(errs, fmt.Errorf("--cluster-monitor-period %v must be greater than 0. ", opts.ClusterMonitorPeriod.Duration))
}
return errs
}

func validateClusterMonitorGracePeriod(opts *Options) []error {
var errs []error

if opts.ClusterMonitorGracePeriod.Duration <= 0 {
errs = append(errs, fmt.Errorf("--cluster-monitor-grace-period %v must be greater than 0. ", opts.ClusterMonitorGracePeriod.Duration))
}
return errs
}

func validateClusterStartupGracePeriod(opts *Options) []error {
var errs []error

if opts.ClusterStartupGracePeriod.Duration <= 0 {
errs = append(errs, fmt.Errorf("--cluster-startup-grace-period %v must be greater than 0. ", opts.ClusterStartupGracePeriod.Duration))
}
return errs
}

// Validate checks Options and return a slice of found errs.
func (o *Options) Validate() []error {
var errs []error
errs = append(errs, validateSkippedResourceConfig(o)...)
errs = append(errs, validateSecurePort(o)...)
errs = append(errs, validateClusterStatusUpdateDuration(o)...)
errs = append(errs, validateClusterLeaseDuration(o)...)
errs = append(errs, validateClusterMonitorPeriod(o)...)
errs = append(errs, validateClusterMonitorGracePeriod(o)...)
errs = append(errs, validateClusterStartupGracePeriod(o)...)

return errs
}

0 comments on commit f7a8a5f

Please sign in to comment.