FlexibleEngineCloud / provider-flexibleengine

Crossplane provider that exposes XRM-conformant managed resources for the FlexibleEngine API.
Apache License 2.0
10 stars 3 forks source link

[CCE] pvc creation failed #51

Open dmicheneau opened 1 year ago

dmicheneau commented 1 year ago

Is there an existing issue for this?

Current Behavior

The creation of PVC (CCE) resource does not work. Crossplane creates the PVC resource with an external name, but not on the Flexible Engine web interface. If I exercise the terraform generated by crossplane, the PVC resource is well created. We believe that the problem is in importation when crossplane asks the API, on the line: Source in HuaweiCloud Provider

Expected Behavior

No response

Steps To Reproduce

create a crossplane pvc resource with manifest below:

apiVersion: cce.flexibleengine.upbound.io/v1beta1
kind: Pvc
metadata:
  annotations:
    meta.upbound.io/example-id: cce/v1beta1/pvc
  labels:
    testing.upbound.io/example-name: example_pvc
  name: example-pvc
spec:
  forProvider:
    accessModes:
    - ReadWriteOnce
    annotations:
      everest.io/disk-volume-type: SSD
    clusterIdSelector:
      matchLabels:
        testing.upbound.io/example-name: example_cce_cluster
    name: example-pvc
    namespaceSelector:
      matchLabels:
        testing.upbound.io/example-name: default
    storage: 10Gi
    storageClassName: csi-disk

locate directory wordir tmp delete terraform tfstate and make a terraform apply. Magic ! the pvc is created.

Environment

azrod commented 1 year ago

After releasing terraform-provider new error is returned

Message:               apply failed: Error creating FlexibleEngine CCE PVC: Resource not found: [POST https://REDACTED.cce.eu-west-0.prod-cloud-ocb.orange-business.com/api/v1/namespaces/REDACTED/persistentvolumeclaims], error message: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"namespaces \"REDACTED\" not found","reason":"NotFound","details":{"name":"REDACTED","kind":"namespaces"},"code":404}
azrod commented 1 year ago

The error in the terraform provider is now corrected

azrod commented 1 year ago

Now i have error caused by a tainted state. After creation the resource as READY = false this is caused by annotations field

Note in terraform doc

Note that the imported state may not be identical to your resource definition, due to some attributes missing from the API response, security or some other reason.

The missing attributes include: annotations. It is generally recommended running terraform plan after importing a PVC. You can then decide if changes should be applied to the PVC, or the resource definition should be updated to align with the PVC. Also you can ignore changes as below.

This problem is know in upjet Upbound/upjet#80

kubectl describe pvc.cce.flexibleengine.upbound.io/example-cce-pvc
Name:         example-cce-pvc
Namespace:    
Labels:       testing.upbound.io/example-name=example_cce_pvc
Annotations:  crossplane.io/external-create-pending: 2023-01-17T11:09:04+01:00
              crossplane.io/external-create-succeeded: 2023-01-17T11:09:04+01:00
              crossplane.io/external-name: redacted
              meta.upbound.io/example-id: cce/v1beta1/pvc
              upjet.crossplane.io/provider-meta: {"redacted":{"create":300000000000,"delete":180000000000}}
API Version:  cce.flexibleengine.upbound.io/v1beta1
Kind:         Pvc
Metadata:
  Creation Timestamp:  2023-01-17T10:08:53Z
  Finalizers:
    finalizer.managedresource.crossplane.io
  Generation:  3
  Managed Fields:
    API Version:  cce.flexibleengine.upbound.io/v1beta1
    Fields Type:  FieldsV1
    Manager:      kubectl-client-side-apply
    Operation:    Update
    Time:         2023-01-17T10:08:53Z
    API Version:  cce.flexibleengine.upbound.io/v1beta1
    Fields Type:  FieldsV1
    fieldsV1: (...)
    Manager:      provider
    Operation:    Update
    Time:         2023-01-17T10:14:08Z
    API Version:  cce.flexibleengine.upbound.io/v1beta1
    Fields Type:  FieldsV1
    fieldsV1: (...)
    Manager:         provider
    Operation:       Update
    Subresource:     status
    Time:            2023-01-17T10:14:10Z
  Resource Version:  1234916
  Self Link:         /apis/cce.flexibleengine.upbound.io/v1beta1/pvcs/example-cce-pvc
  UID:               redacted
Spec:
  Deletion Policy:  Delete
  For Provider:
    Access Modes:
      ReadWriteOnce
    Annotations:
      everest.io/disk-volume-type:  SSD
    Cluster Id:                     redacted
    Cluster Id Ref:
      Name:  example-cce-cluster
    Cluster Id Selector:
      Match Labels:
        testing.upbound.io/example-name:  example_cce_cluster
    Name:                                 example-cce-pvc
    Namespace:                            example-cce-namespace
    Namespace Ref:
      Name:  example-cce-namespace
    Namespace Selector:
      Match Labels:
        testing.upbound.io/example-name:  example_cce_namespace
    Region:                               eu-west-0
    Storage:                              10Gi
    Storage Class Name:                   csi-disk
  Provider Config Ref:
    Name:  default
Status:
  At Provider:
    Creation Timestamp:  2023-01-17T10:09:07Z
    Id:                  redacted
    Status:              Pending
  Conditions:
    Last Transition Time:  2023-01-17T10:14:09Z
    Reason:                Available
    Status:                True
    Type:                  Ready
    Last Transition Time:  2023-01-17T10:14:12Z
    Message:               observe failed: cannot run plan: plan failed: Instance cannot be destroyed: Resource flexibleengine_cce_pvc.example-cce-pvc has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or reduce the scope of the plan using the -target flag.
    Reason:                ReconcileError
    Status:                False
    Type:                  Synced
    Last Transition Time:  2023-01-17T10:14:06Z
    Reason:                Finished
    Status:                True
    Type:                  AsyncOperation
    Last Transition Time:  2023-01-17T10:14:06Z
    Message:               apply failed: Timeout for waiting PVC status become ready: context deadline exceeded: 
    Reason:                ApplyFailure
    Status:                False
    Type:                  LastAsyncOperation
Events:
  Type     Reason                         Age                From                                                     Message
  ----     ------                         ----               ----                                                     -------
  Normal   CreatedExternalResource        6m35s              managed/cce.flexibleengine.upbound.io/v1beta1, kind=pvc  Successfully requested creation of external resource
  Warning  CannotObserveExternalResource  19s (x7 over 87s)  managed/cce.flexibleengine.upbound.io/v1beta1, kind=pvc  cannot run plan: plan failed: Instance cannot be destroyed: Resource flexibleengine_cce_pvc.example-cce-pvc has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or reduce the scope of the plan using the -target flag.