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

feat(environmentConfig): allow setting sourceFieldPath label selector optional #4547

Merged
merged 2 commits into from
Sep 5, 2023

Conversation

phisco
Copy link
Contributor

@phisco phisco commented Aug 30, 2023

Description of your changes

Fixes #3723 .

I have:

  • Read and followed Crossplane's contribution process.
  • Added or updated unit and E2E tests for my change.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR, if necessary.
  • Opened a PR updating the docs, if necessary.

@phisco phisco requested a review from MisterMX August 30, 2023 14:38
@phisco phisco requested review from turkenh and a team as code owners August 30, 2023 14:38
…ctors as optional

Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
@phisco phisco changed the title feat(environmentConfig): allow setting sourceFieldPath for label sele… feat(environmentConfig): allow setting sourceFieldPath label selector optional Aug 30, 2023
@@ -132,7 +135,7 @@ func (s *APIEnvironmentSelector) lookUpConfigs(ctx context.Context, cr resource.
func (s *APIEnvironmentSelector) buildEnvironmentConfigRefFromSelector(cl *v1alpha1.EnvironmentConfigList, selector *v1.EnvironmentSourceSelector) ([]corev1.ObjectReference, error) {
ec := make([]v1alpha1.EnvironmentConfig, 0)

if len(cl.Items) == 0 {
if cl == nil || len(cl.Items) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

should be a regular case to pass nil for cl in this function? lookUpConfig never returns nil, nil so perhaps we should return error instead? Otherwise, could we add selector unit test for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should never happen but I feel it's ok to handle it as if it had 0 items.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it should never happen, then passing nil here might smell like a bug, and failing early would uncover it.

https://en.wikipedia.org/wiki/Design_by_contract

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then let me rephrase: "it can happen and should be handled as if it was an empty list"

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, can you please add selector unit test for that situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had a look at it. Currently there is no way to pass nil there and there are no tests yet specifically targeting buildEnvironmentConfigRefFromSelector. I don't personally see a reason to add a test for it, but feel free to let me know if you feel differently. In Go the length of nil lists and maps is already 0, so I would not be surprised reading this, nor would expect something else from it while using it.

Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
@phisco phisco merged commit b526110 into crossplane:master Sep 5, 2023
15 of 16 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.

Allow ignoring environment config if it does not exists
4 participants