Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

[WIP] feat(bundleinstance): add call to crd validator inside of controller #199

Closed

Conversation

tylerslaton
Copy link
Contributor

Summary

Doing a few things here that we should talk through:

  1. Moving the crd package into its own separate one. Additionally remove its ability to execute a creation/upgrade.
  2. Calling the crd.Validate() function on any incoming CRD's to ensure the upgrade won't cause any destructive actions.
  3. Added a new ReasonUnsafeCRDUpgrade status that gets created on failure to Validate the crd

Working On

This is not complete yet, there are still a few things I'm working through but wanted to get the approach into code review while working through theses:

  1. Adding a label/annotation/spec field that turns this functionality off
  2. Adding a few E2E test cases for this logic

@tylerslaton tylerslaton requested a review from a team as a code owner April 1, 2022 02:09
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 1, 2022
api/v1alpha1/bundleinstance_types.go Show resolved Hide resolved
Comment on lines +172 to +173
err = yaml.Unmarshal(jsonData, &unmarshalledCRD)
if err == nil && unmarshalledCRD.GroupVersionKind() == apiextensionsv1.SchemeGroupVersion.WithKind("CustomResourceDefinition") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type check is a bit awkward -- I'm not sure but since we are unmarshaling to an apiextensionsv1.CustomResourceDefinition concrete type I imagine the GVK for that type will always be the v1 apiextensions GVK regardless of whether the underlying JSON represents a v1 CRD in reality. If it doesn't, then an error occurs (probably some field is not able to be unmarshaled successfully) which doesn't seem to be handled here.

I would recommend as an intermediate step unmarshaling the jsonData into an unstructured.Unstructured object, which has a GroupVersionKind() method. From there we can do the GVK equality check and be more confident that the object we are handling is actually a CRD. It also shouldn't error since we are just converting JSON into another JSON-based type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we can move this check up to L146 to do a obj.GetObjectKind() when we are handling the client.Object directly and handle the CRD from there..it makes the code a bit less clear though.

internal/crd/crd.go Outdated Show resolved Hide resolved
Note: There was some contention around this commit. Ultimately this should not be the end state for CRD Validation. The main sentiment right now is eventually moving toward a ValidatingWebhook that runs agonstic of Rukpak. As that runs, it will check and send back validity to the underlying Helm library

Signed-off-by: Tyler Slaton <tyslaton@redhat.com>
@tylerslaton
Copy link
Contributor Author

Closed in favor of #213

@tylerslaton tylerslaton closed this Apr 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants