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

Support GKE's weird 10+ versions #506

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions cmd/sonobuoy/app/imageversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func (c *ConformanceImageVersion) Set(str string) error {
case ConformanceImageVersionLatest:
*c = ConformanceImageVersionLatest
default:
if err := validateVersion(str); err != nil {
version, err := validateVersion(str)
if err != nil {
return err
}
*c = ConformanceImageVersion(str)
*c = ConformanceImageVersion(version.String())
}

return nil
Expand All @@ -77,19 +78,26 @@ func (c *ConformanceImageVersion) Get(client discovery.ServerVersionInterface) (
return "", errors.Wrap(err, "couldn't retrieve server version")
}

if err := validateVersion(version.GitVersion); err != nil {
parsedVersion, err := validateVersion(version.GitVersion)
if err != nil {
return "", err
}

segments := parsedVersion.Segments()
Copy link
Contributor

Choose a reason for hiding this comment

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

@liztio could you put a comment here to follow up on why GKE diverged on minor version. It's super odd.

if len(segments) < 2 {
return "", fmt.Errorf("version %q only has %d segments, need at least 2", version.GitVersion, len(segments))
}

// NOTE: Until the kube-conformance container is pushed upstream we can't
// guarantee alignment with exact versioning see https://github.com/heptio/kube-conformance/issues/25
// for more details
return fmt.Sprintf("v%s.%s", version.Major, version.Minor), nil
// Use the segments instead of .major and .minor because GKE's .minor is `10+` instead of `10`.
return fmt.Sprintf("v%d.%d", segments[0], segments[1]), nil
}
return string(*c), nil
}

func validateVersion(v string) error {
func validateVersion(v string) (*version.Version, error) {
version, err := version.NewVersion(v)
if err == nil {
if version.Metadata() != "" || version.Prerelease() != "" {
Expand All @@ -98,5 +106,6 @@ func validateVersion(v string) error {
err = errors.New("version must start with v")
}
}
return errors.Wrapf(err, "version %q is invalid", v)

return version, errors.Wrapf(err, "version %q is invalid", v)
}
21 changes: 20 additions & 1 deletion cmd/sonobuoy/app/imageversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func TestSetConformanceImageVersion(t *testing.T) {
version: "v1.11.0-beta.2.78+e0b33dbc2bde88",
error: false,
},
{
name: "version with plus",
version: "v1.10+",
error: true,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -106,6 +111,14 @@ func TestGetConformanceImageVersion(t *testing.T) {
},
}

gkeServerVersion := &fakeServerVersionInterface{
version: version.Info{
Major: "1",
Minor: "10+",
GitVersion: "v1.10.5-gke.3",
},
}

brokenServerVersion := &fakeServerVersionInterface{
err: errors.New("can't connect"),
}
Expand All @@ -131,12 +144,18 @@ func TestGetConformanceImageVersion(t *testing.T) {
error: true,
},
{
name: "beta server version throws error",
name: "beta server version throws warning",
version: "auto",
serverVersion: betaServerVersion,
warning: true,
expected: "v1.11",
},
{
name: "gke server strips plus sign",
version: "auto",
serverVersion: gkeServerVersion,
expected: "v1.10",
},
{
name: "set version ignores server version",
version: "v1.10.2",
Expand Down