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

Commit

Permalink
Added validation for extra field (#481)
Browse files Browse the repository at this point in the history
* Updated Vendoring for gojsonschema package

* Added validation for extra field

For validation purpose, we are `gojsonschema` library and json schema for kedge file,
JSON schema are located in `pkg/validation` directory
  • Loading branch information
surajnarwade authored and cdrage committed Feb 13, 2018
1 parent 1f0908a commit 81857c6
Show file tree
Hide file tree
Showing 414 changed files with 42,437 additions and 79 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,8 @@ vendor-update:
.PHONY: test-jsonschema-generation
test-jsonschema-generation:
docker run -v `pwd`/pkg/spec/types.go:/data/types.go:ro,Z surajd/kedgeschema

# Update schema which is used for json-schema validation
.PHONY: update-schema
update-schema:
docker run --rm -v `pwd`:/data:Z kedge/update-kedge-schema
3 changes: 2 additions & 1 deletion cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var applyCmd = &cobra.Command{
command = append(command, "--namespace", Namespace)
}

if err := pkgcmd.CreateArtifacts(InputFiles, false, command...); err != nil {
if err := pkgcmd.CreateArtifacts(InputFiles, false, SkipValidation, command...); err != nil {
fmt.Println(err)
os.Exit(-1)
}
Expand All @@ -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 Kedge file")
RootCmd.AddCommand(applyCmd)
}
3 changes: 2 additions & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var createCmd = &cobra.Command{
command = append(command, "--namespace", Namespace)
}

if err := pkgcmd.CreateArtifacts(InputFiles, false, command...); err != nil {
if err := pkgcmd.CreateArtifacts(InputFiles, false, SkipValidation, command...); err != nil {
fmt.Println(err)
os.Exit(-1)
}
Expand All @@ -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 Kedge file")

RootCmd.AddCommand(createCmd)
}
2 changes: 1 addition & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var deleteCmd = &cobra.Command{
command = append(command, "--namespace", Namespace)
}

if err := pkgcmd.CreateArtifacts(InputFiles, false, command...); err != nil {
if err := pkgcmd.CreateArtifacts(InputFiles, false, SkipValidation, command...); err != nil {
fmt.Println(err)
os.Exit(-1)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var generateCmd = &cobra.Command{
fmt.Println(err)
os.Exit(-1)
}
if err := pkgcmd.CreateArtifacts(InputFiles, true, ""); err != nil {
if err := pkgcmd.CreateArtifacts(InputFiles, true, SkipValidation, ""); err != nil {
fmt.Println(err)
os.Exit(-1)
}
Expand All @@ -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 Kedge file")
RootCmd.AddCommand(generateCmd)
}
5 changes: 3 additions & 2 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import "github.com/pkg/errors"
// so it makes sense to use the common InputFiles variable in both of those
// commands.
var (
InputFiles []string
Namespace string
InputFiles []string
Namespace string
SkipValidation bool
)

func ifFilesPassed(files []string) error {
Expand Down
1 change: 0 additions & 1 deletion docs/examples/all/web.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: web
replicas: 1
deployments:
- replicas: 1
containers:
Expand Down
21 changes: 11 additions & 10 deletions docs/examples/imagestreams/is.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
name: webapp
deploymentConfigss:
deploymentConfigs:
- containers:
- image: ""
triggers:
- imageChangeParams:
automatic: true
containerNames:
- webapp
from:
kind: ImageStreamTag
name: webapp:2.4
type: ImageChange
triggers:
- imageChangeParams:
automatic: true
containerNames:
- webapp
from:
kind: ImageStreamTag
name: webapp:2.4
type: ImageChange
services:
- portMappings:
- "8080"

imageStreams:
- tags:
- from:
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/jobs/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ jobs:
- containers:
- image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
parallelism: 3
restartPolicy: Never
parallelism: 3
31 changes: 15 additions & 16 deletions docs/examples/s2i/configs/application.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: ticker
controller: deploymentconfig

containers:
- image: ""
env:
- name: REDIS_HOST
value: redis

triggers:
- imageChangeParams:
automatic: true
containerNames:
- ticker
from:
kind: ImageStreamTag
name: ticker:latest
type: ImageChange
deploymentConfigs:
- containers:
- image: ""
env:
- name: REDIS_HOST
value: redis
triggers:
- imageChangeParams:
automatic: true
containerNames:
- ticker
from:
kind: ImageStreamTag
name: ticker:latest
type: ImageChange

services:
- portMappings:
Expand Down
8 changes: 5 additions & 3 deletions docs/examples/s2i/configs/redis.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: redis
controller: deploymentconfig
containers:
- image: redis

deploymentConfigs:
- containers:
- image: redis

services:
- portMappings:
- "6379"
71 changes: 35 additions & 36 deletions examples/gitlab/gitlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,44 @@ deployments:
requests:
cpu: 500m
memory: 1Gi

# Environment variables
env:
- name: GITLAB_OMNIBUS_CONFIG
valueFrom:
configMapKeyRef:
name: gitlab
key: gitlab_omnibus_config
- name: GITLAB_ROOT_PASSWORD
- name: EXTERNAL_URL
value: "http://your-domain.com/"
- name: DB_HOST
value: postgresql
- name: DB_USER
valueFrom:
secretKeyRef:
name: gitlab
key: db-user
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: gitlab
key: db-password
- name: DB_DATABASE
value: "gitlab"
- name: REDIS_HOST
value: redis
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: gitlab
key: redis-password
env:
- name: GITLAB_OMNIBUS_CONFIG
valueFrom:
configMapKeyRef:
name: gitlab
key: gitlab_omnibus_config
- name: GITLAB_ROOT_PASSWORD
- name: EXTERNAL_URL
value: "http://your-domain.com/"
- name: DB_HOST
value: postgresql
- name: DB_USER
valueFrom:
secretKeyRef:
name: gitlab
key: db-user
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: gitlab
key: db-password
- name: DB_DATABASE
value: "gitlab"
- name: REDIS_HOST
value: redis
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: gitlab
key: redis-password


volumeMounts:
- name: gitlab-etc
mountPath: /etc/gitlab
- name: gitlab-data
mountPath: /gitlab-data
volumeMounts:
- name: gitlab-etc
mountPath: /etc/gitlab
- name: gitlab-data
mountPath: /gitlab-data


services:
Expand Down
6 changes: 6 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import:
- package: github.com/novln/docker-parser
version: 6030251119d652af8ead44ac7907444227b64d56

- package: github.com/xeipuuv/gojsonschema
version: 212d8a0df7acfab8bdd190a7a69f0ab7376edcc8

# pinning 'golang.org/x/sys' otherwise docker dependencies complain to compiling
- package: golang.org/x/sys
version: 8d1157a435470616f975ff9bb013bea8d0962067
Expand Down
10 changes: 8 additions & 2 deletions pkg/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/kedgeproject/kedge/pkg/spec"
"github.com/kedgeproject/kedge/pkg/validation"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
)

// GenerateArtifacts either writes to file or uses kubectl/oc to deploy.
// TODO: Refactor into two separate functions (remove `generate bool`).
func CreateArtifacts(paths []string, generate bool, args ...string) error {

func CreateArtifacts(paths []string, generate bool, skipValidation bool, args ...string) error {
files, err := GetAllYAMLFiles(paths)
if err != nil {
return errors.Wrap(err, "unable to get YAML files")
Expand All @@ -55,7 +55,13 @@ func CreateArtifacts(paths []string, generate bool, args ...string) error {
return errors.Wrap(err, "failed to replace variables")
}

// Validate input kedge file
if !skipValidation {
validation.Validate(kedgeData)
}

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

if err != nil {
return errors.Wrap(err, "unable to perform controller operations")
}
Expand Down
Loading

0 comments on commit 81857c6

Please sign in to comment.