kubeshop / kusk-gateway

Kusk-gateway is an OpenAPI-driven API Gateway for Kubernetes
https://kubeshop.github.io/kusk-gateway/
MIT License
259 stars 21 forks source link

Improve error messages #520

Closed aabedraba closed 2 years ago

aabedraba commented 2 years ago

Describe the enhancement you'd like to see For example, if I tried to apply an OpenAPI with mocking and validation enabled together, the error message is unreadable

$ kusk api generate --envoyfleet.name kusk-gateway-envoy-fleet -i openapi.yaml | kubectl apply -f -
Error from server: error when applying patch:
{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"gateway.kusk.io/v1alpha1\",\"kind\":\"API\",\"metadata\":{\"annotations\":{},\"name\":\"simple-api\",\"namespace\":\"default\"},\"spec\":{\"fleet\":{\"name\":\"kusk-gateway-envoy-fleet\",\"namespace\":\"kusk-system\"},\"spec\":\"components: {}\\ninfo:\\n  title: simple-api\\n  version: 0.1.0\\nopenapi: 3.0.0\\npaths:\\n  /hello:\\n    get:\\n      responses:\\n        \\\"200\\\":\\n          content:\\n            application/json:\\n              example:\\n                message: Hello from a mocked response!\\n              schema:\\n                properties:\\n                  message:\\n                    type: string\\n                type: object\\n          description: A simple hello world!\\n    x-kusk:\\n      mocking:\\n        enabled: true\\n      validation:\\n        request:\\n          enabled: true\\n  /validated:\\n    post:\\n      requestBody:\\n        content:\\n          application/json:\\n            schema:\\n              properties:\\n                name:\\n                  type: string\\n              required:\\n              - name\\n              type: object\\n        required: true\\n      responses:\\n        \\\"200\\\":\\n          content:\\n            text/plain:\\n              example: Hello mocked Kusk!\\n              schema:\\n                type: string\\n          description: \\\"\\\"\\nx-kusk:\\n  auth:\\n    auth-upstream:\\n      host:\\n        hostname: basic-auth-svc.default\\n        port: 8080\\n    scheme: basic\\n  cache:\\n    enabled: true\\n    max_age: 60\\n  cors:\\n    methods:\\n    - GET\\n    - POST\\n    origins:\\n    - '*'\\n  openapi-path: openapi.yaml\\n  rate_limit:\\n    requests_per_unit: 2\\n    unit: minute\\n  upstream:\\n    service:\\n      name: hello-world-svc\\n      namespace: default\\n      port: 8080\\n\"}}\n"}},"spec":{"spec":"components: {}\ninfo:\n  title: simple-api\n  version: 0.1.0\nopenapi: 3.0.0\npaths:\n  /hello:\n    get:\n      responses:\n        \"200\":\n          content:\n            application/json:\n              example:\n                message: Hello from a mocked response!\n              schema:\n                properties:\n                  message:\n                    type: string\n                type: object\n          description: A simple hello world!\n    x-kusk:\n      mocking:\n        enabled: true\n      validation:\n        request:\n          enabled: true\n  /validated:\n    post:\n      requestBody:\n        content:\n          application/json:\n            schema:\n              properties:\n                name:\n                  type: string\n              required:\n              - name\n              type: object\n        required: true\n      responses:\n        \"200\":\n          content:\n            text/plain:\n              example: Hello mocked Kusk!\n              schema:\n                type: string\n          description: \"\"\nx-kusk:\n  auth:\n    auth-upstream:\n      host:\n        hostname: basic-auth-svc.default\n        port: 8080\n    scheme: basic\n  cache:\n    enabled: true\n    max_age: 60\n  cors:\n    methods:\n    - GET\n    - POST\n    origins:\n    - '*'\n  openapi-path: openapi.yaml\n  rate_limit:\n    requests_per_unit: 2\n    unit: minute\n  upstream:\n    service:\n      name: hello-world-svc\n      namespace: default\n      port: 8080\n"}}
to:
Resource: "gateway.kusk.io/v1alpha1, Resource=apis", GroupVersionKind: "gateway.kusk.io/v1alpha1, Kind=API"
Name: "simple-api", Namespace: "default"
for: "STDIN": admission webhook "vapi.kb.io" denied the request: spec: x-kusk should be a valid set of options: OperationFinalSubOptions: (GET/hello: validation and mocking are mutually exclusive.).

Could we make it more readable?

$ kusk api generate --envoyfleet.name kusk-gateway-envoy-fleet -i openapi.yaml | kubectl apply -f -
validation and mocking are mutually exclusive
aabedraba commented 2 years ago

This applies to every syntax error or configuration error in Kusk, they're very hard to read, specially from the terminal and being a novice user.

crjones commented 2 years ago

From refinement: In the scenario above the output is being piped through kubectl and the error message is being generated out of our control without making a kubectl plugin.

aabedraba commented 2 years ago

@crjones kubectl will complain anyway if the provided string is not Kubernetes compatible... and people will double-check the output of the command to see what error is being produced. I think we should improve the reporting of errors and not letting kubectl do that.

jasmingacic commented 2 years ago

I will close this one out since we can't do much about it.

Error messages we are sending are messed up by kubectl.