openshift-online / maestro

Maestro Service Repo
Apache License 2.0
9 stars 17 forks source link

Creating a resource with the same name after its deletion fails #101

Closed machi1990 closed 3 months ago

machi1990 commented 4 months ago

Reproducer:

  1. Create the resource

    ocm post /api/maestro/v1/resources << EOF
    {
        "consumer_name": "cluster1", "name": "mambo-2",
        "version": 1,
        "manifest": {
          "apiVersion": "work.open-cluster-management.io/v1",
          "kind": "ManifestWork",
          "metadata": {
                "name": "mw",
                "namespace": "cluster1"
          },
          "spec": {
                "workload": { "manifests": [
                        {
                          "apiVersion": "v1",
                          "data": {
                                "mambo": "poa"
                          },
                          "kind": "Secret",
                          "metadata": {
                                "name": "test",
                                "namespace": "test"
                          }
                        }
                  ]}
          }
        }
    }
    EOF
  2. Delete the resource using the id given after the create call; replace the <resource_id> below with the id returned from 1

    ocm delete /api/maestro/v1/resources/<resource_id>
  3. Once the resource is successful deleted, attempt to recreate it again using step (1) above. And observe the failure.

A quick debug reveals this to be a DB level constraint of uniqueness name and soft deletion. Since the resource in step(2) is soft deleted, it's still present in the database. Recreating a resource with the same name afterwards fail since the resource still exists in the DB.

The constraint is defined as

 "idx_resources_name" UNIQUE, btree (name)
clyang82 commented 4 months ago

Do you have agent available? the agent should report back the deletion status and then we will delete from DB. We may introduce force deletion after 5 mins.

machi1990 commented 4 months ago

the agent should report back the deletion status and then we will delete from DB

@clyang82 Hey, Yes. The agent is available. I confirm that deleted resource was marked for deletion successfully and then soft deleted. The issue is that once it was soft deleted, it remained in the database making it impossible to create another resource with the same name.

clyang82 commented 3 months ago

@machi1990 this issue was fixed. please verify it. Thanks.

machi1990 commented 3 months ago

Thank you. I've verified the code change. It looks good to me. I'll close the issue.