Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Added validation for extra field #481

Merged
merged 2 commits into from
Feb 13, 2018
Merged

Conversation

surajnarwade
Copy link
Collaborator

@surajnarwade surajnarwade commented Nov 22, 2017

For validation purpose, we are using gojsonschema library and json schema for kedge file,
we are downloading from kedgeproject/json-schema

@surajnarwade surajnarwade changed the title Added validation for extra field [WIP]Added validation for extra field Nov 22, 2017
@surajnarwade
Copy link
Collaborator Author

@kadel @cdrage @surajssd @containscafeine can you please try this PR and let me know feedback for further changes

@surajssd
Copy link
Member

For this there are few things we need to figure out @kadel @containscafeine @cdrage need your help here:

So here the validation happens on the external config files a.k.a. jsonschema which is located outside of the project. Now how do we handle/manage those external files. Do we download those files on each invocation of kedge(of course the last thing we wanna do)? Download it locally in home directory and keep it cached, update on every new version of kedge release? Skip validation with warning if the file cannot be downloaded? Need your help here guys!

Copy link
Member

@surajssd surajssd left a comment

Choose a reason for hiding this comment

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

Once we figure out the way to manage these configs, accodingly we can either download them on every request or cache it or put it in code and update it on every release of kedge or something like that!

@kadel
Copy link
Member

kadel commented Nov 22, 2017

So here the validation happens on the external config files a.k.a. jsonschema which is located outside of the project. Now how do we handle/manage those external files. Do we download those files on each invocation of kedge(of course the last thing we wanna do)? Download it locally in home directory and keep it cached, update on every new version of kedge release? Skip validation with warning if the file cannot be downloaded? Need your help here guys!

Those files need to be embedded into Kedge binary, somehow 😏

@kadel
Copy link
Member

kadel commented Nov 22, 2017

we can do something like this:

file: jsonSchemas.go

package jsonSchema

const DeploymentspecmodJson := `{
"$schema": "http://json-schema.org/schema#", 
"required": [
     "containers", 
     "name"
...
...
`

const JobspecModJson := `{
 "$schema": "http://json-schema.org/schema#", 
...
...
`

...
...

@kadel
Copy link
Member

kadel commented Nov 22, 2017

how is Kubernetes doing it?

@surajssd
Copy link
Member

@kadel AFAIK the client downloads the schema from server

@kadel
Copy link
Member

kadel commented Nov 23, 2017

@kadel AFAIK the client downloads the schema from server

ah, right.

Copy link
Collaborator

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

To be honest, having more comments / descriptions on what's happening would benefit when reviewing it 👍 But confused on the validate part!

}
}

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although WIP, entire code here needs to be spaced out more / added comments in order to understand what's happening 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cdrage , added comments now, I hope it will help now

Copy link
Collaborator

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Please check e2e tests / run on your own machine. Something weird is messing up.

@surajnarwade surajnarwade force-pushed the validation branch 2 times, most recently from 5cca0e9 to 32f2613 Compare December 7, 2017 12:40
@surajnarwade surajnarwade force-pushed the validation branch 7 times, most recently from 2d6ff09 to 890443c Compare December 27, 2017 08:48
@kadel
Copy link
Member

kadel commented Jan 2, 2018

can you please add vendor changes as a separate commit?

// validate function will validate input kedgefile against JSON schema provided in pkg/validation
func Validate(p []byte) {
var speco interface{}
err := yaml.Unmarshal(p, &speco)
Copy link
Member

Choose a reason for hiding this comment

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

If we can't avoid this then we need explanation why we are doing it like this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure

@@ -56,6 +56,12 @@ func CreateArtifacts(paths []string, generate bool, args ...string) error {
}

ros, includeResources, err := spec.CoreOperations(kedgeData)

// Validate input kedge file
if !skipValidation {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we move this before CoreOperations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah , that will save much time and operation

@surajnarwade surajnarwade force-pushed the validation branch 3 times, most recently from 9891ce0 to 897e4ea Compare January 10, 2018 06:58
@surajnarwade surajnarwade mentioned this pull request Jan 17, 2018
8 tasks
@kadel
Copy link
Member

kadel commented Jan 18, 2018

#565 was merged, we can now update this accordingly once #566 is merged we can use it as tests for this PR. Tests from #566 should be passing with this PR before we merge this

@surajnarwade surajnarwade force-pushed the validation branch 3 times, most recently from 75518c5 to b4cf7cf Compare January 18, 2018 13:57
@surajnarwade surajnarwade force-pushed the validation branch 2 times, most recently from f865282 to f78c5a4 Compare February 5, 2018 06:16
@surajnarwade surajnarwade changed the title [WIP]Added validation for extra field Added validation for extra field Feb 5, 2018
@surajnarwade
Copy link
Collaborator Author

surajnarwade commented Feb 5, 2018

@kadel , Ready for review :)
Probably works for every case now

Copy link
Collaborator

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Works locally (pulling down the PR and running the binary) against a few examples.

Code LGTM.

Have a few spelling errors / suggestions.

Perhaps the only suggestion is to add a few verbosity logging lines?

loader := gojsonschema.NewGoLoader(body)

var schema gojsonschema.JSONLoader
schema = gojsonschema.NewStringLoader(SchemaJson)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment above this line that we are retrieving SchemaJson from pkg/validation/kedgeschema.go ? Also that it is automatically generated when using make update-schema

Makefile Outdated
.PHONY: update-schema
update-schema:
./scripts/update-schema.sh
#docker run --rm -v `pwd`:/data:Z surajnarwade/update-kedge-schema
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove commented line

cmd/apply.go Outdated
@@ -53,5 +53,6 @@ var applyCmd = &cobra.Command{
func init() {
applyCmd.Flags().StringArrayVarP(&InputFiles, "files", "f", []string{}, "Specify files")
applyCmd.Flags().StringVarP(&Namespace, "namespace", "n", "", "Namespace or project to deploy your application to")
applyCmd.Flags().BoolVar(&SkipValidation, "skip-validation", false, "Skip Validation of input file")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Skip validation of Kedge file may be better..

cmd/create.go Outdated
@@ -53,6 +53,7 @@ func init() {
createCmd.Flags().StringArrayVarP(&InputFiles, "files", "f", []string{}, "Specify files")
createCmd.MarkFlagRequired("files")
createCmd.Flags().StringVarP(&Namespace, "namespace", "n", "", "Namespace or project to deploy your application to")
createCmd.Flags().BoolVar(&SkipValidation, "skip-validation", false, "Skip Validation of input file")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Skip validation of Kedge file

cmd/generate.go Outdated
@@ -43,5 +43,6 @@ var generateCmd = &cobra.Command{
func init() {
generateCmd.Flags().StringArrayVarP(&InputFiles, "files", "f", []string{}, "input files")
generateCmd.MarkFlagRequired("files")
generateCmd.Flags().BoolVar(&SkipValidation, "skip-validation", false, "Skip Validation of input file")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Skip validation of Kedge file

@@ -0,0 +1,42 @@
var fs = require('fs')
Copy link
Member

Choose a reason for hiding this comment

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

javascript? 😞

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it's easy to play with big JSON ;)

Copy link
Member

Choose a reason for hiding this comment

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

It just sucks if you have to run it :-(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thats why I put Docker image for it

Makefile Outdated
# Update schema which is used for json-schema validation
.PHONY: update-schema
update-schema:
docker run --rm -v `pwd`:/data:Z surajnarwade/update-kedge-schema
Copy link
Member

Choose a reason for hiding this comment

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

There is kedge org in docker hub, we should use that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it seems that I don't have access to that org, can someone please add me there

Copy link
Member

Choose a reason for hiding this comment

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

same here :-( @cdrage should have access.

@kadel
Copy link
Member

kadel commented Feb 12, 2018

docker image should be in kedge org in docker hub (https://hub.docker.com/r/kedge), so every kedge maintainer can update it

For validation purpose, we are `gojsonschema` library and json schema for kedge file,
JSON schema are located in `pkg/validation` directory
@surajnarwade
Copy link
Collaborator Author

@kadel @cdrage pushed docker image to new home updated docker image name

@cdrage
Copy link
Collaborator

cdrage commented Feb 13, 2018

@surajnarwade Awesome. That was the last conflict! Going to merge this in, in-time for today's release!

@cdrage cdrage merged commit 81857c6 into kedgeproject:master Feb 13, 2018
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.

4 participants