GoogleCloudPlatform / gcr-cleaner

Delete untagged image refs in Google Container Registry or Artifact Registry
Apache License 2.0
805 stars 112 forks source link

cannot unmarshal string into Go struct #10

Closed udAL closed 4 years ago

udAL commented 4 years ago

Hi, I'm sending payload: {"repo":"gcr.io/project/repo","grace":"24h"} And I'm getting: failed to decode payload as JSON: json: cannot unmarshal string into Go struct field Payload.grace of type time.Duration But if I send an integer grace it works as it should.

I don't know golang, but to the best of my knowledge, I think the issue it's you created function UnmarshalJSON to handle different Grace formats (and calling time.ParseDuration) but you never called UnmarshalJSON. Related to GH-7 issue

Anyway, just letting you know. Thanks for the tool

sethvargo commented 4 years ago

Can you make sure you have the most recent version? This has been fixed in a recent release.

udAL commented 4 years ago

Looking at gcr.io/gcr-cleaner/gcr-cleaner looks like the latest tag it's on an older revision image I just tried tag 0.2.0 with a string grace and it works fine. Shouldn't the latest tag be on the last revision? Otherwise it would be good to specify 0.2.0 tag on your instructions

EDIT: Nope, I checked it wrong, it still gives me the same error. Payload (unscaped): {"repo":"eu.gcr.io/project/repo","grace":"1440h"}

EDIT2: Oh ok. Last version is v0.2.1 but I has not been build and/or pushed to gcr.io. Could you please?

Final EDIT: I built master on my own and tested it. It works great with string grace. What's a really confusing behaviour it's that grace has to be negative (it's an Add to the current time). It would be really good to specify it in the README because I didn't expected it and had to try and figure it out. Also great if you could build and push master to gcr.io/gcr-cleaner/gcr-cleaner with latest tag. Thanks

sethvargo commented 4 years ago

Hmm 0.2.0 should not be up there. We don't mirror the git tags. The most recent push is up there now.