Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

--validate: Check server version for minimum version number. #167

Merged
merged 1 commit into from
Apr 4, 2018

Conversation

G-Harmon
Copy link
Contributor

@G-Harmon G-Harmon commented Apr 2, 2018

We need a minimum of v1.8.1 for MCI to work.

This is for Issue #53 .

cc @nikhiljindal


This change is Reviewable

Copy link
Contributor

@nikhiljindal nikhiljindal left a 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.

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")
Copy link
Contributor

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?

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 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.

Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

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 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().

Copy link
Contributor

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()?

Copy link
Contributor Author

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])
Copy link
Contributor

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).

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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 "//"

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@G-Harmon G-Harmon force-pushed the serverVersionRebased branch from 77f68f3 to df669b4 Compare April 3, 2018 21:47
Copy link
Contributor Author

@G-Harmon G-Harmon left a 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) {
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

Copy link
Contributor

@nikhiljindal nikhiljindal left a 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},
Copy link
Contributor

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.
Copy link
Contributor

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) {

Copy link
Contributor

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) {
Copy link
Contributor

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

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")
Copy link
Contributor

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) {
Copy link
Contributor

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()?

@G-Harmon
Copy link
Contributor Author

G-Harmon commented Apr 4, 2018

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…

This never returns an error so no need to include it in method signatures

Done.


app/kubemci/pkg/validations/validations_test.go, line 38 at r1 (raw file):

Previously, nikhiljindal (Nikhil Jindal) wrote…

Add v1.9.3-gke.0 as a test case. Also one without "v". Like 1.2.3

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…

optional: You can link to kubernetes/ingress-gce#182 in case reader is curious

Done.


app/kubemci/pkg/validations/validations_test.go, line 94 at r1 (raw file):

Previously, nikhiljindal (Nikhil Jindal) wrote…

nit: line break not needed

Done.


Comments from Reviewable

@G-Harmon G-Harmon force-pushed the serverVersionRebased branch from df669b4 to 0aa8194 Compare April 4, 2018 07:26
@nikhiljindal
Copy link
Contributor

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…

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.

invalid is fine. i was pointing out that you dont have any case without the v prefix


Comments from Reviewable

We need a minimum of v1.8.1 for MCI to work.
@G-Harmon G-Harmon force-pushed the serverVersionRebased branch from e3c94d5 to e27890b Compare April 4, 2018 17:18
@G-Harmon
Copy link
Contributor Author

G-Harmon commented Apr 4, 2018

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

@nikhiljindal
Copy link
Contributor

/lgtm
thanks!

@G-Harmon G-Harmon merged commit 226be1a into GoogleCloudPlatform:master Apr 4, 2018
@G-Harmon G-Harmon deleted the serverVersionRebased branch April 4, 2018 17:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants