cloudfoundry / cf-crd-explorations

Apache License 2.0
3 stars 2 forks source link

Spike: Add `PATCH /v3/apps/:guid/relationships/current_droplet` endpoint (set current droplet) #20

Open tcdowney opened 3 years ago

tcdowney commented 3 years ago

Context

Although an App can have multiple staged and ready Droplets, it can only have one "desired" or "current" Droplet assigned at any given time. Clients can set the current droplet via the PATCH /v3/apps/:guid/relationships/current_droplet endpoint.


Acceptance Criteria

Aim to reach parity with the existing CF API. Cloud Controller has strict validations around ownership of the Droplet. If you try and set a Droplet that either does not exist or does not belong to the App it will return a 422 error. (relevant code)

Setting a Droplet (Happy Path)

GIVEN I have the shim running and a Droplet/App both exist in the same namespace and the Droplet is associated with the App WHEN I make the following request

curl "http://api-shim.example.org/v3/apps/[app_guid]/relationships/current_droplet" \
  -X PATCH \
  -H "Content-type: application/json" \
  -d '{ "data": { "guid": "[droplet_guid]" } }'

THEN I see the following response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "data": {
    "guid": "[droplet_guid]"
  },
  "links": {
    "self": {
      "href": "https://api.example.org/v3/apps/[app_guid]/relationships/current_droplet"
    },
    "related": {
      "href": "https://api.example.org/v3/apps/[app_guid]/droplets/current"
    }
  }
}

AND I can view the App CR and see that its currentDropletRef points to the Droplet I specified

Setting a Droplet (App does not exist)

GIVEN I have the shim running and the App does not exist WHEN I make the following request

curl "http://api-shim.example.org/v3/apps/[non_existant_app_guid]/relationships/current_droplet" \
  -X PATCH \
  -H "Content-type: application/json" \
  -d '{ "data": { "guid": "[droplet_guid]" } }'

THEN I receive a 404 response with the error in the body (see what happens on CF for VMs today)

Setting a Droplet (Droplet does not exist)

GIVEN I have the shim running and the Droplet does not exist WHEN I make the following request

curl "http://api-shim.example.org/v3/apps/[non_existant_app_guid]/relationships/current_droplet" \
  -X PATCH \
  -H "Content-type: application/json" \
  -d '{ "data": { "guid": "[droplet_guid]" } }'

THEN I receive a 422 response with the error in the body (see what happens on CF today)

Setting a Droplet (Droplet exists but not in namespace for the App)

GIVEN I have the shim running and the Droplet does exist but is in a different namespace from the App WHEN I make the following request

curl "http://api-shim.example.org/v3/apps/[non_existant_app_guid]/relationships/current_droplet" \
  -X PATCH \
  -H "Content-type: application/json" \
  -d '{ "data": { "guid": "[droplet_guid]" } }'

THEN I receive a 422 response with the error in the body (see what happens on CF today)

Setting a Droplet (Droplet exists and in correct namespace, but not owned by the App)

⚠️ Not sure how valuable this case is.

GIVEN I have the shim running and the Droplet does exist and is in the correct namespace, but is not Associated with the App WHEN I make the following request

curl "http://api-shim.example.org/v3/apps/[non_existant_app_guid]/relationships/current_droplet" \
  -X PATCH \
  -H "Content-type: application/json" \
  -d '{ "data": { "guid": "[droplet_guid]" } }'

THEN I receive a 422 response with the error in the body (see what happens on CF today)


Dev Notes