From 2cbe336ad37c94de890300c27a17586614a9bc60 Mon Sep 17 00:00:00 2001 From: Kyle Hodgetts Date: Tue, 28 Sep 2021 17:20:32 +0300 Subject: [PATCH] Docs for Ambassador 2 + fixes for preview breakages (#174) * Add docs for ambassador 2.0 generator usage * make host option mandatory. Introduce template func for splitting a comma separated string into its components for the mapping template cors section as Ambassador 2.0 doesn't support comma separated strings as paramters for cors anymore. * host option is now mandatory for Ambassador 2.0 as AmbassadorMappings must match an AmbassadorHost resource in order to work * host option is now mandatory for Ambassador 2.0 as AmbassadorMappings must match an AmbassadorHost resource in order to work * split CORS comma separated strings into array using template func and iterate over them creating a yaml array in the resulting AmbassadorMapping resource * Add warnings to Ambassador 2.0 docs regarding unstability of the Developer Preview --- README.md | 4 +- docs/ambassador2.md | 550 +++++++++++++++++++ examples/booksapp/booksapp_extension.yaml | 1 + generators/ambassador/v2/ambassador.go | 18 +- generators/ambassador/v2/ambassador_test.go | 107 +++- generators/ambassador/v2/mapping_template.go | 38 +- 6 files changed, 698 insertions(+), 20 deletions(-) create mode 100644 docs/ambassador2.md diff --git a/README.md b/README.md index b337ccf..b00c311 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,13 @@ allowing you to Kusk currently supports (click for configuration options) - [Ambassador 1.x](https://kubeshop.github.io/kusk/ambassador/) +- [Ambassador 2.0](https://kubeshop.github.io/kusk/ambassador/) + - **Warning** This is a developer preview and should be treated as unstable - [Linkerd](https://kubeshop.github.io/kusk/linkerd/) - [Nginx-Ingress](https://kubeshop.github.io/kusk/nginx-ingress/) - [Traefik V2 (v2.x)](https://kubeshop.github.io/kusk/traefik/) -Some of the upcoming tools we'd like to support are Kong, Ambassador 2.x, etc. Please don't hesitate to +Some of the upcoming tools we'd like to support are Kong and Contour. Please don't hesitate to suggest others or contribute your own generator! ## Documentation & Support diff --git a/docs/ambassador2.md b/docs/ambassador2.md new file mode 100644 index 0000000..743ea0e --- /dev/null +++ b/docs/ambassador2.md @@ -0,0 +1,550 @@ +# Ambassador 2.0 +**Warning**: Ambassador 2.0 is currently in Developer Preview and could change at any point, breaking the implementation here. + + +```shell +kusk ambassador2 --help +Generates Ambassador 2.0 Mappings for your service + +Usage: + kusk ambassador2 [flags] + +Flags: + -i, --in string file path to api spec file to generate mappings from. e.g. --in apispec.yaml + --namespace string namespace for generated resources (default "default") + --service.name string target Service name + --service.namespace string namespace containing the target Service (default "default") + --service.port int32 target Service port (default 80) + --host string the Host header value to listen on + --path.base string a base path for Service endpoints (default "/") + --path.split force Kusk to generate a separate Mapping for each operation + --path.trim_prefix string a prefix to trim from the URL before forwarding to the upstream Service + --rate_limits.burst uint32 request per second burst + --rate_limits.rps uint32 request per second rate limit + --timeouts.idle_timeout uint32 idle connection timeout (seconds) + --timeouts.request_timeout uint32 total request timeout (seconds) + -h, --help +``` + +The Ambassador generator generates [AmbassadorMapping]s (https://www.getambassador.io/docs/edge-stack/2.0/topics/using/intro-mappings/) resources for mapping resource to services. All options that can be set via +flags can also be set using our `x-kusk` OpenAPI extension in your specification. + +CLI flags apply only at the global level i.e. applies to all paths and methods. + +To override settings on the path or HTTP method level, you are required to use the x-kusk extension at that path in your API specification. + +## Full Options Reference +| Name | CLI Option | OpenAPI Spec x-kusk label | Descriptions | Overwritable at path / method | +|-------------------------|----------------------------|---------------------------|--------------------------------------------------------------------------------------------------------------------|-------------------------------| +| OpenAPI or Swagger File | --in | N/A | Location of the OpenAPI or Swagger specification | ❌ | +| Namespace | --namespace | namespace | the namespace in which to create the generated resources (Required) | ❌ | +| Service Name | --service.name | service.name | the name of the service running in Kubernetes (Required) | ❌ | +| Service Namespace | --service.namespace | service.namespace | The namespace where the service named above resides (default value: default) | ❌ | +| Service Port | --service.port | service.port | Port the service is listening on (default value: 80) | ❌ | +| Path Base | --path.base | path.base | Prefix for your resource routes | ❌ | +| Path Trim Prefix | --path.trim_prefix | path.trim_prefix | Trim the specified prefix from URl before passing request onto service | ❌ | +| Path split | --path.split | path.split | Boolean; whether or not to force generator to generate a mapping for each path | ❌ | +| Host | --host | host | The value to set the host field to in the AmbassadorMapping resource | ✅ | +| Rate limit (RPS) | --rate_limits.rps | rate_limits.rps | Request per second rate limit | ✅ | +| Rate limit (burst) | --rate_limits.burst | rate_limits.burst | Rate limit burst | ✅ | +| Rate limit group | N/A | rate_limits.group | Rate limit endpoint group | | +| Request Timeout | --timeouts.request_timeout | timeouts.request_timeout | Total request timeout (seconds) | ✅ | +| Idle Timeout | --timeouts.idle_timeout | timeouts.idle_timeout | Idle connection timeout (seconds) | ✅ | +| CORS Origins | N/A | cors.origins | Array of origins | ✅ | +| CORS Methods | N/A | cors.methods | Array of methods | ✅ | +| CORS Headers | N/A | cors.headers | Array of headers | ✅ | +| CORS ExposeHeaders | N/A | cors.expose_headers | Array of headers to expose | ✅ | +| CORS Credentials | N/A | cors.credentials | Boolean: enable credentials (default value: false) | ✅ | +| CORS Max Age | N/A | cors.max_age | Integer:how long the response to the preflight request can be cached for without sending another preflight request | ✅ | + +## Ambassador 2.0 Setup +[source](https://www.getambassador.io/docs/edge-stack/latest/tutorials/getting-started/) + +### Create cluster +`k3d cluster create -p "8080:80@loadbalancer" -p "8443:443@loadbalancer" --k3s-server-arg '--disable=traefik' cl1` + +### Install the edge-stack +``` +# Add the Repo: +helm repo add datawire https://www.getambassador.io +helm repo update + +# Create Namespace and Install: +helm install -n ambassador --create-namespace \ + edge-stack --devel \ + datawire/edge-stack && \ + kubectl rollout status -n ambassador deployment/edge-stack -w +``` + +### Create the AmbassadorListeners +``` +kubectl apply -f - <