Skip to content

Commit

Permalink
mimic velero cli loglevel options (#692)
Browse files Browse the repository at this point in the history
use logrus ParseLevel directly
  • Loading branch information
kaovilai authored May 24, 2022
1 parent b55c71f commit c791b37
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 37 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/oadp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type VeleroConfig struct {
PodConfig *PodConfig `json:"podConfig,omitempty"`
// Velero server’s log level (use debug for the most logging, leave unset for velero default)
// +optional
// +kubebuilder:validation:Enum=error;warn;warning;info;debug;trace
// +kubebuilder:validation:Enum=trace;debug;info;warning;error;fatal;panic
LogLevel string `json:"logLevel,omitempty"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,13 @@ spec:
description: Velero server’s log level (use debug for the
most logging, leave unset for velero default)
enum:
- error
- warn
- warning
- info
- debug
- trace
- debug
- info
- warning
- error
- fatal
- panic
type: string
noDefaultBackupLocation:
description: If you need to install Velero without a default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@ spec:
description: Velero server’s log level (use debug for the
most logging, leave unset for velero default)
enum:
- error
- warn
- warning
- info
- debug
- trace
- debug
- info
- warning
- error
- fatal
- panic
type: string
noDefaultBackupLocation:
description: If you need to install Velero without a default
Expand Down
29 changes: 3 additions & 26 deletions controllers/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ func (r *DPAReconciler) customizeVeleroDeployment(dpa *oadpv1alpha1.DataProtecti
}

if dpa.Spec.Configuration.Velero.LogLevel != "" {
_, err := veleroLogrusParseLevel(dpa.Spec.Configuration.Velero.LogLevel)
logLevel, err := logrus.ParseLevel(dpa.Spec.Configuration.Velero.LogLevel)
if err != nil {
return fmt.Errorf("invalid log level %s\nallowed: %s", dpa.Spec.Configuration.Velero.LogLevel, "error;warn;warning;info;debug;trace")
return fmt.Errorf("invalid log level %s, use: %s", dpa.Spec.Configuration.Velero.LogLevel, "trace, debug, info, warning, error, fatal, or panic")
}
veleroContainer.Args = append(veleroContainer.Args, "--log-level", dpa.Spec.Configuration.Velero.LogLevel)
veleroContainer.Args = append(veleroContainer.Args, "--log-level", logLevel.String())
}

return credentials.AppendPluginSpecificSpecs(dpa, veleroDeployment, veleroContainer, providerNeedsDefaultCreds, hasCloudStorage)
Expand Down Expand Up @@ -768,26 +768,3 @@ func (r DPAReconciler) noDefaultCredentials(dpa oadpv1alpha1.DataProtectionAppli

}

// imported from https://github.com/sirupsen/logrus/blob/v1.8.1/logrus.go#L25-L45
// removes panic and fatal from valid levels.
func veleroLogrusParseLevel(lvl string) (logrus.Level, error) {
switch strings.ToLower(lvl) {
// case "panic":
// return logrus.PanicLevel, nil
// case "fatal":
// return logrus.FatalLevel, nil
case "error":
return logrus.ErrorLevel, nil
case "warn", "warning":
return logrus.WarnLevel, nil
case "info":
return logrus.InfoLevel, nil
case "debug":
return logrus.DebugLevel, nil
case "trace":
return logrus.TraceLevel, nil
}

var l logrus.Level
return l, fmt.Errorf("not a valid logrus Level: %q", lvl)
}

0 comments on commit c791b37

Please sign in to comment.