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

adds datetime tagger tagpolicy #621

Merged
merged 3 commits into from
May 31, 2018
Merged

adds datetime tagger tagpolicy #621

merged 3 commits into from
May 31, 2018

Conversation

balopat
Copy link
Contributor

@balopat balopat commented May 30, 2018

Fixes #309.

Copy link
Contributor

@r2d4 r2d4 left a comment

Choose a reason for hiding this comment

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

Looks good. One comment about the tag validation and about moving the clock interface into date_time.go

limitations under the License.
*/

package util
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can just live in date_time.go and the tagger package, not sure what else we could use it for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that's where I had it the first time - but then I figured if we'd need time/date related mocking anywhere else, this could serve as a pattern, save some "time". Happy to move it back and do the extraction to util when the second use case actually occurs!

type RealClock struct{}

func (RealClock) Now() time.Time {
return time.Now()
Copy link
Contributor

Choose a reason for hiding this comment

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

Or you could just get rid of this. I don't think we'd have other implementations of the interface or other functions on it, so i think it would be safe to just make it

type dateTimeTagger struct {
	Format   string
	TimeZone string
	timeFn    func()time.Time
}

tagger := dateTimeTagger{timeFn: time.Now}
mockTagger := dateTimeTagger{timeFn: func()time.Time { return test.time } }

Might save a bit of code, but either way SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍
nice! I guess similarly to above, we can introduce the Clock interface later if it's needed (when there are multiple functions there to be mocked).

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

const tagTime = "2006-01-02_15-04-05.999_MST"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a valid image tag? I don't think we do any validation in the code on whether or not the tags we produce are valid according to the image tag spec

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be.

Copy link
Contributor Author

@balopat balopat May 31, 2018

Choose a reason for hiding this comment

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

yeah, this is valid. here's a snippet from a skaffold output for the default format:

...
Build complete in 13.545233439s
gcr.io/***/svc-issues -> gcr.io/***/svc-issues:2018-05-31_11-05-38.609_PDT
gcr.io/***/petclinic-skaffold -> gcr.io/***/petclinic-skaffold:2018-05-31_11-05-38.609_PDT
...

I was thinking about validation, but then the tool fails with a very clear message when tagging fails, for example for

     dateTime:
       format: "2006-01-02_15:04:05"

The colons are not valid, so:

Successfully tagged 345165a2228c4b2f255f5eabcdd5724e:latest
FATA[0000] build step: tagging image: Error parsing reference: "gcr.io/***/svc-issues:2018-05-31_18:03:00" is not a valid repository/tag: invalid reference format 

Copy link
Contributor

Choose a reason for hiding this comment

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

I think as long as the default format is valid its fine

return "", fmt.Errorf("bad timezone provided: \"%s\", error: %s", timezone, err)
}

return opts.ImageName + ":" + c.Now().In(loc).Format(format), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt.Sprintf("%s:%s"

format = tagger.Format
}

timezone := "Local"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: i'd move this down to right before time.LoadLocation, I had to look this up to figure out what it did :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm...it is right before it - is there a more concise way in go to assign "Local as the default value if tagger.TimeZone is not defined"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh disregard, bad comment

@dgageot dgageot merged commit a02d996 into master May 31, 2018
@balopat
Copy link
Contributor Author

balopat commented May 31, 2018

yay!

@r2d4 r2d4 deleted the datetime_tagger branch May 31, 2018 21:36
@tuananh
Copy link
Contributor

tuananh commented Jun 1, 2018

@balopat can you add example usage?

@balopat
Copy link
Contributor Author

balopat commented Jun 1, 2018

@tuananh I'll add an issue for it. I did add the section in annotated-skaffold.yaml - I hope that helps in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants