sostheim / krak8s

API Service for Kraken and Kubernetes Commands
Apache License 2.0
1 stars 5 forks source link

can't list applications with /v1/projects/${id}/applications #11

Open jshimko opened 7 years ago

jshimko commented 7 years ago

I have a project, namespace, cluster, etc. and a single application running. I can query for the single application and successfully get it, but I can't list applications in that same namespace.

# GET the single app

curl http://localhost:8080/v1/projects/77907b06/applications/bb7dd432

{
  "channel": "stable",
  "config": "",
  "created_at": "2017-09-18T13:35:53.981897503Z",
  "deployment_name": "jeremy-mongodb",
  "id": "bb7dd432",
  "json_values": "",
  "name": "mongodb-replicaset",
  "namespace_id": "02678191",
  "registry": "quay.io/samsung_cnct",
  "server": "quay.io",
  "status": {
    "deployed_at": "2017-09-18T13:35:57.832285003Z",
    "state": "DEPLOYED"
  },
  "type": "application",
  "updated_at": "2017-09-18T13:35:57.832285386Z",
  "username": "",
  "version": "latest"
}
# GET all apps in that same namespace

curl http://localhost:8080/v1/projects/77907b06/applications \
     -H "Content-Type: application/json" \
     -d '{ "namespaceid": "02678191" }'

{
  "id": "9PjU+W/E",
  "code": "invalid_request",
  "status": 400,
  "detail": "missing required payload"
}

Yes, I realize my body has namespaceid instead of namespace_id, but that’s what the spec says. Regardless, I tried both ways and got the same result.

swagger_editor

Just to show you that the namespace definitely exists...

curl http://localhost:8080/v1/projects/77907b06/namespaces/02678191

{
  "applications": [
    {
      "oid": "bb7dd432",
      "url": "/v1/projects/77907b06/applications/bb7dd432"
    }
  ],
  "created_at": "2017-09-11T21:49:32.759664083Z",
  "id": "02678191",
  "name": "jeremy",
  "resources": {
    "oid": "e322aa1c",
    "url": "/v1/projects/77907b06/cluster/e322aa1c"
  },
  "type": "namespace"
}
sostheim commented 7 years ago

So, I think this is just a peculiarity of curl and the order of arguments on the command line. I was able to reproduce this by putting the header and body arguments after the URL.

Reproduced Failure:

$ curl http://localhost:8080/v1/projects/6f6c206e/applications -H "Content-Type: application/json" -d'{"namespaceid":"fc0c6a6b"}' 
{
    "id": "rFzsPcwX",
    "code": "bad_request",
    "status": 400,
    "detail": "[WSUhRC52] 400 invalid_request: attribute \"name\" of response is missing and required; attribute \"namespace_id\" of response is missing and required, attribute: namespace_id, parent: response"
}

Only change is to add a -XGET parameter after the URL.

Working:

$ curl http://localhost:8080/v1/projects/6f6c206e/applications -XGET -H "Content-Type: application/json" -d'{"namespaceid":"fc0c6a6b"}' 
[{
    "channel": "stable",
    "config": "",
    "created_at": "2017-09-18T22:32:31.325098155-07:00",
    "deployment_name": "illinois-urbana-mongodb",
    "id": "7412131c",
    "json_values": "",
    "name": "mongodb-replicaset",
    "namespace_id": "fc0c6a6b",
    "registry": "samsung_cnct",
    "server": "quay.io",
    "status": {
        "deployed_at": "2017-09-18T22:32:31.325669159-07:00",
        "state": "DEPLOYED"
    },
    "type": "application",
    "updated_at": "2017-09-18T22:32:31.325669175-07:00",
    "username": "",
    "version": "latest"
}]
sostheim commented 7 years ago

@jshimko - will leave this open until tomorrow so you have a chance to verify.

jshimko commented 7 years ago

So I guess I'm not exactly sure it this isn't a bug though, because I don't have the same issue with any other API I've just tested (5 different ones). Even doing a GET for a single item on krak8s allows you to have that same header and not use -X GET, so at the very least it's inconsistent.

curl http://localhost:8080/v1/projects/77907b06/applications/bb7dd432 \
     -H "Content-Type: application/json"

{
  "channel": "stable",
  "config": "",
  "created_at": "2017-09-18T13:35:53.981897503Z",
  "deployment_name": "jeremy-mongodb",
  "id": "bb7dd432",
  "json_values": "",
  "name": "mongodb-replicaset",
  "namespace_id": "02678191",
  "registry": "quay.io/samsung_cnct",
  "server": "quay.io",
  "status": {
    "deployed_at": "0001-01-01T00:00:00Z",
    "state": "UNKNOWN"
  },
  "type": "application",
  "updated_at": "2017-09-18T13:35:53.981897503Z",
  "username": "",
  "version": "latest"
}

Anyway, if the API is going to choke on something like this, you may want to add some more useful error handling there. Because the error detail it spit out is completely incorrect. That's not actually what caused the error.

{
  "id": "rFzsPcwX",
  "code": "bad_request",
  "status": 400,
  "detail": "[WSUhRC52] 400 invalid_request: attribute \"name\" of response is missing and required; attribute \"namespace_id\" of response is missing and required, attribute: namespace_id, parent: response"
}
sostheim commented 7 years ago

Consideration for future enhancement.