Skip to content

Commit

Permalink
Merge pull request kubernetes#6059 from ripta/coreos-logrotate
Browse files Browse the repository at this point in the history
Set a `dateformat` on logrotate configs on CoreOS
  • Loading branch information
k8s-ci-robot committed Nov 24, 2018
2 parents f139374 + 17ad5af commit 4eeba15
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions nodeup/pkg/model/logrotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,21 @@ func (b *LogrotateBuilder) addLogrotateService(c *fi.ModelBuilderContext) error
}

type logRotateOptions struct {
MaxSize string
MaxSize string
DateFormat string
}

func (b *LogrotateBuilder) addLogRotate(c *fi.ModelBuilderContext, name, path string, options logRotateOptions) {
if options.MaxSize == "" {
options.MaxSize = "100M"
}

// CoreOS sets "dateext" options, and maxsize-based rotation will fail if
// the file has been previously rotated on the same calendar date.
if b.Distribution == distros.DistributionCoreOS {
options.DateFormat = "-%Y%m%d-%s"
}

lines := []string{
path + "{",
" rotate 5",
Expand All @@ -129,12 +136,20 @@ func (b *LogrotateBuilder) addLogRotate(c *fi.ModelBuilderContext, name, path st
" notifempty",
" delaycompress",
" maxsize " + options.MaxSize,
}

if options.DateFormat != "" {
lines = append(lines, " dateformat "+options.DateFormat)
}

lines = append(
lines,
" daily",
" create 0644 root root",
"}",
}
)

contents := strings.Join(lines, "\n")
contents := strings.Join(lines, "\n") + "\n"

c.AddTask(&nodetasks.File{
Path: "/etc/logrotate.d/" + name,
Expand Down

0 comments on commit 4eeba15

Please sign in to comment.