-
Notifications
You must be signed in to change notification settings - Fork 345
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
Autodetect version #479
Conversation
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>
d7cb99d
to
6f64a20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some feedback comments
cmd/sonobuoy/app/gen.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 re naming getClient.
There was a problem hiding this comment.
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.
pkg/config/config.go
Outdated
@@ -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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/const/var
cmd/sonobuoy/app/gen.go
Outdated
|
||
rbacEnabled, err := genflags.rbacMode.Enabled(kubeclient) | ||
if err != nil { | ||
if errors.Cause(err) == ErrRBACNoClient { |
There was a problem hiding this comment.
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.
cmd/sonobuoy/app/gen.go
Outdated
var discoveryClient discovery.ServerVersionInterface | ||
var image string | ||
|
||
if g.kubeConformanceImage != "" { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ughhhhh yeah true
cmd/sonobuoy/app/gen.go
Outdated
if err != nil { | ||
if errors.Cause(err) == ErrImageVersionNoClient { | ||
return nil, errors.Wrap(err, kubeError.Error()) | ||
} else { |
There was a problem hiding this comment.
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
cmd/sonobuoy/app/gen.go
Outdated
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 re naming getClient.
cmd/sonobuoy/app/gen.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
pkg/config/config.go
Outdated
@@ -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" |
There was a problem hiding this comment.
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>
f68fd3b
to
65b48e4
Compare
cmd/sonobuoy/app/gen.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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>
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: