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

Autodetect version #479

Merged
merged 4 commits into from
Jul 11, 2018
Merged

Conversation

liztio
Copy link
Contributor

@liztio liztio commented Jul 11, 2018

What this PR does / why we need it:
Sonobuoy will now detect the server's version and try to run the appropriate conformance container

Which issue(s) this PR fixes

Special notes for your reviewer:

Release note:

sonobuoy run automatically detects server version, gen uses latest

--kube-conformance-image-version has several possible arguments:
auto queries the server version and uses that
latest uses the `latest` tag
a literal version (e.g. v1.10.2) always uses that

Signed-off-by: liz <liz@heptio.com>
--kube-conformance-image-version has several options:
auto queries the server version and uses that
latest uses the `latest` tag
a literal version (e.g. v1.10.2) always uses that

Signed-off-by: liz <liz@heptio.com>
Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

some feedback comments

@@ -65,14 +69,46 @@ func (g *genFlags) Config() (*client.GenConfig, error) {
return nil, errors.Wrap(err, "could not retrieve E2E config")
}

kubeclient, kubeError := maybeGetClient(&g.kubecfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

This flow is an unusual go pattern. The name maybeGetClient should be getClient that returns a client and an error, then the error should be checked and handled accordingly, not depend on rbacMode.Enabled handling the nil case.

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 know it's unusual, but there's not much choice. The client is only required in some situtations, so erroring out when the configuration isn't valid is the wrong behaviour. I'm pretty committed to having sonobuoy gen work without access to a cluster, and I don't know any other ways to support this.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 re naming getClient.

Copy link
Contributor

Choose a reason for hiding this comment

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

The logic flow below this can be reduced based on whether there is a client and error below.

@@ -30,7 +30,7 @@ const (
// DefaultNamespace is the namespace where the master and plugin workers will run (but not necessarily the pods created by the plugin workers).
DefaultNamespace = "heptio-sonobuoy"
// DefaultKubeConformanceImage is the URL of the docker image to run for the kube conformance tests.
DefaultKubeConformanceImage = "gcr.io/heptio-images/kube-conformance:latest"
DefaultKubeConformanceImage = "gcr.io/heptio-images/kube-conformance:%s"
Copy link
Contributor

Choose a reason for hiding this comment

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

This default should not change. The default value needs to be valid on its own. If you need a format string you could create one instead of changing the default value.

Copy link
Contributor

Choose a reason for hiding this comment

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

s/const/var


rbacEnabled, err := genflags.rbacMode.Enabled(kubeclient)
if err != nil {
if errors.Cause(err) == ErrRBACNoClient {
Copy link
Contributor

Choose a reason for hiding this comment

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

This type of error checking is a bit fragile and also requires errors to be exported for testing. An alternative approach to consider is defining a behavior on the custom error and then type checking to see if the returned error implements that behavior:

https://golang.org/src/os/error.go#L22

This makes it easy to create an error that implements that behavior without having to do a string comparison.

var discoveryClient discovery.ServerVersionInterface
var image string

if g.kubeConformanceImage != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This part could be at the very top, if kubeConformanceImage is defined, return the config. Otherwise, we can do the client song and dance and then return the config. This would drop the indentation level, be easier to read, and remove some of the error checking here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We also need the client song and dance for RBAC detection.

Copy link
Contributor

Choose a reason for hiding this comment

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

ughhhhh yeah true

if err != nil {
if errors.Cause(err) == ErrImageVersionNoClient {
return nil, errors.Wrap(err, kubeError.Error())
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

drop the else, it's very rarely used in go

@@ -65,14 +69,46 @@ func (g *genFlags) Config() (*client.GenConfig, error) {
return nil, errors.Wrap(err, "could not retrieve E2E config")
}

kubeclient, kubeError := maybeGetClient(&g.kubecfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 re naming getClient.

@@ -65,14 +69,46 @@ func (g *genFlags) Config() (*client.GenConfig, error) {
return nil, errors.Wrap(err, "could not retrieve E2E config")
}

kubeclient, kubeError := maybeGetClient(&g.kubecfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic flow below this can be reduced based on whether there is a client and error below.

@@ -30,7 +30,7 @@ const (
// DefaultNamespace is the namespace where the master and plugin workers will run (but not necessarily the pods created by the plugin workers).
DefaultNamespace = "heptio-sonobuoy"
// DefaultKubeConformanceImage is the URL of the docker image to run for the kube conformance tests.
DefaultKubeConformanceImage = "gcr.io/heptio-images/kube-conformance:latest"
DefaultKubeConformanceImage = "gcr.io/heptio-images/kube-conformance:%s"
Copy link
Contributor

Choose a reason for hiding this comment

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

s/const/var

Signed-off-by: liz <liz@heptio.com>
@@ -65,14 +69,45 @@ func (g *genFlags) Config() (*client.GenConfig, error) {
return nil, errors.Wrap(err, "could not retrieve E2E config")
}

kubeclient, kubeError := getClient(&g.kubecfg)

rbacEnabled, err := genflags.rbacMode.Enabled(kubeclient)
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on the semantics here and open an issue on auto-detection then lgtm.

Copy link
Contributor

@chuckha chuckha left a comment

Choose a reason for hiding this comment

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

changes look good, thanks for opening that cleanup ticket

Signed-off-by: liz <liz@heptio.com>
@timothysc timothysc merged commit 43b287a into vmware-tanzu:master Jul 11, 2018
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.

RFE: Autodetect kubernetes version and set kube-conformance image accordingly
3 participants