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

fix: fix control plane ref validation #159

Merged
merged 2 commits into from
Nov 18, 2024
Merged

fix: fix control plane ref validation #159

merged 2 commits into from
Nov 18, 2024

Conversation

pmalek
Copy link
Member

@pmalek pmalek commented Nov 15, 2024

What this PR does / why we need it:

This PR:

  • adds the following methods to types that have the cp ref in configuration.konghq.com
    • SetControlPlaneRef(*configurationv1alpha1.ControlPlaneRef)
    • GetControlPlaneRef() *configurationv1alpha1.ControlPlaneRef
  • adds NewCRDValidationTestCasesGroupCPRefChange() which constructs CRDValidationTestCasesGroup in such a way that it generalizes the CRD ref tests
  • fixes several CRD validation rules (which are now covered with tests mentioned above).

Which issue this PR fixes

Fixes #154

@pmalek pmalek self-assigned this Nov 15, 2024
@pmalek pmalek marked this pull request as ready for review November 15, 2024 17:31
@pmalek pmalek requested a review from a team as a code owner November 15, 2024 17:31
@pmalek pmalek added this to the KIC v3.4.x milestone Nov 15, 2024
Copy link
Contributor

@czeslavo czeslavo left a comment

Choose a reason for hiding this comment

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

Thanks for handling this. 🙇 I like the generic approach to testing it.

I only have one concern. Currently, KIC only supports 3 types that have a CP ref in their spec: KongConsumer, KongConsumerGroup and KongVault. It makes sense for them to allow a nil CP reference. But what about the rest of types? Given there's no scenario in which a CP ref being empty for a type not supported by KIC (e.g. KongService, KongUpstream, etc.) would mean anything sensible, shouldn't we require this to be set for them?

@pmalek
Copy link
Member Author

pmalek commented Nov 18, 2024

I only have one concern. Currently, KIC only supports 3 types that have a CP ref in their spec: KongConsumer, KongConsumerGroup and KongVault. It makes sense for them to allow a nil CP reference. But what about the rest of types? Given there's no scenario in which a CP ref being empty for a type not supported by KIC (e.g. KongService, KongUpstream, etc.) would mean anything sensible, shouldn't we require this to be set for them?

Yup, that makes sense as next improvement to types that are not supported by KIC. While these would simply hang and not get reconciled by anything (with the default cp ref of kic) what you're proposing is going to allow faster feedback for users that could possible expect that entities of those types get translated into configuration.

I believe this could be solved by

  • adding a validation rule for spec types for those CRD that are not reconciled by KIC

    // +kubebuilder:validation:XValidation:rule="!has(self.controlPlaneRef) ? true : self.controlPlaneRef.type != 'kic'", message=""
    
  • adding a parameter to NewCRDValidationTestCasesGroupCPRefChange which would disable some tests for those types

  • adding separate test cases for these types to ensure they cannot get cp ref type set to kic

WDYT?

I propose to solve this in a follow up PR as this would unnecessary make this one complex.

@pmalek pmalek enabled auto-merge (squash) November 18, 2024 12:28
@pmalek pmalek merged commit 96347ff into main Nov 18, 2024
7 checks passed
@pmalek pmalek deleted the cp-ref-crdvalidation branch November 18, 2024 12:30
@pmalek
Copy link
Member Author

pmalek commented Nov 18, 2024

@czeslavo The draft PR for the above is at #161.

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.

Cover updates with empty ControlPlane reference
2 participants