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

Ensure conformance image version is prefixed with 'v' #717

Merged
merged 1 commit into from
May 14, 2019
Merged

Ensure conformance image version is prefixed with 'v' #717

merged 1 commit into from
May 14, 2019

Conversation

johnSchnake
Copy link
Contributor

What this PR does / why we need it:
When using flags to set the kube-conformance-image-version
the Set method ends up stripping the v prefix which it
requires the user to provide.

This causes a problem because the rest of the codebase assumes
the version will start with that prefix due to the fact that that
is how images are tagged (for Sonobuoy, Heptio kube-conformance,
and for upstream conformance images).

This change just adds the prefix back after validating the version
and updates the tests to actually check for the version that
gets persisted.

Which issue(s) this PR fixes
Fixes #716

Special notes for your reviewer:
A simple test:

$ ./sonobuoy gen --kube-conformance-image-version=v1.14.0|grep conform
$ ./sonobuoy gen --kube-conformance-image-version=v1.14.1|grep conform

Both of those should result in images with the tag prefixed with v. In addition, the first should be a heptio image, the latter a google image.

As it stands now, the v prefix is missing and both try to use the Heptio registry due to the missing prefix affecting the comparison.

Release note:

Fixes handling of the --kube-conformance-image-version flag so that the resulting conformance image tag is prefixed with 'v' as expected.

When using flags to set the kube-conformance-image-version
the `Set` method ends up stripping the `v` prefix which it
requires the user to provide.

This causes a problem because the rest of the codebase assumes
the version will start with that prefix due to the fact that that
is how images are tagged (for Sonobuoy, Heptio kube-conformance,
and for upstream conformance images).

This change just adds the prefix back after validating the version
and updates the tests to actually check for the version that
gets persisted.

Fixes #716

Signed-off-by: John Schnake <jschnake@vmware.com>
@johnSchnake johnSchnake requested a review from stevesloka May 13, 2019 17:50
@codecov-io
Copy link

Codecov Report

Merging #717 into master will increase coverage by 0.15%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #717      +/-   ##
==========================================
+ Coverage   39.22%   39.38%   +0.15%     
==========================================
  Files          68       68              
  Lines        3816     3816              
==========================================
+ Hits         1497     1503       +6     
+ Misses       2221     2217       -4     
+ Partials       98       96       -2
Impacted Files Coverage Δ
pkg/image/imageversion.go 82.92% <100%> (+2.43%) ⬆️
pkg/plugin/aggregation/aggregator.go 72.16% <0%> (+5.15%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c76f2f5...cf007ec. Read the comment docs.


// It is important to set the string with the `v` prefix in order
// to be consistent with server version reporting and image tagging norms.
*c = ConformanceImageVersion(fmt.Sprintf("v%v", version.String()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should ConformanceImageVersion return the properly formatted string?

Copy link
Contributor Author

@johnSchnake johnSchnake May 13, 2019

Choose a reason for hiding this comment

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

ConformanceImageVersion isn't a function, it is just casting the string to the type.

If you meant that "should the String() string method on the ConformanceImageVersion type do this formatting, I would argue no. We have a constrained type so if we want validation like this we have to either use custom Get() methods which return the value and an error (more overhead than we need for a flag wrapper) or just do the proper validation on Set.

To put all this logic in the String method would be a bit awkward because we wouldn't be able to handle the error case so we'd just end up having to put the logic in both places. And once we fix it here we don't really have a problem which would make it worth copying the logic to String or a custom Get method in addition to what we have.

(tl;dr; the problem really is with the logic itself and not where we put it)

Copy link
Contributor

@stevesloka stevesloka left a comment

Choose a reason for hiding this comment

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

/lgtm

Just needs a rebase. =)

@johnSchnake johnSchnake merged commit affd4fb into vmware-tanzu:master May 14, 2019
@johnSchnake johnSchnake deleted the imageVersionPrefix branch May 14, 2019 18:36
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.

kube-conformance-image-version flag strips v leading to errors
3 participants