Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable logrotate for Kubernetes configs on CoreOS #3488

Merged

Conversation

julianvmodesto
Copy link
Contributor

Addresses #2710.

Also, remove logrotate crontab because logrotate ships with a systemd timer, logrotate.timer, to run logrotate daily.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 30, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @julianvmodesto. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 30, 2017
@justinsb
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 30, 2017
Copy link
Contributor

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for you

if b.Distribution == distros.DistributionContainerOS {
glog.Infof("Detected ContainerOS; won't install logrotate")
return nil
} else if b.Distribution == distros.DistributionCoreOS {
glog.Infof("Detected CoreOS; won't install logrotate")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we enabling? Confused ... sorry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logrotate is already installed on CoreOS, so we don't need to install the package, only the logrotate conf.

https://github.com/coreos/init/blob/9b0971c8f7f1d634daa399b74f2591cac97f1ede/systemd/system/logrotate.service#L5

https://github.com/coreos/init/blob/9b0971c8f7f1d634daa399b74f2591cac97f1ede/configs/logrotate.conf#L18-L19

Would c.AddTask(&nodetasks.Package{Name: "logrotate"}) be okay to run away on CoreOS?

Copy link
Contributor

@chrislovecnm chrislovecnm Sep 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julianvmodesto you can answer

Would c.AddTask(&nodetasks.Package{Name: "logrotate"}) be okay to run away on CoreOS?

Better than I :) What do you recommend? Test it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - you generally can't run the Package task on CoreOS - it'll complain that it doesn't know the package manager, because it only supports apt & yum.

@justinsb
Copy link
Member

I'll take a look at this - thank you! It looks good, I just need to verify that the rotation is indeed installed on Debian, but it sounds right :-)

@justinsb
Copy link
Member

/retest

was a testing problem, not a PR issue

@justinsb
Copy link
Member

Thanks @julianvmodesto - will be great to get logrotation working on CoreOS!

Can we keep the hourly rotation, i.e. wrap that block in an if !coreOS statement? Because the logs do get big fast, so the recommendation is to rotate them hourly, and I'm pretty sure that in both jessie & stretch it's only configured to rotate daily (e.g. https://packages.debian.org/stretch/amd64/logrotate/filelist and https://stackoverflow.com/questions/25485047/hourly-rotation-of-files-using-logrotate).

I suspect we'll actually want to tweak CoreOS to logrotate more often than daily, but we can see :-) But I don't want to change the existing behaviour for Debian images.

@justinsb justinsb self-assigned this Sep 30, 2017
@julianvmodesto
Copy link
Contributor Author

Done!

Instead of an hourly cron, could we use an houry systemd timer for Jessie and CoreOS, the latter by overriding the existing timer?

https://github.com/coreos/init/blob/9b0971c8f7f1d634daa399b74f2591cac97f1ede/systemd/system/logrotate.timer

e.g.

	// Add timer to run hourly.
	unit := &systemd.Manifest{}
	unit.Set("Unit", "Description", "Hourly Log Rotation")
	unit.Set("Timer", "OnCalendar", "hourly")

	service := &nodetasks.Service{
		Name:       "logrotate.timer",
		Definition: s(unit.Render()),
	}

	service.InitDefaults()

	c.AddTask(service)

@justinsb
Copy link
Member

justinsb commented Oct 9, 2017

/lgtm

thanks @julianvmodesto!

On the idea of moving to the hourly systemd timer, that would be great - we could even trigger it more often if needed than hourly. Want to send a PR? :-)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 9, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 9, 2017
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue.

@k8s-github-robot k8s-github-robot merged commit 7cfa1b7 into kubernetes:master Oct 9, 2017
k8s-github-robot pushed a commit that referenced this pull request Oct 10, 2017
Automatic merge from submit-queue.

Replace logrotate crontab with systemd timer

Related to #2710, minor improvement mentioned in #3488 (comment).

This change replaces the logrotate crontab with a systemd timer. Any existing systemd timer for logrotate will be overridden.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants