Skip to content

[27.x backport] builder: fall back to defaultKeepStorage if keepStorage is unset for GC policy#49137

Merged
thaJeztah merged 1 commit intomoby:27.xfrom
thaJeztah:27.x_backport_builder-gcpolicy-empty-keepbytes
Dec 19, 2024
Merged

[27.x backport] builder: fall back to defaultKeepStorage if keepStorage is unset for GC policy#49137
thaJeztah merged 1 commit intomoby:27.xfrom
thaJeztah:27.x_backport_builder-gcpolicy-empty-keepbytes

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

(cherry picked from commit b08ff81)

- What I did

Builder GC policies without a keepStorage option set should fall back to using the defaultKeepStorage value. But currently, the policy's keepStorage is parsed unconditionally, meaning that if it's unset, an error occurs:

could not get builder GC policy: invalid size: ''

The only way to get a policy to use defaultKeepStorage limit for GC would be to set it to "0".

This patch is to make sure policy keepStorage is conditionally parsed, if set, otherwise the defaultKeepStorage is used.

I also modified related error messages:

could not get builder GC policy: failed to parse defaultKeepStorage: invalid size: 'foo'
could not get builder GC policy: failed to parse keepStorage: invalid size: 'bar'

- How I did it

- How to verify it

Tested manually;

{
        "builder": {
                "gc": {
                        "enabled": true,
                        "defaultKeepStorage": "10GB",
                        "policy": [ { "filter": ["unused-for=2200h"] } ] 
                }
        }
}
$ docker buildx inspect
...
GC Policy rule#0:
 All:            false
 Filters:        
 Keep Duration:  2200h0m0.5074347s
 Reserved Space: 10GiB

- Description for the changelog

- Builder GC policies without a `keepStorage` value now inherit the `defaultKeepStorage` limit as intended.

- A picture of a cute animal (not mandatory but encouraged)

…GC policy

Signed-off-by: David Karlsson <[email protected]>
(cherry picked from commit b08ff81)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah added this to the 27.5.0 milestone Dec 19, 2024
@thaJeztah thaJeztah self-assigned this Dec 19, 2024
@thaJeztah thaJeztah merged commit 09b6837 into moby:27.x Dec 19, 2024
@thaJeztah thaJeztah deleted the 27.x_backport_builder-gcpolicy-empty-keepbytes branch December 19, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants