Support json logformatter

This commit introduces a new flag '--log-format' that allows a user
to configure json logging on the pods. If the log-format
is not specified, the formatter will default to the existing
text formatter.
This commit is contained in:
Daniel Kvist
2021-10-25 14:38:53 +02:00
parent 2ae0a82510
commit b108aa4d2d
3 changed files with 10 additions and 0 deletions
+1
View File
@@ -115,6 +115,7 @@ Flags:
--slack-username string slack username for reboot notfications (default "kured")
--start-time string schedule reboot only after this time of day (default "0:00")
--time-zone string use this timezone for schedule inputs (default "UTC")
--log-format string log format specified as text or json, defaults to "text"
```
### Reboot Sentinel File & Period
+8
View File
@@ -64,6 +64,7 @@ var (
messageTemplateReboot string
podSelectors []string
rebootCommand string
logFormat string
rebootDays []string
rebootStart string
@@ -164,6 +165,9 @@ func main() {
rootCmd.PersistentFlags().BoolVar(&annotateNodes, "annotate-nodes", false,
"if set, the annotations 'weave.works/kured-reboot-in-progress' and 'weave.works/kured-most-recent-reboot-needed' will be given to nodes undergoing kured reboots")
rootCmd.PersistentFlags().StringVar(&logFormat, "log-format", "text",
"use text or json log format")
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
@@ -623,6 +627,10 @@ func parseRebootCommand(rebootCommand string) []string {
}
func root(cmd *cobra.Command, args []string) {
if logFormat == "json" {
log.SetFormatter(&log.JSONFormatter{})
}
log.Infof("Kubernetes Reboot Daemon: %s", version)
nodeID := os.Getenv("KURED_NODE_ID")
+1
View File
@@ -75,3 +75,4 @@ spec:
# - --time-zone=UTC
# - --annotate-nodes=false
# - --lock-release-delay=30m
# - --log-format=text