mirror of
https://github.com/external-secrets/external-secrets.git
synced 2024-12-14 11:57:59 +00:00
[FEATURE] Customizable encoding of logging timestamp (#1808)
Objective of this commit is to allow logs to be more readable. Default log ts encoding in the logger employed (zap) is unix time. This leads to logs not much human-readable. This change introduces the possibility to customize the ts with a set of preconfigured encodings: one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano' Default value does not change Signed-off-by: RiccardoColella <colella.git@outlook.com> Signed-off-by: RiccardoColella <colella.git@outlook.com>
This commit is contained in:
parent
7416a84b2a
commit
131bd617aa
3 changed files with 49 additions and 16 deletions
|
@ -38,12 +38,22 @@ var certcontrollerCmd = &cobra.Command{
|
|||
For more information visit https://external-secrets.io`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var lvl zapcore.Level
|
||||
err := lvl.UnmarshalText([]byte(loglevel))
|
||||
if err != nil {
|
||||
setupLog.Error(err, "error unmarshalling loglevel")
|
||||
var enc zapcore.TimeEncoder
|
||||
lvlErr := lvl.UnmarshalText([]byte(loglevel))
|
||||
if lvlErr != nil {
|
||||
setupLog.Error(lvlErr, "error unmarshalling loglevel")
|
||||
os.Exit(1)
|
||||
}
|
||||
logger := zap.New(zap.Level(lvl))
|
||||
encErr := enc.UnmarshalText([]byte(zapTimeEncoding))
|
||||
if encErr != nil {
|
||||
setupLog.Error(encErr, "error unmarshalling timeEncoding")
|
||||
os.Exit(1)
|
||||
}
|
||||
opts := zap.Options{
|
||||
Level: lvl,
|
||||
TimeEncoder: enc,
|
||||
}
|
||||
logger := zap.New(zap.UseFlagOptions(&opts))
|
||||
ctrl.SetLogger(logger)
|
||||
|
||||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
|
||||
|
@ -121,5 +131,6 @@ func init() {
|
|||
"Enable leader election for controller manager. "+
|
||||
"Enabling this will ensure there is only one active controller manager.")
|
||||
certcontrollerCmd.Flags().StringVar(&loglevel, "loglevel", "info", "loglevel to use, one of: debug, info, warn, error, dpanic, panic, fatal")
|
||||
certcontrollerCmd.Flags().StringVar(&zapTimeEncoding, "zap-time-encoding", "epoch", "Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano')")
|
||||
certcontrollerCmd.Flags().DurationVar(&crdRequeueInterval, "crd-requeue-interval", time.Minute*5, "Time duration between reconciling CRDs for new certs")
|
||||
}
|
||||
|
|
20
cmd/root.go
20
cmd/root.go
|
@ -59,6 +59,7 @@ var (
|
|||
clientQPS float32
|
||||
clientBurst int
|
||||
loglevel string
|
||||
zapTimeEncoding string
|
||||
namespace string
|
||||
enableClusterStoreReconciler bool
|
||||
enableClusterExternalSecretReconciler bool
|
||||
|
@ -96,6 +97,7 @@ var rootCmd = &cobra.Command{
|
|||
Long: `For more information visit https://external-secrets.io`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var lvl zapcore.Level
|
||||
var enc zapcore.TimeEncoder
|
||||
// the client creates a ListWatch for all resource kinds that
|
||||
// are requested with .Get().
|
||||
// We want to avoid to cache all secrets or configmaps in memory.
|
||||
|
@ -109,12 +111,21 @@ var rootCmd = &cobra.Command{
|
|||
if !enableConfigMapsCache {
|
||||
cacheList = append(cacheList, &v1.ConfigMap{})
|
||||
}
|
||||
err := lvl.UnmarshalText([]byte(loglevel))
|
||||
if err != nil {
|
||||
setupLog.Error(err, "error unmarshalling loglevel")
|
||||
lvlErr := lvl.UnmarshalText([]byte(loglevel))
|
||||
if lvlErr != nil {
|
||||
setupLog.Error(lvlErr, "error unmarshalling loglevel")
|
||||
os.Exit(1)
|
||||
}
|
||||
logger := zap.New(zap.Level(lvl))
|
||||
encErr := enc.UnmarshalText([]byte(zapTimeEncoding))
|
||||
if encErr != nil {
|
||||
setupLog.Error(encErr, "error unmarshalling timeEncoding")
|
||||
os.Exit(1)
|
||||
}
|
||||
opts := zap.Options{
|
||||
Level: lvl,
|
||||
TimeEncoder: enc,
|
||||
}
|
||||
logger := zap.New(zap.UseFlagOptions(&opts))
|
||||
ctrl.SetLogger(logger)
|
||||
config := ctrl.GetConfigOrDie()
|
||||
config.QPS = clientQPS
|
||||
|
@ -224,6 +235,7 @@ func init() {
|
|||
rootCmd.Flags().Float32Var(&clientQPS, "client-qps", 0, "QPS configuration to be passed to rest.Client")
|
||||
rootCmd.Flags().IntVar(&clientBurst, "client-burst", 0, "Maximum Burst allowed to be passed to rest.Client")
|
||||
rootCmd.Flags().StringVar(&loglevel, "loglevel", "info", "loglevel to use, one of: debug, info, warn, error, dpanic, panic, fatal")
|
||||
rootCmd.Flags().StringVar(&zapTimeEncoding, "zap-time-encoding", "epoch", "Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano')")
|
||||
rootCmd.Flags().StringVar(&namespace, "namespace", "", "watch external secrets scoped in the provided namespace only. ClusterSecretStore can be used but only work if it doesn't reference resources from other namespaces")
|
||||
rootCmd.Flags().BoolVar(&enableClusterStoreReconciler, "enable-cluster-store-reconciler", true, "Enable cluster store reconciler.")
|
||||
rootCmd.Flags().BoolVar(&enableClusterExternalSecretReconciler, "enable-cluster-external-secret-reconciler", true, "Enable cluster external secret reconciler.")
|
||||
|
|
|
@ -55,22 +55,31 @@ var webhookCmd = &cobra.Command{
|
|||
For more information visit https://external-secrets.io`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var lvl zapcore.Level
|
||||
err := lvl.UnmarshalText([]byte(loglevel))
|
||||
if err != nil {
|
||||
setupLog.Error(err, "error unmarshalling loglevel")
|
||||
os.Exit(1)
|
||||
}
|
||||
var enc zapcore.TimeEncoder
|
||||
c := crds.CertInfo{
|
||||
CertDir: certDir,
|
||||
CertName: "tls.crt",
|
||||
KeyName: "tls.key",
|
||||
CAName: "ca.crt",
|
||||
}
|
||||
|
||||
logger := zap.New(zap.Level(lvl))
|
||||
lvlErr := lvl.UnmarshalText([]byte(loglevel))
|
||||
if lvlErr != nil {
|
||||
setupLog.Error(lvlErr, "error unmarshalling loglevel")
|
||||
os.Exit(1)
|
||||
}
|
||||
encErr := enc.UnmarshalText([]byte(zapTimeEncoding))
|
||||
if encErr != nil {
|
||||
setupLog.Error(encErr, "error unmarshalling timeEncoding")
|
||||
os.Exit(1)
|
||||
}
|
||||
opts := zap.Options{
|
||||
Level: lvl,
|
||||
TimeEncoder: enc,
|
||||
}
|
||||
logger := zap.New(zap.UseFlagOptions(&opts))
|
||||
ctrl.SetLogger(logger)
|
||||
|
||||
err = waitForCerts(c, time.Minute*2)
|
||||
err := waitForCerts(c, time.Minute*2)
|
||||
if err != nil {
|
||||
setupLog.Error(err, "unable to validate certificates")
|
||||
os.Exit(1)
|
||||
|
@ -212,6 +221,7 @@ func init() {
|
|||
webhookCmd.Flags().IntVar(&port, "port", 10250, "Port number that the webhook server will serve.")
|
||||
webhookCmd.Flags().StringVar(&dnsName, "dns-name", "localhost", "DNS name to validate certificates with")
|
||||
webhookCmd.Flags().StringVar(&certDir, "cert-dir", "/tmp/k8s-webhook-server/serving-certs", "path to check for certs")
|
||||
webhookCmd.Flags().StringVar(&zapTimeEncoding, "zap-time-encoding", "epoch", "Zap time encoding (one of 'epoch', 'millis', 'nano', 'iso8601', 'rfc3339' or 'rfc3339nano')")
|
||||
webhookCmd.Flags().StringVar(&loglevel, "loglevel", "info", "loglevel to use, one of: debug, info, warn, error, dpanic, panic, fatal")
|
||||
webhookCmd.Flags().DurationVar(&certCheckInterval, "check-interval", 5*time.Minute, "certificate check interval")
|
||||
webhookCmd.Flags().DurationVar(&certLookaheadInterval, "lookahead-interval", crds.LookaheadInterval, "certificate check interval")
|
||||
|
|
Loading…
Reference in a new issue