scaleway / crossplane-provider-scaleway

Crossplane Scaleway Provider
Apache License 2.0
21 stars 10 forks source link

RDB Instance matchLabels does not work #86

Open MicheleSica opened 3 months ago

MicheleSica commented 3 months ago

Dear Support,

this is the follow up of the issue: https://github.com/scaleway/crossplane-provider-scaleway/issues/78

The below Crossplane code creates the objects Instance and Database in the "Managed Databases" Scaleway section

apiVersion: rdb.scaleway.upbound.io/v1alpha1
kind: Database
metadata:
  name: rdb-database
spec:
  forProvider:
    instanceIdRef:
      name: rdb-instance
    name: crossplane-rdb-database
  providerConfigRef:
    name: crossplane   
---
apiVersion: rdb.scaleway.upbound.io/v1alpha1
kind: Instance
metadata:
  name: rdb-instance
spec:
  forProvider:
    disableBackup: true
    engine: PostgreSQL-14
    isHaCluster: false
    name: crossplane-rdb-instance
    nodeType: DB-DEV-S
    passwordSecretRef:
      key: password
      name: instance-secret
      namespace: crossplane
    userName: admin
  providerConfigRef:
    name: crossplane

The status of the Crossplane objects after the creation:

➜  ~ kubectl get instance
NAME           SYNCED   READY   EXTERNAL-NAME                                         AGE
rdb-instance   True     True          ***                                             7m13s
➜  ~ kubectl get database
NAME           SYNCED   READY   EXTERNAL-NAME                                         AGE
rdb-database   True     True          ***/crossplane-rdb-database                     7m45s

Checking the documentation https://marketplace.upbound.io/providers/scaleway/provider-scaleway/v0.3.0/resources/rdb.scaleway.upbound.io/Instance/v1alpha1

I have added this code on the instance definition to link the database to the Private Network

    privateNetwork:
      - pnIdSelector:
          matchLabels:
            crossplane: network

The label crossplane: network has been added at the PrivateNetwork creation, this is the manifest of PrivateNetwork object:

apiVersion: vpc.scaleway.upbound.io/v1alpha1
kind: PrivateNetwork
metadata:
  annotations:
....
  finalizers:
  - finalizer.managedresource.crossplane.io
  generation: 3
  labels:
    argocd.argoproj.io/instance: crossplane
    crossplane: network

This is the updated instance manifest to link the Database to the PrivateNetwork

apiVersion: rdb.scaleway.upbound.io/v1alpha1
kind: Instance
metadata:
  name: rdb-instance
spec:
  forProvider:
    disableBackup: true
    engine: PostgreSQL-14
    isHaCluster: false
    name: crossplane-rdb-instance
    nodeType: DB-DEV-S
    passwordSecretRef:
      key: password
      name: instance-secret
      namespace: crossplane
    privateNetwork:
      - pnIdSelector:
          matchLabels:
            crossplane: network
    userName: admin
  providerConfigRef:
    name: crossplane

After creating the objects on Crossplane, it attempted to create the managed database but encountered this error:

Events:
  Type     Reason                           Age                   From                                                     Message
  ----     ------                           ----                  ----                                                     -------
  Warning  CannotResolveResourceReferences  46m                   managed/rdb.scaleway.upbound.io/v1alpha1, kind=database  cannot resolve references: mg.Spec.ForProvider.InstanceID: cannot get referenced resource: Instance.rdb.scaleway.upbound.io "rdb-instance" not found
  Warning  CannotResolveResourceReferences  35m (x16 over 46m)    managed/rdb.scaleway.upbound.io/v1alpha1, kind=database  cannot resolve references: mg.Spec.ForProvider.InstanceID: referenced field was empty (referenced resource may not yet be ready)

The Spec.ForProvider.InstanceID reported in the error is not a mandatory string: https://marketplace.upbound.io/providers/scaleway/provider-scaleway/v0.3.0/resources/rdb.scaleway.upbound.io/Database/v1alpha1#doc:spec-forProvider-instanceId

This is the database state after the creation attempt

➜  ~ kubectl get database
NAME           SYNCED   READY   EXTERNAL-NAME   AGE
rdb-database   False                                                     62m

➜  ~ kubectl get instance
NAME           SYNCED   READY   EXTERNAL-NAME   AGE
rdb-instance   False    False                                          63m

Could you kindly check?

Thanks in advance