Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KIALI-2034 Fixes for Create Istio Object endpoints #804

Merged
merged 2 commits into from Jan 25, 2019

Conversation

lucasponce
Copy link
Contributor

  • Adjust the right endpoint in the k8s Api
  • Parse object to validate type vs payload
  • Reformat JSON object used

- Adjust the right endpoint in the k8s Api
- Parse object to validate type vs payload
- Reformat JSON object used
@lucasponce
Copy link
Contributor Author

Tested with:

POST http://admin:admin@localhost:8000/api/namespaces/bookinfo/istio/destinationrules
Content-Type: application/json

{
  "metadata": {
    "name": "reviews"
  },
  "spec": {
    "host": "reviews",
    "subsets": [
      {
        "name": "v1",
        "labels": {
          "version": "v1"
        }
      },
      {
        "name": "v2",
        "labels": {
          "version": "v2"
        }
      },
      {
        "name": "v3",
        "labels": {
          "version": "v3"
        }
      }
    ]
  }
}

Or

POST http://admin:admin@localhost:8000/api/namespaces/bookinfo/istio/adapters/memquotas
Content-Type: application/json

{
  "metadata": {
    "name": "adapter-memquota-fake"
  },
  "spec": {
  }
}

@@ -304,8 +303,24 @@ func IstioConfigCreate(w http.ResponseWriter, r *http.Request) {
RespondWithError(w, http.StatusBadRequest, "Create request could not be read: "+err.Error())
}

business.IstioConfig.CreateIstioConfigDetail(api, namespace, objectType, objectSubtype, object, string(body))
json, err := business.IstioConfig.ParseJsonForCreate(objectType, objectSubtype, body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this kinda ruin the separation? Shouldn't it be a detail of Create?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that handler layer should process the input parameters and validate those are correct.
Return a BadRequest / 400 error, like a malformed or bad body.
Yeah, this is something in the middle of handlers / business layer.
Return a 404 from the business layer ? and add a IsBadRequest() after the CreateIstioConfigDetail() ?

I can do that if it's more clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense, given that we return 404 from business layer also later. Thus, the handler should probably only verify the JSON can be extracted and not care about the actual data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will move it inside the business and also check the 400 in the returning error, that will place same logic together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burmanm I've sent a commit to move this logic, let me know if the PR works for you.

@rhqci
Copy link

rhqci commented Jan 24, 2019

Jenkins CI: kiali-core-pr-e2e-test #442

@lucasponce
Copy link
Contributor Author

@hhovsepy I don't see why the e2e are failing as there is not a change on them and the logic introduced is new.
Could you take a look ? The PR is not yet finished, I need to address some comments, but the e2e failing is intriguing.

@rhqci
Copy link

rhqci commented Jan 25, 2019

Jenkins CI: kiali-core-pr-e2e-test #457

  • ✔️ run-kiali-e2e-tests #[1071]

@burmanm
Copy link
Contributor

burmanm commented Jan 25, 2019

Appears to work, although I would say our "DELETE" answer is incorrect - it's not JSON.

[miburman@miranda kiali]$ curl -X DELETE https://admin:admin@kiali-istio-system.192.168.1.105.nip.io/api/namespaces/bookinfo/istio/destinationrules/reviews --insecure
"Deleted"[miburman@miranda kiali]$ 
[miburman@miranda kiali]$ curl -d "@post-test.json" -X POST https://admin:admin@kiali-istio-system.192.168.1.105.nip.io/api/namespaces/bookinfo/istio/destinationrules --insecure | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1124  100   759  100   365   7744   3724 --:--:-- --:--:-- --:--:-- 11469
{
    "adapter": null,
    "destinationRule": {
        "metadata": {
            "creationTimestamp": "2019-01-25T11:45:35Z",
            "generation": 1,
            "name": "reviews",
            "namespace": "bookinfo",
            "resourceVersion": "409174",
            "selfLink": "/apis/networking.istio.io/v1alpha3/namespaces/bookinfo/destinationrules/reviews",
            "uid": "ba6034c1-2096-11e9-8c48-28d2449dcdfa"
        },
        "spec": {
            "host": "reviews",
            "subsets": [
                {
                    "labels": {
                        "version": "v1"
                    },
                    "name": "v1"
                },
                {
                    "labels": {
                        "version": "v2"
                    },
                    "name": "v2"
                },
                {
                    "labels": {
                        "version": "v3"
                    },
                    "name": "v3"
                }
            ],
            "trafficPolicy": null
        }
    },
    "gateway": null,
    "namespace": {
        "name": "bookinfo"
    },
    "objectType": "destinationrules",
    "permissions": {
        "delete": false,
        "update": false
    },
    "policy": null,
    "quotaSpec": null,
    "quotaSpecBinding": null,
    "rule": null,
    "serviceEntry": null,
    "template": null,
    "validation": null,
    "virtualService": null
}
[miburman@miranda kiali]$ curl -d "@post-test.json" -X POST https://admin:admin@kiali-istio-system.192.168.1.105.nip.io/api/namespaces/bookinfo/istio/destinationrules --insecure | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   440  100    75  100   365   1136   5530 --:--:-- --:--:-- --:--:--  6666
{
    "error": "destinationrules.networking.istio.io \"reviews\" already exists"
}
[miburman@miranda kiali]$

@burmanm burmanm merged commit 0d00a67 into kiali:master Jan 25, 2019
@lucasponce lucasponce deleted the fixes-on-create-object branch July 10, 2019 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants