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

Add JSON-schema export (KEP-35 part 2) #1727

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ ifeq (, $(shell which go-bindata))
go get github.com/go-bindata/go-bindata/v3/go-bindata@$$(go list -f '{{.Version}}' -m github.com/go-bindata/go-bindata/v3)
endif
go-bindata -pkg crd -o pkg/kudoctl/kudoinit/crd/bindata.go -ignore README.md -nometadata config/crds
go-bindata -pkg convert -o pkg/kudoctl/packages/convert/bindata.go -nometadata config/json-schema
./hack/update_codegen.sh

.PHONY: generate-clean
Expand All @@ -197,7 +198,13 @@ endif
# example: make update-golden
# tests in update==true mode show as failures
update-golden: ## Updates golden files
ifdef _INTELLIJ_FORCE_SET_GOFLAGS
# Run tests from a Goland terminal. Goland already set '-mod=readonly'
go test ./pkg/... --update=true
else
go test ./pkg/... -v -mod=readonly --update=true
endif


.PHONY: todo
# Show to-do items per file.
Expand Down
19 changes: 19 additions & 0 deletions config/crds/kudo.dev_operatorversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ spec:
connectionString:
description: ConnectionString defines a templated string that can be used to connect to an instance of the Operator.
type: string
groups:
items:
properties:
description:
type: string
displayName:
type: string
name:
type: string
prio:
type: integer
type: object
type: array
operator:
description: 'ObjectReference contains enough information to let you inspect or modify the referred object. --- New uses of this type are discouraged because of difficulty describing its usage when embedded in APIs. 1. Ignored fields. It includes many fields which are not generally honored. For instance, ResourceVersion and FieldPath are both very rarely valid in actual usage. 2. Invalid usage help. It is impossible to add specific help for individual usage. In most embedded usages, there are particular restrictions like, "must refer only to types A and B" or "UID not honored" or "name must be restricted". Those cannot be well described when embedded. 3. Inconsistent validation. Because the usages are different, the validation rules are different by usage, which makes it hard for users to predict what will happen. 4. The fields are both imprecise and overly precise. Kind is not a precise mapping to a URL. This can produce ambiguity during interpretation and require a REST mapping. In most cases, the dependency is on the group,resource tuple and the version of the actual struct is irrelevant. 5. We cannot easily change it. Because this type is embedded in many locations, updates to this type will affect numerous schemas. Don''t make new APIs embed an underspecified API type they do not control. Instead of using this type, create a locally provided and used type that is well-focused on your reference. For example, ServiceReferences for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533 .'
properties:
Expand Down Expand Up @@ -66,6 +79,8 @@ spec:
items:
description: Parameter captures the variability of an OperatorVersion being instantiated in an instance.
properties:
advanced:
type: boolean
default:
description: Default is a default value if no parameter is provided by the instance.
type: string
Expand All @@ -80,6 +95,10 @@ spec:
items:
type: string
type: array
group:
type: string
hint:
type: string
immutable:
description: Specifies if the parameter can be changed after the initial installation of the operator
type: boolean
Expand Down
200 changes: 200 additions & 0 deletions config/json-schema/full.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$recursiveAnchor": true,
"$id": "https://kudo.dev/json-schema-full",
"title": "KUDO JSON-Schema",
"type": ["object", "boolean"],
"additionalProperties": false,
"properties": {
"$id": {
"type": "string",
"format": "uri-reference",
"$comment": "Non-empty fragments not allowed.",
"pattern": "^[^#]*#?$"
},
"$schema": {
"type": "string",
"format": "uri"
},
"$anchor": {
"type": "string",
"pattern": "^[A-Za-z][-A-Za-z0-9.:_]*$"
},
"$ref": {
"type": "string",
"format": "uri-reference"
},
"$recursiveRef": {
"type": "string",
"format": "uri-reference"
},
"$recursiveAnchor": {
"type": "boolean",
"default": false
},
"$comment": {
"type": "string"
},
"$defs": {
"type": "object",
"additionalProperties": { "$recursiveRef": "#" },
"default": {}
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"examples": {
"type": "array",
"items": true
},
"default": true,
"multipleOf": {
"type": "number",
"exclusiveMinimum": 0
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "number"
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "number"
},
"maxLength": { "$ref": "#/$defs/nonNegativeInteger" },
"minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
"pattern": {
"type": "string",
"format": "regex"
},
"maxItems": { "$ref": "#/$defs/nonNegativeInteger" },
"minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
"minContains": {
"$ref": "#/$defs/nonNegativeInteger",
"default": 1
},
"maxProperties": { "$ref": "#/$defs/nonNegativeInteger" },
"minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
"required": { "$ref": "#/$defs/stringArray" },
"dependentRequired": {
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/stringArray"
}
},
"const": true,
"enum": {
"type": "array",
"items": true
},
"type": {
"anyOf": [
{ "$ref": "#/$defs/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/$defs/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"additionalItems": { "$recursiveRef": "#" },
"unevaluatedItems": { "$recursiveRef": "#" },
"items": {
"anyOf": [
{ "$recursiveRef": "#" },
{ "$ref": "#/$defs/schemaArray" }
]
},
"contains": { "$recursiveRef": "#" },
"unevaluatedProperties": { "$recursiveRef": "#" },
"properties": {
"type": "object",
"additionalProperties": { "$recursiveRef": "#" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$recursiveRef": "#" },
"propertyNames": { "format": "regex" },
"default": {}
},
"dependentSchemas": {
"type": "object",
"additionalProperties": {
"$recursiveRef": "#"
}
},
"propertyNames": { "$recursiveRef": "#" },
"if": { "$recursiveRef": "#" },
"then": { "$recursiveRef": "#" },
"else": { "$recursiveRef": "#" },
"allOf": { "$ref": "#/$defs/schemaArray" },
"anyOf": { "$ref": "#/$defs/schemaArray" },
"oneOf": { "$ref": "#/$defs/schemaArray" },
"not": { "$recursiveRef": "#" },
"advanced": {
"type": "boolean",
"default": false
},
"hint": {
"type": "string"
},
"listName": {
"type": "string"
},
"trigger": {
"type": "string"
},
"immutable": {
"type": "boolean",
"default": false
},
"priority": {
"type": "integer"
}
},
"$defs": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$recursiveRef": "#" }
},
"nonNegativeInteger": {
"type": "integer",
"minimum": 0
},
"nonNegativeIntegerDefault0": {
"$ref": "#/$defs/nonNegativeInteger",
"default": 0
},
"simpleTypes": {
"enum": [
"array",
"boolean",
"integer",
"null",
"number",
"object",
"string"
]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"uniqueItems": true,
"default": []
}
}
}
130 changes: 130 additions & 0 deletions config/json-schema/limited.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$recursiveAnchor": true,
"$id": "https://kudo.dev/json-schema-limited",
"title": "Limited KUDO JSON-Schema",
"type": ["object", "boolean"],
"additionalProperties": false,
"properties": {
"type": {
"$ref": "#/$defs/simpleTypes"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"properties": {
"additionalProperties": {
"anyOf": [
{ "$ref": "#/$defs/group" },
{ "$ref": "#/$defs/parameter" }
]
}
}
},
"$defs": {
"group": {
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"const": "object"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"priority": {
"type": "integer"
},
"required": { "$ref": "#/$defs/stringArray" },
"properties": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#/$defs/group" },
{ "$ref": "#/$defs/parameter" }
]
},
"default": {}
}
}
},
"parameter": {
"type": "object",
"additionalProperties": false,
"required": [
"type",
"listName"
],
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": true,
"required": { "$ref": "#/$defs/stringArray" },
"enum": {
"type": "array",
"items": true
},
"type": {
"anyOf": [
{ "$ref": "#/$defs/simpleTypes" },
{
"type": "array",
"items": { "$ref": "#/$defs/simpleTypes" },
"minItems": 1,
"uniqueItems": true
}
]
},
"advanced": {
"type": "boolean",
"default": false
},
"hint": {
"type": "string"
},
"listName": {
"type": "string"
},
"trigger": {
"type": "string"
},
"immutable": {
"type": "boolean",
"default": false
}
}
},
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$recursiveRef": "#" }
},
"simpleTypes": {
"enum": [
"array",
"boolean",
"integer",
"null",
"number",
"object",
"string"
]
},
"stringArray": {
"type": "array",
"items": { "type": "string" },
"uniqueItems": true,
"default": []
}
}
}
Loading