Skip to content

Commit

Permalink
BoolString hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Feb 14, 2020
1 parent 745d890 commit 25c9ed0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion kotskinds/apis/kots/v1beta1/helmchart_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ func (h *HelmChartSpec) RenderValues(values map[string]MappedChartValue) ([]stri
}

type OptionalValue struct {
When string `json:"when"`
When string `json:"when"`

// +type ma[string]any
Values map[string]MappedChartValue `json:"values,omitempty"`
}

Expand Down
8 changes: 4 additions & 4 deletions kotskinds/config/crds/kots.io_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
unmarshalling, it produces or consumes the inner type. This
allows you to have, for example, a JSON field that can
accept a booolean string or raw bool.
type: object
type: BoolString
help_text:
type: string
hidden:
Expand All @@ -69,7 +69,7 @@ spec:
the inner type. This allows you to have, for example,
a JSON field that can accept a booolean string or
raw bool.
type: object
type: BoolString
name:
type: string
recommended:
Expand All @@ -83,7 +83,7 @@ spec:
the inner type. This allows you to have, for example,
a JSON field that can accept a booolean string or
raw bool.
type: object
type: BoolString
required:
- name
- title
Expand Down Expand Up @@ -113,7 +113,7 @@ spec:
unmarshalling, it produces or consumes the inner type. This
allows you to have, for example, a JSON field that can
accept a booolean string or raw bool.
type: object
type: BoolString
when:
type: string
write_once:
Expand Down
1 change: 1 addition & 0 deletions kotskinds/multitype/boolstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// +protobuf=true
// +protobuf.options.(gogoproto.goproto_stringer)=false
// +k8s:openapi-gen=true
// +kubebuilder:validation:Type=BoolString
type BoolOrString struct {
Type BoolOrStringType `protobuf:"varbool,1,opt,name=type,casttype=Type" json:"-"`
BoolVal bool `protobuf:"varbool,2,opt,name=boolVal" json:"-"`
Expand Down
7 changes: 6 additions & 1 deletion kotskinds/schemagen/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ func generateSchemaFromCRD(crd []byte, outfile string) error {
}
}

err = ioutil.WriteFile(outfile, b, 0644)
// whoa now
// working around the fact that controller-gen doesn't have tags to generate oneOf schemas, so this is hacky.
// going to work to add an issue there to support and if they accept, this terrible thing can go away
boolStringed := strings.ReplaceAll(string(b), `"type": "BoolString"`, `"oneOf": [{"type": "string"},{"type": "boolean"}]`)

err = ioutil.WriteFile(outfile, []byte(boolStringed), 0644)
if err != nil {
return errors.Wrap(err, "failed to write file")
}
Expand Down
8 changes: 4 additions & 4 deletions kotskinds/schemas/config-kots-v1beta1.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"default": {
"description": "BoolOrString is a type that can hold an bool or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a booolean string or raw bool.",
"type": "object"
"oneOf": [{"type": "string"},{"type": "boolean"}]
},
"help_text": {
"type": "string"
Expand All @@ -68,7 +68,7 @@
"properties": {
"default": {
"description": "BoolOrString is a type that can hold an bool or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a booolean string or raw bool.",
"type": "object"
"oneOf": [{"type": "string"},{"type": "boolean"}]
},
"name": {
"type": "string"
Expand All @@ -81,7 +81,7 @@
},
"value": {
"description": "BoolOrString is a type that can hold an bool or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a booolean string or raw bool.",
"type": "object"
"oneOf": [{"type": "string"},{"type": "boolean"}]
}
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@
},
"value": {
"description": "BoolOrString is a type that can hold an bool or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a booolean string or raw bool.",
"type": "object"
"oneOf": [{"type": "string"},{"type": "boolean"}]
},
"when": {
"type": "string"
Expand Down

0 comments on commit 25c9ed0

Please sign in to comment.