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

@The-Loeki
Copy link
Contributor

@The-Loeki The-Loeki 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
Copy link
Contributor Author

@The-Loeki The-Loeki 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
Copy link
Contributor

@rallytime rallytime 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
Copy link
Contributor Author

@The-Loeki The-Loeki 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
Copy link
Collaborator

@terminalmage terminalmage Mar 3, 2018

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.

Copy link
Collaborator

@terminalmage terminalmage 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
Copy link
Collaborator

@terminalmage terminalmage 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 2 commits Mar 3, 2018
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
Copy link
Collaborator

@terminalmage terminalmage 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.

Bugfixes, tweaks, tests for docker.prune
@The-Loeki
Copy link
Contributor Author

@The-Loeki The-Loeki 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
Copy link
Collaborator

@terminalmage terminalmage 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
Copy link
Contributor Author

@The-Loeki The-Loeki 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
Copy link
Collaborator

@terminalmage terminalmage 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
@The-Loeki The-Loeki deleted the docker-prune branch Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants