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(environment): Validate against correct patch types #78

Merged

Conversation

MisterMX
Copy link
Contributor

This validates the given environment patch types against the correct types as specified in the API.

Originally, only the *EnvironmentFieldPath types were accepted but the input API definition only defines *CompositeFieldPath patches:

// +kubebuilder:validation:Enum=FromCompositeFieldPath;ToCompositeFieldPath;CombineFromComposite;CombineToComposite

Copy link
Collaborator

@phisco phisco left a comment

Choose a reason for hiding this comment

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

Good catch! 🙏

@negz
Copy link
Member

negz commented Jan 10, 2024

@MisterMX Looks like this needs a small unit test update too.

Using the correct patch types requires changing the order in which xr
and env are passed to ApplyToObjects to the "correct" order (xr, env)
instead of (env, xr). Here env takes over the role of the composed
resource just like in `Apply`.

Signed-off-by: Maximilian Blatt <[email protected]>
@MisterMX MisterMX force-pushed the fix/environment-correct-patches branch from c845d4c to 06869e5 Compare January 11, 2024 11:13
@MisterMX
Copy link
Contributor Author

MisterMX commented Jan 11, 2024

Thanks for the hint. I fixed the tests. To accomplish that I had to make some small changes to the render code:

Using the correct patch types requires changing the order in which xr and env are passed to ApplyToObjects to the "correct" order (xr, env) instead of (env, xr). Here env takes over the role of the composed resource just like in Apply.

Also, the tests were incorrectly assuming the environment data in patches to be under data which is not the case in Crossplane (see https://github.com/crossplane/crossplane/blob/806f0d20d146f6f4f1735c5ec6a7dc78923814b3/internal/controller/apiextensions/composite/environment_fetcher.go#L106). There it is not required to prefix environment patches with data. I changed that and remove the prefix from the tests.

@phisco phisco self-requested a review January 11, 2024 11:22
Copy link
Collaborator

@phisco phisco left a comment

Choose a reason for hiding this comment

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

Thanks again! 🙏

@phisco phisco merged commit 8b8f2a4 into crossplane-contrib:main Jan 11, 2024
6 checks passed
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.

3 participants