Skip to content

Commit

Permalink
Merge branch 'main' into CI_PR_run
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmingacic authored Nov 21, 2022
2 parents 762f403 + 3648529 commit bc4fb85
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 236 deletions.
40 changes: 7 additions & 33 deletions api/v1alpha1/staticroute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,57 +45,31 @@ type StaticRouteSpec struct {
// Fleet represents EnvoyFleet ID, which is deployed EnvoyFleet CustomResource name and namespace
// Optional, if missing will be automatically added by the Kusk Gateway with the discovery of the single fleet in the cluster (MutatingWebhookConfiguration for the API resource must be enabled).
Fleet *EnvoyFleetID `json:"fleet,omitempty"`

// Hosts is a collection of vhosts the rules apply to.
// Defaults to "*" - vhost that matches all domain names.
// +optional
Hosts []options.Host `json:"hosts,omitempty"`

// +optional
Auth *options.AuthOptions `json:"auth,omitempty"`

// Paths is a multidimensional map of path / method to the routing rules
Paths map[Path]Methods `json:"paths"`
// Upstream is a set of options of a target service to receive traffic.
// +required
Upstream *options.UpstreamOptions `json:"upstream"`
}

// GetOptionsFromSpec is a converter to generate Options object from StaticRoutes spec
func (spec *StaticRouteSpec) GetOptionsFromSpec() (*options.StaticOptions, error) {
// 2 dimensional map["path"]["method"]SubOptions
paths := make(map[string]options.StaticOperationSubOptions)
opts := &options.StaticOptions{
Paths: paths,
Auth: spec.Auth,
Hosts: spec.Hosts,
Paths: paths,
Auth: spec.Auth,
Hosts: spec.Hosts,
Upstream: spec.Upstream,
}
if err := opts.Validate(); err != nil {
return nil, fmt.Errorf("failed to validate options: %w", err)
}

for specPath, specMethods := range spec.Paths {
path := string(specPath)
opts.Paths[path] = make(options.StaticOperationSubOptions)
pathMethods := opts.Paths[path]
for specMethod, specRouteAction := range specMethods {
methodOpts := &options.SubOptions{}
pathMethods[specMethod] = methodOpts
if specRouteAction.Redirect != nil {
methodOpts.Redirect = specRouteAction.Redirect
continue
}
if specRouteAction.Route != nil {
methodOpts.Upstream = *&specRouteAction.Route.Upstream
if specRouteAction.Route.CORS != nil {
methodOpts.CORS = specRouteAction.Route.CORS.DeepCopy()
}
if specRouteAction.Route.QoS != nil {
methodOpts.QoS = specRouteAction.Route.QoS
}
if specRouteAction.Route.Websocket != nil {
methodOpts.Websocket = specRouteAction.Route.Websocket
}
}
}
}
return opts, opts.Validate()
}

Expand Down
27 changes: 3 additions & 24 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions cmd/kusk/cmd/manifest_data.go

Large diffs are not rendered by default.

202 changes: 51 additions & 151 deletions config/crd/bases/gateway.kusk.io_staticroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,161 +202,61 @@ spec:
*example*), or simple domain (www.example.com)
type: string
type: array
paths:
additionalProperties:
additionalProperties:
description: Action is either a route to the upstream or a redirect,
they're mutually exclusive.
upstream:
description: Upstream is a set of options of a target service to receive
traffic.
properties:
host:
description: UpstreamHost defines any DNS hostname with port that
we can proxy to, even outside of the cluster
properties:
redirect:
description: RedirectOptions provide http redirects see https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-redirectaction
properties:
host_redirect:
type: string
path_redirect:
description: mutually exclusive with rewrite regex redirect
type: string
port_redirect:
format: int32
type: integer
response_code:
format: int32
type: integer
rewrite_regex:
description: mutually exclusive with path redirect
properties:
pattern:
type: string
substitution:
type: string
required:
- pattern
- substitution
type: object
scheme_redirect:
description: http|https
type: string
strip_query:
type: boolean
type: object
route:
description: Route defines a routing rule that proxies to
upstream
properties:
cors:
properties:
credentials:
type: boolean
expose_headers:
items:
type: string
type: array
headers:
items:
type: string
type: array
max_age:
type: integer
methods:
items:
type: string
type: array
origins:
items:
type: string
type: array
type: object
qos:
properties:
idle_timeout:
description: IdleTimeout is timeout for idle connection
format: int32
type: integer
request_timeout:
description: RequestTimeout is total request timeout
format: int32
type: integer
retries:
description: Retries define how many times to retry
calling the backend
format: int32
type: integer
type: object
upstream:
description: UpstreamOptions defines upstream that we
proxy to Host and Service are mutually exclusive
properties:
host:
description: UpstreamHost defines any DNS hostname
with port that we can proxy to, even outside of
the cluster
properties:
hostname:
description: Hostname is the upstream hostname,
without port.
type: string
port:
description: Port is the upstream port.
format: int32
type: integer
required:
- hostname
- port
type: object
rewrite:
description: Rewrite is the pattern (regex) and a
substitution string that will change URL when request
is being forwarded to the upstream service. e.g.
given that Prefix is set to "/petstore/api/v3",
and with Rewrite.Pattern is set to "^/petstore",
Rewrite.Substitution is set to "" path that would
be generated is "/petstore/api/v3/pets", URL that
the upstream service would receive is "/api/v3/pets".
properties:
pattern:
type: string
substitution:
type: string
required:
- pattern
- substitution
type: object
service:
description: UpstreamService defines K8s Service in
the cluster
properties:
name:
description: Name is the upstream K8s Service's
name.
type: string
namespace:
description: Namespace where service is located
type: string
port:
description: Port is the upstream K8s Service's
port.
format: int32
type: integer
required:
- namespace
- port
type: object
type: object
websocket:
description: Enable establishing Websocket connections,
by default disabled
type: boolean
required:
- upstream
type: object
hostname:
description: Hostname is the upstream hostname, without port.
type: string
port:
description: Port is the upstream port.
format: int32
type: integer
required:
- hostname
- port
type: object
rewrite:
description: Rewrite is the pattern (regex) and a substitution
string that will change URL when request is being forwarded
to the upstream service. e.g. given that Prefix is set to "/petstore/api/v3",
and with Rewrite.Pattern is set to "^/petstore", Rewrite.Substitution
is set to "" path that would be generated is "/petstore/api/v3/pets",
URL that the upstream service would receive is "/api/v3/pets".
properties:
pattern:
type: string
substitution:
type: string
required:
- pattern
- substitution
type: object
service:
description: UpstreamService defines K8s Service in the cluster
properties:
name:
description: Name is the upstream K8s Service's name.
type: string
namespace:
description: Namespace where service is located
type: string
port:
description: Port is the upstream K8s Service's port.
format: int32
type: integer
required:
- namespace
- port
type: object
description: Methods maps Method (GET, POST) to Action
type: object
description: Paths is a multidimensional map of path / method to the
routing rules
type: object
required:
- paths
- upstream
type: object
status:
description: StaticRouteStatus defines the observed state of StaticRoute
Expand Down
2 changes: 1 addition & 1 deletion config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ patchesStrategicMerge:
images:
- name: kusk-gateway
newName: kubeshop/kusk-gateway
newTag: v1.3.21
newTag: v1.3.22
- name: kusk-gateway:dev
newName: kubeshop/kusk-gateway
newTag: latest
2 changes: 1 addition & 1 deletion config/manager/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ metadata:
app.kubernetes.io/component: kusk-gateway-manager
app.kubernetes.io/instance: kusk-gateway
app.kubernetes.io/name: kusk-gateway
app.kubernetes.io/version: "v1.3.21"
app.kubernetes.io/version: "v1.3.22"
name: kusk-gateway-manager
namespace: kusk-system
2 changes: 1 addition & 1 deletion examples/auth/oauth2/static-route/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spec:
- name: HTTP_HEADERS
value: 'Content-Type: "application/json"'
- name: HTTP_BODY
value: '{ "kusk-gateway-manager": "v1.3.21" }'
value: '{ "kusk-gateway-manager": "v1.3.22" }'
---
apiVersion: v1
kind: Service
Expand Down
14 changes: 14 additions & 0 deletions examples/static-route/example-1-top-level-upstream/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: gateway.kusk.io/v1alpha1
kind: StaticRoute
metadata:
name: static-route-example-1-top-level-upstream
namespace: default
spec:
upstream:
service:
name: static-route-example-1-top-level-upstream
namespace: default
port: 80
fleet:
name: default
namespace: default
37 changes: 37 additions & 0 deletions examples/static-route/example-1-top-level-upstream/manifests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: static-route-example-1-top-level-upstream
namespace: default
labels:
app: static-route-example-1-top-level-upstream
spec:
selector:
matchLabels:
app: static-route-example-1-top-level-upstream
replicas: 1
template:
metadata:
labels:
app: static-route-example-1-top-level-upstream
spec:
containers:
- name: go-httpbin
image: docker.io/mccutchen/go-httpbin:v2.4.1
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: static-route-example-1-top-level-upstream
namespace: default
labels:
app: static-route-example-1-top-level-upstream
spec:
selector:
app: static-route-example-1-top-level-upstream
ports:
- name: http
port: 80
targetPort: 8080
Loading

0 comments on commit bc4fb85

Please sign in to comment.