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

Add docker.prune - pruning for Docker subsystems #46176

Merged
merged 6 commits into from Mar 3, 2018

Conversation

Projects
None yet
3 participants
@The-Loeki
Copy link
Contributor

commented Feb 24, 2018

What does this PR do?

Add docker.prune, which is capable of clearing Docker's subsystems of cruft. Which seems necessary, a lot ;)

@rallytime rallytime requested a review from terminalmage Feb 24, 2018

@The-Loeki

This comment has been minimized.

Copy link
Contributor Author

commented Feb 24, 2018

Function prune has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

FOR REALZ ROFLMAO I could explain this function to my Cognitively Complexively Challenged neighbours

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Feb 26, 2018

@The-Loeki Yeah, we need to tweak the rules for the code-climate build. Can you also add some tests for this new function?

@The-Loeki

This comment has been minimized.

Copy link
Contributor Author

commented Feb 26, 2018

Hi, I'm afraid I'm going to have to pass on that one due to time constraints... I will however update the function once I get the same function PR'd in docker-py; that should get rid of the hidden function calls.

After that I'm not even sure what there is to test in this case. That is, I'm assuming Docker does it's testing on the API endpoints, _client_wrapper is tested as well, I'm not parsing / evalling any output, so what's left is to test is the if constructs?

def prune(system=True, containers=False, networks=False, images=False, build=False, volumes=False, **filters):
'''
Prune Docker's various subsystems

This comment has been minimized.

Copy link
@terminalmage

terminalmage Mar 3, 2018

Contributor

Doing a quick sweep of the codebase, these API functions all seem to have been added in docker-py 2.1.0. Can you please add the following here?

    .. note::
        This requires docker-py version 2.1.0 or later.

If pre-2.1.0 docker-py is installed, _client_wrapper() function will handle the API error from the unknown function call, so we won't have a traceback. This is just a bit of extra information that should help users who may be on earlier docker-py releases.

@terminalmage
Copy link
Contributor

left a comment

Actually there are a few things about this which don't actually work at all, it looks like it may not even have been tested since the kwargs argument doesn't exist for these API funcs and trying to run this function on my laptop immediately resulted in a tracecback.

I'm working on some modifications that I can submit against your fork that should clear this up.

@terminalmage

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2018

Another thing I noticed as I look deeper into the docker-py codebase is that negative filters don't seem to be supported. I've opened docker/docker-py#1940 upstream to get clarification.

terminalmage added some commits Mar 3, 2018

Bugfixes, tweaks for docker.prune
The kwargs argument isn't supported and attempting to pass it to the API
will result in API errors. This fixes that bug and makes improvements to
the docstring.

It also changes the behavior of the `system` argument so that it doesn't
need to be manually disabled to prune only containers/images/etc.

Finally, it moves the prune function higher up to fit with the
organizational structure of the module.
@terminalmage

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2018

@The-Loeki Have a look at The-Loeki#1, I made some fixes, changed how system works, and added unit tests.

Merge pull request #1 from terminalmage/pr-46176
Bugfixes, tweaks, tests for docker.prune
@The-Loeki

This comment has been minimized.

Copy link
Contributor Author

commented Mar 3, 2018

@terminalmage thanks for all the help and advice, regarding the older api's: I can probably easily write up the same kind of workarounds for the other prunes?

@terminalmage

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2018

You mean posting directly to the API endpoint? Yeah, that should be doable, and I can also work to get them supported in docker-py. Which other prunes are yet to be supported?

@The-Loeki

This comment has been minimized.

Copy link
Contributor Author

commented Mar 3, 2018

AFAIK just the one I already opened a PR for (https://github.com/docker/docker-py/pull/1925/commits), so that would be purely a backwards compat feature

@terminalmage

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2018

Oh, so you were talking about making backwards-compatibility changes for containers, images, etc? If so, I don't think it's necessary in this PR.

@terminalmage terminalmage merged commit 58afd8f into saltstack:develop Mar 3, 2018

4 of 10 checks passed

jenkins/PR/salt-pr-linode-cent7-py3 Pull Requests » Salt PR - Linode CentOS 7 - PY3 #2816 — ABORTED
Details
codeclimate 3 issues to fix
Details
jenkins/PR/salt-pr-linode-ubuntu14-n Pull Requests » Salt PR - Linode Ubuntu14.04 #20465 — FAILURE
Details
jenkins/PR/salt-pr-rs-cent7-n Pull Requests » Salt PR - RS CentOS 7 #16867 — FAILURE
Details
default Build started sha1 is merged.
Details
jenkins/PR/salt-pr-linode-ubuntu16-py3 Pull Requests » Salt PR - Linode Ubuntu16.04 - PY3 #7381 — RUNNING
Details
WIP ready for review
Details
jenkins/PR/salt-pr-clone Pull Requests » Salt PR - Clone #22870 — SUCCESS
Details
jenkins/PR/salt-pr-docs-n Pull Requests » Salt PR - Docs #15200 — SUCCESS
Details
jenkins/PR/salt-pr-lint-n Pull Requests » Salt PR - Code Lint #19813 — SUCCESS
Details

@The-Loeki The-Loeki deleted the The-Loeki:docker-prune branch Mar 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.