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

Allow additional fields when a schema cycle is detected #304

Closed
wants to merge 1 commit into from

Conversation

thedadams
Copy link
Contributor

Previously, when a schema cycle was detected during CRD generation, the generator would return an empty object schema. This is mostly fine because:

  1. Kubernetes doesn't support $ref in their API schemas
  2. Trying to copy the existing schema would result in a stack overflow error when trying to parse the JSON for a CRD object

The only downfall of this approach is that nothing will get saved to etcd for the cycled schema. Meaning that, all fields would be ignored by Kubernetes and nothing would get saved.

Let's say a schema exists like:

type Employee struct {
    metav1.TypeMeta `json:",inline"`
    metav1.ListMeta `json:"metadata,omitempty"`

    Manager Employee `json:"manager"`
}

Then, after generating the corresponding CRD with the existing code, the Manager field will always be empty in etcd.

After this change, the cycle will still be detected in the same way, but the resulting schema will allow additional fields. Kubernetes will skip the validation of fields and the object will get successfully saved to Kubernetes. For the example above, this means that it would be possible to save fields to etcd for the Manager field. These fields would not be validated by Kubernetes, but the JSON decoding would handle it properly and updates to the object will ensure it has the desired fields.

Previously, when a schema cycle was detected during CRD generation, the
generator would return an empty object schema. This is mostly fine
because:
1. Kubernetes doesn't support $ref in their API schemas
2. Trying to copy the existing schema would result in a stack overflow
error when trying to parse the JSON for an object

The only downfall of this approach is that nothing will get saved to
etcd for the cycled schema. Meaning that, all fields would be ignored by
Kubernetes and nothing would get saved.

Let's say a schema exists like:

```go
type Employee struct {
    metav1.TypeMeta `json:",inline"`
    metav1.ListMeta `json:"metadata,omitempty"`

    Manager Employee `json:"manager"`
}
```

Then, after generating the corresponding CRD with the existing code, the
Manager field will always be empty in etcd.

After this change, the cycle will still be detected in the same way, but
the resulting schema will allow additional fields. Kubernetes will skip
the validation of fields and the object will get successfully saved to
Kubernetes. For the example above, this means that it would be possible
to save fields to etcd for the Manager field. These fields would not be
validated by Kubernetes, but the JSON decoding would handle it properly
and updates to the object will ensure it has the desired fields.

Signed-off-by: Donnie Adams <donnie@acorn.io>
@thedadams
Copy link
Contributor Author

@rmweir @cbron I am not able to request reviews here, so pinging to get your feedback. Let me know what you think or if you have any issue with this.

@thedadams thedadams closed this Feb 8, 2024
@thedadams thedadams deleted the allow-additional-cycles branch February 8, 2024 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant