-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add simple validation for BackendConfig using OpenAPI schema generation #272
Add simple validation for BackendConfig using OpenAPI schema generation #272
Conversation
159cd42
to
bd136cc
Compare
pkg/backendconfig/crdvalidation.go
Outdated
*ref = schemaProps.Ref.String() | ||
} | ||
|
||
props = &extensionsobj.JSONSchemaProps{ |
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.
Oh interesting...Didn't expect it will look like this in codes :)
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.
Surprisingly, this is the only way currently to generate the validation spec in code given go structs.
cc46288
to
04df3f5
Compare
limitations under the License. | ||
*/ | ||
|
||
// Note: All credit goes to github.com/ant31/crd-validation for this code. |
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.
A quick comment, should we vendor github.com/ant31/crd-validation instead?
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 rewrote it :)
@@ -41,7 +41,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { | |||
} | |||
} | |||
|
|||
fakePtr := &testing.Fake{} |
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.
BTW we will need to patch 3af3642 everytime when regenerate this client, or go vet
will fail...
I0516 16:21:40.714] # k8s.io/ingress-gce/pkg/backendconfig/client/clientset/versioned/fake
I0516 16:21:40.714] pkg/backendconfig/client/clientset/versioned/fake/clientset_generated.go:56: literal copies lock value from fakePtr: k8s.io/ingress-gce/vendor/k8s.io/client-go/testing.Fake
348227f
to
2fdbed6
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.
Overall LGTM, thanks for the work
cmd/glbc/main.go
Outdated
@@ -34,7 +34,8 @@ import ( | |||
neg "k8s.io/ingress-gce/pkg/neg" | |||
|
|||
"k8s.io/ingress-gce/cmd/glbc/app" | |||
"k8s.io/ingress-gce/pkg/backendconfig" | |||
backendconfig "k8s.io/ingress-gce/pkg/backendconfig" |
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.
Seems to have no effect?
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
pkg/crd/crd.go
Outdated
if meta.typeSource != "" && meta.fn != nil { | ||
validationSpec, err := validation(meta.typeSource, meta.fn) | ||
if err != nil { | ||
glog.V(0).Infof("Error adding simple validation for %v CRD: %v", meta.kind, err) |
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.
glog.Errorf and return crd
?
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.
And maybe remove the word "simple"?
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.
2fdbed6
to
6271766
Compare
6271766
to
51b54d2
Compare
/assign @nicksardo |
Update codegen scripts to include generation of OpenAPI schema for BackendConfig
Use the generated schema to construct a validation spec which is used to initialize the CRD. If everything works right, when a CR is pushed, the validation spec will kick in and make sure the spec is valid based on the types we have defined for the BackendConfig (pkg/apis/backendconfig/v1beta1/types.go).
Refactor the crd code to be more generic by introducing a CRDMeta type which stores all information needed to build a CRD.
FYI: One of the commits is a vendor update and one is a patch to generated code.
/assign @MrHohn