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

Add warning log when duplicate key is detected in environment config merge #5583

Open
jaylevin opened this issue Apr 16, 2024 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@jaylevin
Copy link

jaylevin commented Apr 16, 2024

What problem are you facing?

When using an environment config selector with mode: Multiple it’s possible for two environment configs to be selected that contain the same key with different values. When the environment configs are merged, one of the values ends up being overwritten with no warning log/event emitted.

I think it would be useful to composition developers/platform engineers to see some sort of warning when duplicate keys are merged into one map when using mode: Multiple environmentconfig selector.

How could Crossplane help solve your problem?

Add a warning log/event when duplicate keys are found during environmentconfig merge for mode: Multiple.

@jaylevin jaylevin added the enhancement New feature or request label Apr 16, 2024
@phisco
Copy link
Contributor

phisco commented Apr 16, 2024

That's by design, selected EnvironmentConfigs are meant to be merged in the order they were specified, if access to all EnvironmentConfigs is needed please look at https://github.com/crossplane-contrib/function-extra-resources

@jaylevin
Copy link
Author

jaylevin commented Apr 16, 2024

@phisco Hmmm, I might be missing something here -- but this issue isn't really concerned with the order in which the env configs are merged.

This issue is geared towards emitting an error/warning message when a composition selects multiple EnvironmentConfigs via a label, and those env configs have duplicate keys. Since it's a single label selector, there's no way to define the order of the env configs that match the label selector.

If two env configs that contain the same key (but different value) are being merged (via a single label selector), Crossplane will silently merge the maps and overwrite the previous key's value with the key value in the map being merged. This could cause undesired behavior if the platform engineer / composition developer is not aware of it. A simple warning/event would help reduce the possibility of this undesired behavior going unnoticed.

For example:

Imagine a platform team has developed a composition with this env config selector:

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: example-composition
spec:
  environment:
    environmentConfigs:
    - type: Selector
      selector:
        mode: Multiple
        minMatch: 1
        matchLabels:
          - key: my-label-key
            type: Value
            value: my-label-value

Now, imagine there are two env configs with label my-label-key: my-label-value. Both env configs have a key named data, but have differing values.

eg:

apiVersion: apiextensions.crossplane.io/v1alpha1
kind: EnvironmentConfig
metadata:
  name: env-config-1
  labels:
    my-label-key: my-label-value
data:
  data: "my data"
---
apiVersion: apiextensions.crossplane.io/v1alpha1
kind: EnvironmentConfig
metadata:
  name: env-config-2
  labels:
    my-label-key: my-label-value
data:
  data: "my data3"

When Crossplane merges these maps it isn't immediately clear which value the final map will have for data key. A simple check in the merge step could bring this silent overwrite to the composition developer's attention and hopefully save some debugging time. That's the idea I had in mind for creating this enhancement issue.

Hope that clarifies, and please let me know if I'm still missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants