Skip to content

Commit

Permalink
Ensure conformance image version is prefixed with 'v' (#717)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
johnSchnake authored May 14, 2019
1 parent 770b85b commit affd4fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
5 changes: 4 additions & 1 deletion pkg/image/imageversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func (c *ConformanceImageVersion) Set(str string) error {
if err != nil {
return err
}
*c = ConformanceImageVersion(version.String())

// 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()))
}

return nil
Expand Down
34 changes: 27 additions & 7 deletions pkg/image/imageversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ func TestSetConformanceImageVersion(t *testing.T) {
tests := []struct {
name string
version string
expect string
error bool
}{
{
name: "version detect",
version: "auto",
expect: "auto",
error: false,
},
{
name: "use latest",
version: "latest",
expect: "latest",
error: false,
},
{
Expand All @@ -53,13 +56,26 @@ func TestSetConformanceImageVersion(t *testing.T) {
{
name: "stable version",
version: "v1.13.0",
expect: "v1.13.0",
error: false,
},
{
name: "version without v",
version: "1.13.0",
error: true,
},
{
name: "version without patch",
version: "v1.13",
expect: "v1.13.0",
error: false,
},
{
name: "version without minor/patch",
version: "v1",
expect: "v1.0.0",
error: false,
},
{
name: "empty string",
version: "",
Expand All @@ -68,6 +84,7 @@ func TestSetConformanceImageVersion(t *testing.T) {
{
name: "version with addendum",
version: "v1.13.0-beta.2.78+e0b33dbc2bde88",
expect: "v1.13.0-beta.2.78+e0b33dbc2bde88",
error: false,
},
{
Expand All @@ -77,14 +94,17 @@ func TestSetConformanceImageVersion(t *testing.T) {
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var v ConformanceImageVersion
err := v.Set(test.version)
if test.error && err == nil {
t.Error("expected error, got nil")
} else if !test.error && err != nil {
t.Errorf("expected no error, got %v", err)
err := v.Set(tc.version)
if tc.error && err == nil {
t.Fatal("expected error, got nil")
} else if !tc.error && err != nil {
t.Fatalf("expected no error, got %v", err)
}
if v.String() != tc.expect {
t.Errorf("Expected %q but got %q", tc.expect, v.String())
}
})
}
Expand Down

0 comments on commit affd4fb

Please sign in to comment.