kedgeproject / kedge

Kedge : Simple, Concise & Declarative Kubernetes Applications
Apache License 2.0
298 stars 41 forks source link

generate a json-schema file #45

Closed jstrachan closed 7 years ago

jstrachan commented 7 years ago

it'd be nice to generate a json schema file so we can include support for kapp inside tools like this: https://github.com/gorkem/vscode-k8s/ so that we can get automatic completion and validation in VS Code / Che / Eclipse.

I wonder if we maybe need to add a line like:

kind: App

to make it easier to know what schema to use in the IDE plugin?

jstrachan commented 7 years ago

since the schema is gonna change, I'm hoping we can automate the generation of the schema as part of the build from the source - am sure the kubernetes project does something like this for its swagger stuff?

surajssd commented 7 years ago

For reference:

We need to figure out how do we create a swagger API or openAPI.

pradeepto commented 7 years ago

@surajssd Thanks for recording all the links here. Will be helpful.

@jstrachan I think, we will take this up this sprint in small pieces. This will help PM validation as well.

jstrachan commented 7 years ago

BTW here's the project which we use to generate Java DTOs & JSON Schemas for kubernetes and openshift https://github.com/fabric8io/kubernetes-model - though its Java centric; there's probably an easier way in golang to go straight from the go code -> json schema

surajssd commented 7 years ago

Right now the work is being done in https://github.com/surajssd/kedgeSchema

It can generate the schema but not sure if the schema is complete or correct

surajssd commented 7 years ago

removing the image field

$ cat ./example/db.json 
{
  "name": "database",
  "containers": [
    {
      "name": "db",
      "env": [
        {
          "name": "MYSQL_ROOT_PASSWORD",
          "value": "rootpasswd"
        },
        {
          "name": "MYSQL_PASSWORD",
          "value": "wordpress"
        }
      ],
      "envFrom": [
        {
          "configMapRef": {
            "name": "database"
          }
        }
      ]
    }
  ],
...

trying to validate

$ jsonschema -F "{error.message}" -i ./example/db.json ./configs/appspec.json 
u'image' is a required property

errors out


changing the field type of name

$ cat ./example/db.json 
{
  "name": 1,
  "containers": [
    {
...

errors out as:

$ jsonschema -F "{error.message}" -i ./example/db.json ./configs/appspec.json 
1 is not of type u'string'

The file configs/appspec.json is the schema for kedge if I am not mistaken.

pradeepto commented 7 years ago

@surajssd This is a great start. We should break this issue into multiple issues and have checklist. WDYT?

surajssd commented 7 years ago

@surajssd This is a great start. We should break this issue into multiple issues and have checklist. WDYT?

Yes I think so we can create a checklist to do that

surajssd commented 7 years ago
kadel commented 7 years ago

Find the right place to place this jsonschema generation code

could we create new subcommand for generating current jsonschema? Something like kedge jsonschema that will output json schema to stdout?

Everytime we update anything in spec.go there has to be a parallel update in the base schema.

solved by above ;-)

What K8s version do we base off of?

depends on how we solve https://github.com/kedgeproject/kedge/issues/141 I think that there should be command line option to specify the version.

kedge generate --k8s-version=1.6 and same for kedge jsonschema --k8s-version=1.6

Versioning of the jsonschema

if we have sub command for outputting JSON schema we don't need that.

kadel commented 7 years ago

how will #119 impact Json schema generation?

surajssd commented 7 years ago

@kadel not sure how it will impact the jsonschema I wil need to find that because now we won't have one struct but multiple ones, so can't say anything now!

pradeepto commented 7 years ago

We need to make sure the generated json schema are stored as artifacts some where in the repository. And this file should be generated by CI for every release for now.

surajssd commented 7 years ago

Find the right place to place this jsonschema generation code

Generation code resides in https://github.com/kedgeproject/kedge-jsonschema

Put some explanation of how this generation works

The repo has documentation of how to generate the configs, also the way code works can be understood by reading comments in code

Everytime we update anything in spec.go there has to be a parallel update in the base schema

This needs to be done filed an issue for this one https://github.com/kedgeproject/kedge/issues/280

What K8s version do we base off of?

right now it is based on k8s 1.7 https://github.com/kedgeproject/kedge-jsonschema/blob/master/scripts/k8s-release

Versioning of the jsonschema

this needs to be evaluated

kadel commented 7 years ago

Is there a place where I can find JSON schema for the latest release?

surajssd commented 7 years ago

@kadel here: https://github.com/kedgeproject/json-schema/tree/master/schema