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

Allow ignoring environment config if it does not exists #3723

Closed
Tracked by #3770
duizabojul opened this issue Feb 3, 2023 · 7 comments · Fixed by #4547
Closed
Tracked by #3770

Allow ignoring environment config if it does not exists #3723

duizabojul opened this issue Feb 3, 2023 · 7 comments · Fixed by #4547
Labels

Comments

@duizabojul
Copy link
Contributor

duizabojul commented Feb 3, 2023

What problem are you facing?

I don't know if I am using environment config the bad way but I can't figure how to ignore selection of an EnvironmentConfig if it does not exists.

Let's say I have the following EnvironmentConfig resources:

apiVersion: apiextensions.crossplane.io/v1alpha1
kind: EnvironmentConfig
metadata:
  labels:
    provider-name: default-provider
  name: defaut-provider-config
data:
  id: 123456
apiVersion: apiextensions.crossplane.io/v1alpha1
kind: EnvironmentConfig
metadata:
  labels:
    provider-name: other-provider
  name: other-provider-config
data:
  id: 456789

Then I have a XRD with an optional field providerConfigRef.name in spec

In my composition I want to load the default-provider-config EnvironmentConfig if providerConfigRef.name is not referenced in my XR, and the correct provider EnvironmentConfig if it is referenced (let's say other-provider-config EnvironmentConfig if providerConfigRef.name : other-provider).

So I tried to add the following environment in the associated composition:

...
environment:
  environmentConfigs:
    - type: Selector
      selector:
        matchLabels:
        - key: provider-name
          type: Value
          value: default-provider
    - type: Selector
      selector:
        matchLabels:
        - key: provider-name
          type: FromCompositeFieldPath
          valueFromFieldPath: spec.providerConfigRef.name

The problem is if spec.providerConfigRef.name does not exists, crossplane will fail reconciliation with the following message: cannot select environment: failed to build reference at index 1: failed to resolve value for label at index 0: spec.providerConfigRef: no such field

How could Crossplane help solve your problem?

Maybe there is a workaround to this issue, but if not it would be neat to have a way to ignore missing environment config, the same way as patches are ignored if field path does not exists

@duizabojul duizabojul added the enhancement New feature or request label Feb 3, 2023
@negz
Copy link
Member

negz commented Feb 3, 2023

CC @MisterMX

@github-actions
Copy link

github-actions bot commented May 6, 2023

Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

@github-actions github-actions bot added the stale label May 6, 2023
@bobh66
Copy link
Contributor

bobh66 commented May 6, 2023

/fresh

@phisco
Copy link
Contributor

phisco commented Jul 12, 2023

This was addressed introducing spec.environment.policy.resolution: Optional (default: Required) by: #3981

@phisco phisco closed this as completed Jul 12, 2023
@phisco phisco reopened this Jul 12, 2023
@phisco
Copy link
Contributor

phisco commented Jul 12, 2023

Actually not, I misread the issue, this is still valid

@MisterMX
Copy link
Contributor

A workaround here in conjuction with #3981 is to use selector instead of ref which can be defined to be optional.

There is currently no way to make a ref optional but it could be made so by adding a policy.resolutionPolicy that works just like provider referencers and can be set to Required (default) or Optional where the latter would could a Not found to be ignored.

@phisco
Copy link
Contributor

phisco commented Aug 31, 2023

@MisterMX i also thought that was the issue, but here the point was actually the missing field in the source composite resource: failed to build reference at index 1: failed to resolve value for label at index 0: spec.providerConfigRef: no such field. Which I'm addressing in #4547.

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

Successfully merging a pull request may close this issue.

5 participants