Skip to content
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

Updated installation schema with correct dependency schema #2165

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 35 additions & 28 deletions pkg/porter/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package porter

import (
"context"
"fmt"
"io/ioutil"
"testing"

Expand All @@ -23,33 +24,39 @@ func TestPorter_PrintManifestSchema(t *testing.T) {
}

func TestPorter_ValidateManifestSchema(t *testing.T) {
ctx := context.Background()
p := NewTestPorter(t)
defer p.Close()

// Load the default Porter manifest
b, err := ioutil.ReadFile("testdata/porter.yaml")
require.NoError(t, err)

// Load the manifest as a go dump
m := make(map[string]interface{})
err = yaml.Unmarshal(b, &m)
require.NoError(t, err)
manifestLoader := gojsonschema.NewGoLoader(m)

// Load the manifest schema
err = p.PrintManifestSchema(ctx)
require.NoError(t, err, "could not generate schema")
schema := p.TestConfig.TestContext.GetOutput()
schemaLoader := gojsonschema.NewStringLoader(schema)

// Validate the manifest against the schema
fails, err := gojsonschema.Validate(schemaLoader, manifestLoader)
require.NoError(t, err)

assert.Empty(t, fails.Errors(), "expected testdata/porter.yaml to validate against the porter schema")
// Print it pretty like
for _, err := range fails.Errors() {
t.Logf("%s", err)
manifests := []string{"testdata/porter.yaml", "testdata/porter-with-dependencies.yaml"}
for _, m := range manifests {
t.Run(fmt.Sprintf("Manifest %s", m), func(t *testing.T) {

ctx := context.Background()
p := NewTestPorter(t)
defer p.Close()

// Load the default Porter manifest
b, err := ioutil.ReadFile(m)
require.NoError(t, err)

// Load the manifest as a go dump
m := make(map[string]interface{})
err = yaml.Unmarshal(b, &m)
require.NoError(t, err)
manifestLoader := gojsonschema.NewGoLoader(m)

// Load the manifest schema
err = p.PrintManifestSchema(ctx)
require.NoError(t, err, "could not generate schema")
schema := p.TestConfig.TestContext.GetOutput()
schemaLoader := gojsonschema.NewStringLoader(schema)

// Validate the manifest against the schema
fails, err := gojsonschema.Validate(schemaLoader, manifestLoader)
require.NoError(t, err)

assert.Empty(t, fails.Errors(), "expected testdata/porter.yaml to validate against the porter schema")
// Print it pretty like
for _, err := range fails.Errors() {
t.Logf("%s", err)
}
})
}
}
90 changes: 90 additions & 0 deletions pkg/porter/testdata/porter-with-dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
schemaVersion: 1.0.0-alpha.1
name: porter-hello
version: 0.1.0
description: "A bundle with dependencies"
registry: "localhost:5000"

custom:
customKey1: "customValue1"

credentials:
- name: my-first-cred
env: MY_FIRST_CRED
- name: my-second-cred
description: "My second cred"
path: /path/to/my-second-cred

images:
something:
description: "an image"
imageType: "docker"
repository: "getporter/boo"

dependencies:
requires:
- name: some-dep
bundle:
reference: some-repo
version: ">1.0"
parameters:
param1: first-param

parameters:
- name: my-first-param
type: integer
default: 9
env: MY_FIRST_PARAM
applyTo:
- "install"
- name: my-second-param
description: "My second parameter"
type: string
default: spring-music-demo
path: /path/to/my-second-param
sensitive: true

outputs:
- name: my-first-output
type: string
applyTo:
- "install"
- "upgrade"
sensitive: true
- name: my-second-output
description: "My second output"
type: boolean
sensitive: false
- name: kubeconfig
type: file
path: /home/nonroot/.kube/config

mixins:
- exec

install:
- exec:
description: "Install Hello World with custom arguments"
command: echo
arguments:
- "{{ bundle.custom.customKey1 }}"

upgrade:
- exec:
description: "World 2.0"
command: bash
flags:
c: echo World 2.0

zombies:
- exec:
description: "Trigger zombie apocalypse"
command: bash
flags:
c: echo oh noes my brains

uninstall:
- exec:
description: "Uninstall Hello World"
command: bash
flags:
c: echo Goodbye World
25 changes: 21 additions & 4 deletions pkg/porter/testdata/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
},
"type": "array"
},
"bundle": {
"description": "The defintion of a bundle reference",
"properties": {
"reference": {
"description": "The full bundle reference for the dependency in the format REGISTRY/NAME:TAG",
"type": "string"
},
"version": {
"description": "Bundle version contstraint for version matching, see https://github.com/Masterminds/semver/blob/master/README.md#checking-version-constraints",
"type": "string"
}
},
"required": [
"reference"
],
"type": "object"
},
"credential": {
"description": "Credential defines a particular credential, and where it should be placed in the invocation image",
"properties": {
Expand Down Expand Up @@ -72,19 +89,19 @@
"dependency": {
"additionalProperties": false,
"properties": {
"bundle": {
"$ref": "#/definitions/bundle"
},
"name": {
"type": "string"
},
"parameters": {
"type": "object"
},
"reference": {
"type": "string"
}
},
"required": [
"name",
"reference"
"bundle"
],
"type": "object"
},
Expand Down
23 changes: 20 additions & 3 deletions pkg/schema/manifest.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,32 @@
"name": {
"type": "string"
},
"reference": {
"type": "string"
"bundle": {
"$ref": "#/definitions/bundle"
},
"parameters": {
"type": "object"
}
},
"required": [
"name",
"bundle"
],
"type": "object"
},
"bundle": {
"description": "The defintion of a bundle reference",
"properties": {
"reference": {
"description": "The full bundle reference for the dependency in the format REGISTRY/NAME:TAG",
"type": "string"
},
"version": {
"description": "Bundle version contstraint for version matching, see https://github.com/Masterminds/semver/blob/master/README.md#checking-version-constraints",
"type": "string"
}
},
"required": [
"reference"
],
"type": "object"
Expand Down Expand Up @@ -436,4 +453,4 @@
"upgrade",
"uninstall"
]
}
}