-
Notifications
You must be signed in to change notification settings - Fork 68
--validate: Check server version for minimum version number. #167
--validate: Check server version for minimum version number. #167
Conversation
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.
Thanks @G-Harmon
Looks great. Main comment is about adding a unit test for the parsing and validating server version logic.
app/kubemci/cmd/create.go
Outdated
if newEnough, err := validations.ServerVersionsNewEnough(clients); err != nil { | ||
return fmt.Errorf("cluster version could not be validated: %s", err) | ||
} else if !newEnough { | ||
return fmt.Errorf("not all cluster versions new enough for kubemci") |
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 should be explicit about what "not new enough" means. Say they should be > 1.8.1 and not 1.10.0?
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 wanted to keep the knowledge of the exact supported versions in a minimum of locations. I've centralized it all in validations.go. That prints
fmt.Println("Cluster", key, "is not running a supported kubernetes version. Need at least 1.8.1.")
I'll the testing and logging about 1.10.0.
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.
hmm. Seems like you can just remove the bool here. If err !=nil, then return that as is.
ServerVersionsNewEnough already returns meaningful error messages.
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.
sure, done.
@@ -89,3 +91,69 @@ func nodePortSameInAllClusters(backend v1beta1.IngressBackend, namespace string, | |||
} | |||
return nil | |||
} | |||
|
|||
func ServerVersionsNewEnough(clients map[string]kubeclient.Interface) (bool, error) { |
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.
Does this have to be public?
Call this from the existing public Validate method?
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 think it needs to be public. validations.Validate is called from loadbalancersyncer.go. ServerVersionsNewEnough is called from create.go. With this setup, we check cluster versions before calling EnsureIngress().
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 should do complete validation first. So validations.Validate() should also be called from create.go before calling EnsureIngress()?
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.
It looks like it works okay to move all the validation code into Validate and calling it earlier in create.go. I'm having a little trouble moving the unit tests over cleanly. (will followup on the unit tests...)
glog.Infof("Checking client %s", key) | ||
discoveryClient := clients[key].Discovery() | ||
if discoveryClient == nil { | ||
return false, fmt.Errorf("no discovery client in client: %+v", clients[key]) |
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.
Also print the cluster name (key).
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.
done.
} | ||
|
||
func serverVersionNewEnough(version string) (bool, error) { | ||
// Example string we're matching: v1.9.3-gke.0 |
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.
FYI thats for GKE clusters. Non GKE clusters will return "v1.9.3", without the gke suffix. We should test both in unit test
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.
most of the tests are without the gke suffix, but i've now added one with "-gke.0"
if patch >= 1 { | ||
return true, nil | ||
} | ||
return false, nil |
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.
Also check !1.10.0? Or you want to do that in a separate PR?
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.
Done. And it was much easier after factoring it out into a "parse version number" function.
} else if major < 1 { | ||
return false, nil | ||
} | ||
//Minor version |
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.
nit: add a space after "//"
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.
done.
return true, nil | ||
} | ||
|
||
func serverVersionNewEnough(version string) (bool, error) { |
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.
Add a unit test for this.
Recommend splitting this into
parseServerVersion() and validateServerVersion() and then you can test both independently.
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.
oops. I wrote a test in validations_test.go, but somehow it got lost before uploading this PR.
77f68f3
to
df669b4
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.
Thanks for the review. PTAL. Now with validations_test.go included :)
return true, nil | ||
} | ||
|
||
func serverVersionNewEnough(version string) (bool, error) { |
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.
oops. I wrote a test in validations_test.go, but somehow it got lost before uploading this PR.
if patch >= 1 { | ||
return true, nil | ||
} | ||
return false, nil |
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.
Done. And it was much easier after factoring it out into a "parse version number" function.
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.
Thanks for the great unit tests!
{"v1.2.3", false, 1, 2, 3}, | ||
{"v10.200.3000", false, 10, 200, 3000}, | ||
{"v0.8.a", true, 0, 0, 0}, | ||
{"v1.-2.3", true, 1, 2, 3}, |
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.
Add v1.9.3-gke.0 as a test case. Also one without "v". Like 1.2.3
{1, 8, 0, false}, | ||
{1, 8, 1, true}, | ||
|
||
// 1.10.0 was buggy and doesn't work. |
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.
optional: You can link to kubernetes/ingress-gce#182 in case reader is curious
} | ||
|
||
func TestVersionsAcrossClusters(t *testing.T) { | ||
|
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.
nit: line break not needed
return true, nil | ||
} | ||
|
||
func serverVersionNewEnough(major, minor, patch uint64) (bool, error) { |
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 never returns an error so no need to include it in method signatures
app/kubemci/cmd/create.go
Outdated
if newEnough, err := validations.ServerVersionsNewEnough(clients); err != nil { | ||
return fmt.Errorf("cluster version could not be validated: %s", err) | ||
} else if !newEnough { | ||
return fmt.Errorf("not all cluster versions new enough for kubemci") |
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.
hmm. Seems like you can just remove the bool here. If err !=nil, then return that as is.
ServerVersionsNewEnough already returns meaningful error messages.
@@ -89,3 +91,69 @@ func nodePortSameInAllClusters(backend v1beta1.IngressBackend, namespace string, | |||
} | |||
return nil | |||
} | |||
|
|||
func ServerVersionsNewEnough(clients map[string]kubeclient.Interface) (bool, error) { |
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 should do complete validation first. So validations.Validate() should also be called from create.go before calling EnsureIngress()?
Review status: 0 of 5 files reviewed at latest revision, 4 unresolved discussions. app/kubemci/pkg/validations/validations.go, line 125 at r1 (raw file): Previously, nikhiljindal (Nikhil Jindal) wrote…
Done. app/kubemci/pkg/validations/validations_test.go, line 38 at r1 (raw file): Previously, nikhiljindal (Nikhil Jindal) wrote…
Are you sure it's valid to not start with "v"? Right now, I'm including that in my regular expression: ^v([0-9]).([0-9]).([0-9]*) Added gke version string. app/kubemci/pkg/validations/validations_test.go, line 79 at r1 (raw file): Previously, nikhiljindal (Nikhil Jindal) wrote…
Done. app/kubemci/pkg/validations/validations_test.go, line 94 at r1 (raw file): Previously, nikhiljindal (Nikhil Jindal) wrote…
Done. Comments from Reviewable |
df669b4
to
0aa8194
Compare
Review status: 0 of 5 files reviewed at latest revision, 4 unresolved discussions. app/kubemci/pkg/validations/validations_test.go, line 38 at r1 (raw file): Previously, G-Harmon wrote…
invalid is fine. i was pointing out that you dont have any case without the v prefix Comments from Reviewable |
da39181
to
e3c94d5
Compare
We need a minimum of v1.8.1 for MCI to work.
e3c94d5
to
e27890b
Compare
PTAL, I think this is ready to merge. I added a TODO to move the NodePort validation out of loadbalancersyncer.go and into create.go |
/lgtm |
We need a minimum of v1.8.1 for MCI to work.
This is for Issue #53 .
cc @nikhiljindal
This change is