Skip to content

Commit

Permalink
Crd optional (#16)
Browse files Browse the repository at this point in the history
* make CRD generation optional

* change example file
  • Loading branch information
brocwoodworthIBLX authored Oct 29, 2020
1 parent 234c5e1 commit 1d91269
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions example/cr/jsonschema-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: jsonschemas.tagging-v2.infoblox.com
name: jsonschemas.schemaregistry.infoblox.com
spec:
group: tagging-v2.infoblox.com
group: schemaregistry.infoblox.com
versions:
- name: v1
served: true
Expand Down
10 changes: 5 additions & 5 deletions example/cr/jsonschema-pb-cr.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: "tagging-v2.infoblox.com/v1"
apiVersion: "schemaregistry.infoblox.com/v1"
kind: JsonSchema
metadata:
name: {{ .Release.Namespace }}.pb.event
Expand All @@ -7,7 +7,7 @@ spec:
schema: >
{ "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "type": { "enum": [ "ACCOUNT", 0, "SYSTEM", 1, "PRODUCT", 2, "USER", 3 ], "oneOf": [ { "type": "string" }, { "type": "integer" } ] }, "subtype": { "type": "string" }, "account_id": { "type": "string" }, "application_id": { "type": "string" }, "location": { "type": "string" }, "severity": { "type": "string" }, "TTL": { "properties": { "seconds": { "oneOf": [ { "type": "integer" }, { "type": "string" } ], "description": "Signed seconds of the span of time. Must be from -315,576,000,000\n to +315,576,000,000 inclusive. Note: these bounds are computed from:\n 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years" }, "nanos": { "type": "integer", "description": "Signed fractions of a second at nanosecond resolution of the span\n of time. Durations less than one second are represented with a 0\n `seconds` field and a positive or negative `nanos` field. For durations\n of one second or more, a non-zero value for the `nanos` field must be\n of the same sign as the `seconds` field. Must be from -999,999,999\n to +999,999,999 inclusive." } }, "additionalProperties": true, "type": "object" }, "metadata": { "additionalProperties": { "type": "string" }, "type": "object" }, "occurredTime": { "type": "string", "format": "date-time" }, "generatedTime": { "type": "string", "format": "date-time" }, "id": { "type": "string" }, "status": { "enum": [ "RAISED", 0, "CLEARED", 1, "REMINDER", 2 ], "oneOf": [ { "type": "string" }, { "type": "integer" } ] }, "product_name": { "type": "string" } }, "additionalProperties": true, "type": "object"}
---
apiVersion: "tagging-v2.infoblox.com/v1"
apiVersion: "schemaregistry.infoblox.com/v1"
kind: JsonSchema
metadata:
name: {{ .Release.Namespace }}.pb.eventsubtype
Expand All @@ -16,7 +16,7 @@ spec:
schema: >
{ "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "id": { "$ref": "gorm.types.UUIDValue", "additionalProperties": true, "type": "object" }, "name": { "type": "string" }, "product_name": { "properties": { "id": { "$ref": "gorm.types.UUIDValue", "additionalProperties": true, "type": "object" }, "name": { "type": "string" }, "description": { "type": "string" }, "allowed": { "type": "boolean" } }, "additionalProperties": true, "type": "object" }, "event_type": { "properties": { "id": { "$ref": "gorm.types.UUIDValue", "additionalProperties": true, "type": "object" }, "name": { "type": "string" }, "description": { "type": "string" } }, "additionalProperties": true, "type": "object" }, "allowed": { "type": "boolean" }, "description": { "type": "string" } }, "additionalProperties": true, "type": "object", "definitions": { "gorm.types.UUIDValue": { "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "value": { "type": "string" } }, "additionalProperties": true, "type": "object", "id": "gorm.types.UUIDValue" } }}
---
apiVersion: "tagging-v2.infoblox.com/v1"
apiVersion: "schemaregistry.infoblox.com/v1"
kind: JsonSchema
metadata:
name: {{ .Release.Namespace }}.pb.eventtype
Expand All @@ -25,7 +25,7 @@ spec:
schema: >
{ "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "id": { "properties": { "value": { "type": "string" } }, "additionalProperties": true, "type": "object" }, "name": { "type": "string" }, "description": { "type": "string" } }, "additionalProperties": true, "type": "object"}
---
apiVersion: "tagging-v2.infoblox.com/v1"
apiVersion: "schemaregistry.infoblox.com/v1"
kind: JsonSchema
metadata:
name: {{ .Release.Namespace }}.pb.productname
Expand All @@ -34,7 +34,7 @@ spec:
schema: >
{ "$schema": "http://json-schema.org/draft-04/schema#", "properties": { "id": { "properties": { "value": { "type": "string" } }, "additionalProperties": true, "type": "object" }, "name": { "type": "string" }, "description": { "type": "string" }, "allowed": { "type": "boolean" } }, "additionalProperties": true, "type": "object"}
---
apiVersion: "tagging-v2.infoblox.com/v1"
apiVersion: "schemaregistry.infoblox.com/v1"
kind: JsonSchema
metadata:
name: {{ .Release.Namespace }}.pb.summary
Expand Down
10 changes: 7 additions & 3 deletions schema_to_cr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const crd_skeleton = "apiVersion: apiextensions.k8s.io/v1\nkind: CustomResourceD
func main() {
inputSchemaPtr := flag.String("inputschema", "", "The directory containing the schema files. tool will automatically import all schema files within subdirectories (required).")
outputPathPtr := flag.String("outputpath", "", "The path to the directory where the result CRs will go (required).")
groupPtr := flag.String("group", "", "The string of the group for the created crd file (example: notifications.infoblox.com) (required).")
groupPtr := flag.String("group", "", "The string of the group for the created CR and CRD files (example: schemaregistry.infoblox.com) (required).")
makeCrdPtr := flag.Bool("makecrd", false, "Boolean option to choose whether to generate a new CRD file (optional; default false)")

flag.Parse()
if *inputSchemaPtr == "" || *outputPathPtr == "" || *groupPtr == "" {
Expand All @@ -53,7 +54,7 @@ func main() {
}

crOutput := createCrOutput(inputSchema, group)
writeFiles(crOutput, outputPath, group)
writeFiles(crOutput, outputPath, group, *makeCrdPtr)
}

func parseNamespaces(schemaDirectory string) []string {
Expand Down Expand Up @@ -124,7 +125,7 @@ func createCR(inputFilePath, schemaName, group string) string {
return tpl.String()
}

func writeFiles(crOutput map[string]string, outputPath, group string) {
func writeFiles(crOutput map[string]string, outputPath, group string, makeCrd bool) {
for namespace, output := range crOutput {
fo1, err := os.Create(outputPath + "/jsonschema-" + namespace + "-cr.yaml")
if err != nil {
Expand All @@ -136,6 +137,9 @@ func writeFiles(crOutput map[string]string, outputPath, group string) {
fmt.Printf("Error writing to jsonschema-%v-cr.yaml file\r\n", namespace)
}
}
if !makeCrd {
return
}
fo2, err := os.Create(outputPath + "/jsonschema-crd.yaml")
if err != nil {
fmt.Printf("Error creating crd.yaml file\r\n")
Expand Down

0 comments on commit 1d91269

Please sign in to comment.