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

ignore images in used by running containers when GC #57020

Merged
merged 1 commit into from
Jan 10, 2018

Conversation

dixudx
Copy link
Member

@dixudx dixudx commented Dec 11, 2017

What this PR does / why we need it:
Let kubelet not attempt to remove images being used by running containers.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #57006

Special notes for your reviewer:
@kubernetes/sig-node-pr-reviews

Release note:

ignore images in used by running containers when GC

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 11, 2017
@dixudx
Copy link
Member Author

dixudx commented Dec 11, 2017

/unassign @sjpotter
/assign @tallclair

@k8s-ci-robot k8s-ci-robot assigned tallclair and unassigned sjpotter Dec 11, 2017
if isImageUsed(image, imagesInUse) {
glog.V(5).Infof("Image ID %s is being used", image)
continue
}

Choose a reason for hiding this comment

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

what was the impact of this earlier for a running container ? Did this cause the container to be killed if its image was GC'd ? If yes , why was it not detected until now ? Is the kubelet GC feature not enabled by default ?

Copy link
Member Author

@dixudx dixudx Dec 11, 2017

Choose a reason for hiding this comment

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

Did this cause the container to be killed if its image was GC'd? If yes , why was it not detected until now ?

This function is to delete unused images to free some space. No containers will be killed since deleting a image that is referred by a running container is forbid. The containers won't become orphanage.

Is the kubelet GC feature not enabled by default ?

Image GC is enabled by default.

Copy link
Member

Choose a reason for hiding this comment

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

So IIUC, this behavior was previously enforced by the runtime, but now you're making the Kubelet enforce it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@tallclair When kubelet is trying to free space by deleting docker images, images that are used by running containers are not skipped.

Even if we let runtime to handle this, these images should not be deleted.

What I am trying to do here is to skip these in-use images to avoid unnecessary overheads and spam log messages as well.

@@ -448,7 +454,8 @@ func TestGarbageCollectImageNotOldEnough(t *testing.T) {

fakeClock := clock.NewFakeClock(time.Now())
t.Log(fakeClock.Now())
require.NoError(t, manager.detectImages(fakeClock.Now()))
_, err := manager.detectImages(fakeClock.Now())
require.NoError(t, err)

Choose a reason for hiding this comment

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

i dont see any new unit tests added for the case you just fixed ?

Copy link
Member Author

Choose a reason for hiding this comment

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

No more tests are needed, since we've already got TestFreeSpaceImagesInUseContainersAreIgnored. This test does test the function.

What this pr does is to not delete images used by running containers and prevent spam event messages like image is being used by running container.

@dixudx
Copy link
Member Author

dixudx commented Dec 11, 2017

/retest

@dixudx
Copy link
Member Author

dixudx commented Dec 14, 2017

ping @tallclair @vishh PTAL. Thanks.

@dixudx
Copy link
Member Author

dixudx commented Dec 18, 2017

ping @yujuhong PTAL. Thanks.

@@ -385,9 +390,9 @@ func (ev byLastUsedAndDetected) Less(i, j int) bool {
}
}

func isImageUsed(image container.Image, imagesInUse sets.String) bool {
func isImageUsed(imageID string, imagesInUse sets.String) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Why make this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we only need imageID. Also we only got imageID in ImageRecords.

Changing to imageID makes it more convenient for calling.

if isImageUsed(image, imagesInUse) {
glog.V(5).Infof("Image ID %s is being used", image)
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

So IIUC, this behavior was previously enforced by the runtime, but now you're making the Kubelet enforce it?

@dchen1107
Copy link
Member

Nice fix. Thanks! cc/ @dashpole

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dchen1107, dixudx

Associated issue: #57006

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-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 10, 2018
@k8s-github-robot
Copy link

/test all

Tests are more than 96 hours old. Re-running tests.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 57823, 58091, 58093, 58096, 57020). If you want to cherry-pick this change to another branch, please follow the instructions here.

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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImageGCFailed attempting to remove images in use by running containers
7 participants