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 a library to parse container image name and other fields #2869

Merged
merged 2 commits into from
Apr 9, 2020

Conversation

nader-ziada
Copy link
Contributor

What this PR does / why we need it:

  • Library to parse image name. and other information
  • Function will split the name of the repository in a seperate field

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2850

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 6, 2020
@k8s-ci-robot k8s-ci-robot requested review from detiber and justinsb April 6, 2020 18:58
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 6, 2020
util/container/image.go Outdated Show resolved Hide resolved
util/container/image.go Outdated Show resolved Hide resolved
util/util.go Outdated Show resolved Hide resolved
@vincepri
Copy link
Member

vincepri commented Apr 6, 2020

/milestone v0.3.4

We'll need to follow-up with more PRs to refactor wherever else we use the reference repository directly and use this one instead.

/assign @benmoss
for another review

@k8s-ci-robot k8s-ci-robot added this to the v0.3.4 milestone Apr 6, 2020
@nader-ziada
Copy link
Contributor Author

@vincepri there is only a couple of places using the reference library, I can include them in this PR

util/container/image.go Outdated Show resolved Hide resolved
util/container/image.go Outdated Show resolved Hide resolved
util/container/image_test.go Outdated Show resolved Hide resolved
util/util.go Show resolved Hide resolved
@nader-ziada
Copy link
Contributor Author

/hold

making some more change to this PR to apply the change to other places in the code using these functions

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 6, 2020
util/util.go Show resolved Hide resolved
Copy link

@benmoss benmoss left a comment

Choose a reason for hiding this comment

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

Nits but otherwise looks good

util/container/image.go Outdated Show resolved Hide resolved
util/container/image.go Outdated Show resolved Hide resolved
util/util_test.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 7, 2020
@@ -119,53 +118,20 @@ func (i *imageMeta) Union(other *imageMeta) {

// ApplyToImage changes an image name applying the transformations defined in the current imageMeta.
func (i *imageMeta) ApplyToImage(image string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

cc @fabriziopandini @wfernandes

to make sure we have tests and the logic looks good

Copy link
Contributor

Choose a reason for hiding this comment

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

In imagemeta_client_test.go there were no specific unit tests for ApplyToImage but there were tests for AlterImage which calls out to ApplyImage. That being said I see that a lot of tests were added for ImageFromString. 👍

util/util.go Outdated Show resolved Hide resolved
util/util.go Outdated Show resolved Hide resolved
@nader-ziada
Copy link
Contributor Author

/hold remove

@@ -119,53 +118,20 @@ func (i *imageMeta) Union(other *imageMeta) {

// ApplyToImage changes an image name applying the transformations defined in the current imageMeta.
func (i *imageMeta) ApplyToImage(image string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In imagemeta_client_test.go there were no specific unit tests for ApplyToImage but there were tests for AlterImage which calls out to ApplyImage. That being said I see that a lot of tests were added for ImageFromString. 👍

// ImageFromString parses a docker image string into three parts: repo, tag and digest.
// If both tag and digest are empty, a default image tag will be returned.
func ImageFromString(image string) (Image, error) {
named, err := reference.ParseNamed(image)
Copy link
Contributor

Choose a reason for hiding this comment

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

In the previous implementation, we used reference.ParseNormalizedNamed(image). Is there some essential difference between ParseNormalizedNamed and ParseName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ParseName does more validation

Copy link

Choose a reason for hiding this comment

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

Good catch. ParseNormalizedNamed will allow for "Docker hub"-style names, ala busybox:latest. ParseNamed will error ErrNameNotCanonical on those. I don't know if we want to support images like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found a few cases with checks to make sure we don't get ErrNameNotCanonical so I assumed its better to use ParsedName

Copy link

Choose a reason for hiding this comment

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

I think it's better just that it forces people to be explicit, the Docker default registry nonsense is terrible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, I took the default out

util/container/image_test.go Outdated Show resolved Hide resolved
util/container/image.go Outdated Show resolved Hide resolved
util/container/image_test.go Outdated Show resolved Hide resolved
})
}

func TestModifyImageTag(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like we can add more tests here. WDYT?


// ModifyImageTag takes an imageName (e.g., repository/image:tag), and returns an image name with updated tag
func ModifyImageTag(imageName, tagName string) (string, error) {
normalisedTagName := SemverToOCIImageTag(tagName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be calling ImageTagIsValid in this function? Is any tag validation happening in the reference library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think validation is happening in the reference library

- use func in util pkg instead of exteral docker reference library to simplify the code
@nader-ziada
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 7, 2020
@nader-ziada
Copy link
Contributor Author

/test pull-cluster-api-capd-e2e

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
over to you @benmoss for final lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nader-ziada, vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 8, 2020
@benmoss
Copy link

benmoss commented Apr 9, 2020

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 9, 2020
@k8s-ci-robot k8s-ci-robot merged commit efe6b70 into kubernetes-sigs:master Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a library to work with container images
5 participants