-
Notifications
You must be signed in to change notification settings - Fork 212
feat: Add support for (custom) types #498
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
Conversation
This fragment is repeated in the downstream functions. I guess it is a left-over from refactorings.
This adds the `Types` field to the ResourceGraphDefinition CRD. It contains a map of names to type definitions, where the definitions follow the simple schema. The defined types are then loaded into the transformer as predefined types. Appearances in the spec are then properly resolved. An example for usage would be: ``` yaml apiVersion: kro.run/v1alpha1 kind: ResourceGraphDefinition metadata: name: service-entry-dns spec: schema: apiVersion: v1alpha1 kind: ServiceEntryDNS spec: ports: "[]port | required=true" types: port: name: string protocol: string number: integer | required ``` Known issues: Currently there is no support for references of custom types within the definition of a custom type! Fixes kro-run#144
If a simple type was used with the required marker: ``` yaml types: myType: string | required=true description="my description" spec: myValue: myType ``` the required marker was lost, while the description was set properly. This happened as in the applyMarkers method of the transformer the required information is set to the parent. While loading the predefined types this parent is just a shell object, that is later read to fill the list of predefined types and then discarded. Now the information on required types is captured in the `predefinedType` type and then later used to set the parent object required fields when handling predefined types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gfrey! left two tiny comments
// A predefined type is a type that is predefined in the schema. | ||
// It is used to resolve references in the schema, while capturing the fact | ||
// whether the type has the required marker set (this information would | ||
// otherwise be lost in the parsing process). | ||
type predefinedType struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! initially i wasn't sure about this, but i just remembered that required fields always live parent-type-schema-definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed that adding this broke the test for the predefined types. So, I fixed that.
pkg/simpleschema/transform_test.go
Outdated
if err != nil { | ||
t.Fatalf("Failed to load pre-defined types: %v", err) | ||
} | ||
func floatPtr(f float64) *float64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this function isn't used, shall we remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely!
flake.lock
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please exclude nix files from this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have force pushed the commits that contained them. Sorry for that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to see the nix files setup for kro. Would you share it in a gist please ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@barney-s https://gist.github.com/gfrey/2101b155e1d1d9f56517bfd00fa06dcb is what I'm using.
This fragment is repeated in the downstream functions. I guess it is a left-over from refactorings.
This is reported when `gofmt` is run with the `-s` option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, thank you @gfrey !!
Have a top level Q. Instead of this: schema:
types:
Person:
name: string
age: integer
spec:
people: '[]Person | required=true` How does this look like ? schema:
Person:
name: string
age: integer
spec:
people: '[]Person | required=true` ?? |
Another alternative is:
for maps:
|
* Add support for (custom) types This adds the `Types` field to the ResourceGraphDefinition CRD. It contains a map of names to type definitions, where the definitions follow the simple schema. The defined types are then loaded into the transformer as predefined types. Appearances in the spec are then properly resolved. An example for usage would be: ``` yaml apiVersion: kro.run/v1alpha1 kind: ResourceGraphDefinition metadata: name: service-entry-dns spec: schema: apiVersion: v1alpha1 kind: ServiceEntryDNS spec: ports: "[]port | required=true" types: port: name: string protocol: string number: integer | required ``` Known issues: Currently there is no support for references of custom types within the definition of a custom type! Fixes kro-run#144 * Add documentation for (custom) types * Fix (custom) simple types with required marker If a simple type was used with the required marker: ``` yaml types: myType: string | required=true description="my description" spec: myValue: myType ``` the required marker was lost, while the description was set properly. This happened as in the applyMarkers method of the transformer the required information is set to the parent. While loading the predefined types this parent is just a shell object, that is later read to fill the list of predefined types and then discarded. Now the information on required types is captured in the `predefinedType` type and then later used to set the parent object required fields when handling predefined types. * Fix typo in documentation * Remove unused code * Fix and improve test for predefined types * Simplify code
* Add support for (custom) types This adds the `Types` field to the ResourceGraphDefinition CRD. It contains a map of names to type definitions, where the definitions follow the simple schema. The defined types are then loaded into the transformer as predefined types. Appearances in the spec are then properly resolved. An example for usage would be: ``` yaml apiVersion: kro.run/v1alpha1 kind: ResourceGraphDefinition metadata: name: service-entry-dns spec: schema: apiVersion: v1alpha1 kind: ServiceEntryDNS spec: ports: "[]port | required=true" types: port: name: string protocol: string number: integer | required ``` Known issues: Currently there is no support for references of custom types within the definition of a custom type! Fixes kro-run#144 * Add documentation for (custom) types * Fix (custom) simple types with required marker If a simple type was used with the required marker: ``` yaml types: myType: string | required=true description="my description" spec: myValue: myType ``` the required marker was lost, while the description was set properly. This happened as in the applyMarkers method of the transformer the required information is set to the parent. While loading the predefined types this parent is just a shell object, that is later read to fill the list of predefined types and then discarded. Now the information on required types is captured in the `predefinedType` type and then later used to set the parent object required fields when handling predefined types. * Fix typo in documentation * Remove unused code * Fix and improve test for predefined types * Simplify code
* Add support for (custom) types This adds the `Types` field to the ResourceGraphDefinition CRD. It contains a map of names to type definitions, where the definitions follow the simple schema. The defined types are then loaded into the transformer as predefined types. Appearances in the spec are then properly resolved. An example for usage would be: ``` yaml apiVersion: kro.run/v1alpha1 kind: ResourceGraphDefinition metadata: name: service-entry-dns spec: schema: apiVersion: v1alpha1 kind: ServiceEntryDNS spec: ports: "[]port | required=true" types: port: name: string protocol: string number: integer | required ``` Known issues: Currently there is no support for references of custom types within the definition of a custom type! Fixes kro-run#144 * Add documentation for (custom) types * Fix (custom) simple types with required marker If a simple type was used with the required marker: ``` yaml types: myType: string | required=true description="my description" spec: myValue: myType ``` the required marker was lost, while the description was set properly. This happened as in the applyMarkers method of the transformer the required information is set to the parent. While loading the predefined types this parent is just a shell object, that is later read to fill the list of predefined types and then discarded. Now the information on required types is captured in the `predefinedType` type and then later used to set the parent object required fields when handling predefined types. * Fix typo in documentation * Remove unused code * Fix and improve test for predefined types * Simplify code
* Add support for (custom) types This adds the `Types` field to the ResourceGraphDefinition CRD. It contains a map of names to type definitions, where the definitions follow the simple schema. The defined types are then loaded into the transformer as predefined types. Appearances in the spec are then properly resolved. An example for usage would be: ``` yaml apiVersion: kro.run/v1alpha1 kind: ResourceGraphDefinition metadata: name: service-entry-dns spec: schema: apiVersion: v1alpha1 kind: ServiceEntryDNS spec: ports: "[]port | required=true" types: port: name: string protocol: string number: integer | required ``` Known issues: Currently there is no support for references of custom types within the definition of a custom type! Fixes kro-run#144 * Add documentation for (custom) types * Fix (custom) simple types with required marker If a simple type was used with the required marker: ``` yaml types: myType: string | required=true description="my description" spec: myValue: myType ``` the required marker was lost, while the description was set properly. This happened as in the applyMarkers method of the transformer the required information is set to the parent. While loading the predefined types this parent is just a shell object, that is later read to fill the list of predefined types and then discarded. Now the information on required types is captured in the `predefinedType` type and then later used to set the parent object required fields when handling predefined types. * Fix typo in documentation * Remove unused code * Fix and improve test for predefined types * Simplify code
* Add support for (custom) types This adds the `Types` field to the ResourceGraphDefinition CRD. It contains a map of names to type definitions, where the definitions follow the simple schema. The defined types are then loaded into the transformer as predefined types. Appearances in the spec are then properly resolved. An example for usage would be: ``` yaml apiVersion: kro.run/v1alpha1 kind: ResourceGraphDefinition metadata: name: service-entry-dns spec: schema: apiVersion: v1alpha1 kind: ServiceEntryDNS spec: ports: "[]port | required=true" types: port: name: string protocol: string number: integer | required ``` Known issues: Currently there is no support for references of custom types within the definition of a custom type! Fixes kro-run#144 * Add documentation for (custom) types * Fix (custom) simple types with required marker If a simple type was used with the required marker: ``` yaml types: myType: string | required=true description="my description" spec: myValue: myType ``` the required marker was lost, while the description was set properly. This happened as in the applyMarkers method of the transformer the required information is set to the parent. While loading the predefined types this parent is just a shell object, that is later read to fill the list of predefined types and then discarded. Now the information on required types is captured in the `predefinedType` type and then later used to set the parent object required fields when handling predefined types. * Fix typo in documentation * Remove unused code * Fix and improve test for predefined types * Simplify code
* Add support for (custom) types This adds the `Types` field to the ResourceGraphDefinition CRD. It contains a map of names to type definitions, where the definitions follow the simple schema. The defined types are then loaded into the transformer as predefined types. Appearances in the spec are then properly resolved. An example for usage would be: ``` yaml apiVersion: kro.run/v1alpha1 kind: ResourceGraphDefinition metadata: name: service-entry-dns spec: schema: apiVersion: v1alpha1 kind: ServiceEntryDNS spec: ports: "[]port | required=true" types: port: name: string protocol: string number: integer | required ``` Known issues: Currently there is no support for references of custom types within the definition of a custom type! Fixes kro-run#144 * Add documentation for (custom) types * Fix (custom) simple types with required marker If a simple type was used with the required marker: ``` yaml types: myType: string | required=true description="my description" spec: myValue: myType ``` the required marker was lost, while the description was set properly. This happened as in the applyMarkers method of the transformer the required information is set to the parent. While loading the predefined types this parent is just a shell object, that is later read to fill the list of predefined types and then discarded. Now the information on required types is captured in the `predefinedType` type and then later used to set the parent object required fields when handling predefined types. * Fix typo in documentation * Remove unused code * Fix and improve test for predefined types * Simplify code
This is the first implementation that was discussed in the slack channel. The other idea of having the
types
field in thespec
part of the schema, seems to be more complicated to implement.Fixes #144.