-
Notifications
You must be signed in to change notification settings - Fork 40
Conversation
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! |
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.
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!
Those files need to be embedded into Kedge binary, somehow 😏 |
we can do something like this: file: package jsonSchema
const DeploymentspecmodJson := `{
"$schema": "http://json-schema.org/schema#",
"required": [
"containers",
"name"
...
...
`
const JobspecModJson := `{
"$schema": "http://json-schema.org/schema#",
...
...
`
...
... |
how is Kubernetes doing it? |
@kadel AFAIK the client downloads the schema from server |
ah, right. |
491dffc
to
c620d91
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.
To be honest, having more comments / descriptions on what's happening would benefit when reviewing it 👍 But confused on the validate part!
pkg/cmd/commands.go
Outdated
} | ||
} | ||
|
||
} |
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.
Although WIP, entire code here needs to be spaced out more / added comments in order to understand what's happening 👍
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.
okay
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.
@cdrage , added comments now, I hope it will help now
f472232
to
2ee7b40
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.
Please check e2e tests / run on your own machine. Something weird is messing up.
5cca0e9
to
32f2613
Compare
2d6ff09
to
890443c
Compare
890443c
to
8f475fe
Compare
can you please add vendor changes as a separate commit? |
pkg/validation/validation.go
Outdated
// 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) |
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.
If we can't avoid this then we need explanation why we are doing it like 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.
sure
pkg/cmd/commands.go
Outdated
@@ -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 { |
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.
shouldn't we move this before CoreOperations
?
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.
Yeah , that will save much time and operation
9891ce0
to
897e4ea
Compare
75518c5
to
b4cf7cf
Compare
f865282
to
f78c5a4
Compare
@kadel , Ready for review :) |
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.
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?
pkg/validation/validation.go
Outdated
loader := gojsonschema.NewGoLoader(body) | ||
|
||
var schema gojsonschema.JSONLoader | ||
schema = gojsonschema.NewStringLoader(SchemaJson) |
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.
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 |
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.
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") |
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.
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") |
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.
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") |
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.
Skip validation of Kedge file
f78c5a4
to
7db1cb6
Compare
@@ -0,0 +1,42 @@ | |||
var fs = require('fs') |
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.
javascript? 😞
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.
Because it's easy to play with big JSON ;)
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 just sucks if you have to run it :-(
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.
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 |
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.
There is kedge org in docker hub, we should use that.
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 seems that I don't have access to that org, can someone please add me there
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.
same here :-( @cdrage should have access.
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
7db1cb6
to
4c42307
Compare
@surajnarwade Awesome. That was the last conflict! Going to merge this in, in-time for today's release! |
For validation purpose, we are using
gojsonschema
library and json schema for kedge file,we are downloading from
kedgeproject/json-schema