crossplane / crossplane

The Cloud Native Control Plane
https://crossplane.io
Apache License 2.0
9.59k stars 965 forks source link

Lock conditions does not display all parent constraints when there is no valid version to install #6074

Open ezgidemirel opened 3 weeks ago

ezgidemirel commented 3 weeks ago

What happened?

With the recent changes, we know see the resolver reconciler's error messages in the lock object's conditions. This allows us to understand why package manager does not proceed with dependency installations.

When there are multiple packages depending on the same package, we're trying to find a valid version which satisfies all constraints. If there is no such version, or if that version requires a downgrade, package manager gives and error and stores it in the lock object as a condition.

In the following case, multiple packages are depending on provider-nop with different constraints,

apiVersion: pkg.crossplane.io/v1beta1
kind: Lock
metadata:
  creationTimestamp: "2024-11-06T10:37:31Z"
  finalizers:
  - lock.pkg.crossplane.io
  generation: 4
  name: lock
  resourceVersion: "931"
  uid: 9471decf-2655-4c27-84d3-cee2f694f9d6
packages:
- dependencies:
  - constraints: <=v0.3.0
    package: xpkg.upbound.io/crossplane-contrib/provider-nop
    type: Provider
  - constraints: v0.2.0
    package: xpkg.upbound.io/crossplane/e2e-depends-on-provider-nop
    type: Configuration
  name: configuration-getting-started-4a25d454a403
  source: xpkg.upbound.io/crossplane/e2e-nested-configuration
  type: Configuration
  version: v0.1.0-nd
- dependencies: []
  name: crossplane-contrib-provider-nop-37f3300ebfa7
  source: xpkg.upbound.io/crossplane-contrib/provider-nop
  type: Provider
  version: v0.3.0
- dependencies:
  - constraints: =v0.2.0
    package: crossplane-contrib/provider-nop
    type: Provider
  name: crossplane-e2e-depends-on-provider-nop-167d23fb5bc0
  source: xpkg.upbound.io/crossplane/e2e-depends-on-provider-nop
  type: Configuration
  version: v0.2.0
status:
  conditions:
  - lastTransitionTime: "2024-11-06T10:38:29Z"
    message: 'Error occurred during dependency resolution cannot find dependency version
      to upgrade: dependency (crossplane-contrib/provider-nop) does not have a valid
      version to upgrade that satisfies all constraints. If there is a valid version
      that requires downgrade, manual intervention is required. Constraints: [=v0.2.0
      =v0.2.0]'
    reason: DependencyResolutionFailed
    status: "False"
    type: Resolved

However, error message does not contain the first constraint <=v0.3.0. Also, =v0.2.0 constraint is displayed multiple times which can also be improved.

How can we reproduce it?

To reproduce, we need to enable the alpha feature by passing --enable-dependency-version-upgrades and apply the following manifest:

apiVersion: pkg.crossplane.io/v1
kind: Configuration
metadata:
  name: configuration-getting-started
spec:
  package: xpkg.upbound.io/crossplane/e2e-nested-configuration:v0.1.0-nd

P.S: Feature flag is required because without this new behavior, resolver reconciler does not send an error since all dependencies are installed (even though the versions are not satisfying the constraints) and only the package revision reconciler displays the error.

What environment did it happen in?

Crossplane version: v1.18.0

ezgidemirel commented 3 weeks ago

I've spent some time on this bug to find a quick fix, but got stuck after noticing that we're not passing default registry info to the lock obj. Therefore, storing the correct parent constraints on the edges is not possible with the current data structures.

I suggest to reimplement dependency management logic in Crossplane from scratch to handle package identification and constraint satisfactions in a better way.