Skip to content

Commit

Permalink
feat(MeshHTTPRoute): initial plugin (kumahq#5530)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
Signed-off-by: Bart Smykla <bartek@smykla.com>
  • Loading branch information
michaelbeaumont authored and bartsmykla committed Jan 14, 2023
1 parent 04a1ec1 commit 15ed591
Show file tree
Hide file tree
Showing 26 changed files with 2,234 additions and 4 deletions.
11 changes: 11 additions & 0 deletions pkg/plugins/policies/meshhttproute/api/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1alpha1

type PolicyDefault struct {
AppendRules []Rule
}

func (x *To) GetDefault() interface{} {
return PolicyDefault{
AppendRules: x.Rules,
}
}
62 changes: 62 additions & 0 deletions pkg/plugins/policies/meshhttproute/api/v1alpha1/meshhttproute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// +kubebuilder:object:generate=true
package v1alpha1

import (
common_api "github.com/kumahq/kuma/api/common/v1alpha1"
)

// MeshHTTPRoute
// +kuma:policy:skip_registration=true
// +kuma:policy:singular_display_name=Mesh HTTP Route
//
// This policy defines its own `GetDefault` method so that it can have the given
// structure for deserialization but still use the generic policy merging
// machinery.
//
// +kuma:policy:skip_get_default=true
type MeshHTTPRoute struct {
// TargetRef is a reference to the resource the policy takes an effect on.
// The resource could be either a real store object or virtual resource
// defined inplace.
TargetRef common_api.TargetRef `json:"targetRef,omitempty"`

// To matches destination services of requests and holds configuration.
To []To `json:"to,omitempty"`
}

type To struct {
// TargetRef is a reference to the resource that represents a group of
// request destinations.
TargetRef common_api.TargetRef `json:"targetRef,omitempty"`
// Rules contains the routing rules applies to a combination of top-level
// targetRef and the targetRef in this entry.
Rules []Rule `json:"rules,omitempty"`
}

type Rule struct {
Matches []Match `json:"matches"`
// Default holds routing rules that can be merged with rules from other
// policies.
Default RuleConf `json:"default"`
}

type Match struct {
Path PathMatch `json:"path,omitempty"`
}

type PathMatch struct {
Prefix string `json:"prefix,omitempty"`
}

type RuleConf struct {
Filters *[]Filter `json:"filters,omitempty"`
BackendRefs *[]BackendRef `json:"backendRefs,omitempty"`
}

type Filter struct {
}

type BackendRef struct {
common_api.TargetRef `json:",omitempty"`
Weight int `json:"weight,omitempty"`
}
129 changes: 129 additions & 0 deletions pkg/plugins/policies/meshhttproute/api/v1alpha1/rest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
openapi: 3.0.1
info:
version: v1alpha1
title: Kuma API
description: Kuma API

paths:
/meshes/{mesh}/meshhttproutes/{name}:
get:
summary: Returns MeshHTTPRoute entity
tags: [ "MeshHTTPRoute" ]
parameters:
- in: path
name: mesh
schema:
type: string
required: true
description: name of the mesh
- in: path
name: name
schema:
type: string
required: true
description: name of the MeshHTTPRoute
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: 'schema.yaml'

put:
summary: Creates or Updates MeshHTTPRoute entity
tags: [ "MeshHTTPRoute" ]
parameters:
- in: path
name: mesh
schema:
type: string
required: true
description: name of the mesh
- in: path
name: name
schema:
type: string
required: true
description: name of the MeshHTTPRoute
requestBody:
description: MeshHTTPRoute entity
required: true
content:
application/json:
schema:
$ref: 'schema.yaml'
responses:
'200':
description: Updated
'201':
description: Created

delete:
summary: Deletes MeshHTTPRoute entity
tags: [ "MeshHTTPRoute" ]
parameters:
- in: path
name: mesh
schema:
type: string
required: true
description: name of the mesh
- in: path
name: name
schema:
type: string
required: true
description: name of the MeshHTTPRoute
responses:
'200':
description: Successful response


/meshes/{mesh}/meshhttproutes:
get:
summary: Returns a list of MeshHTTPRoute in the mesh.
tags: [ "MeshHTTPRoute" ]
parameters:
- in: path
name: mesh
schema:
type: string
required: true
description: name of the mesh
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
items:
type: array
items:
$ref: 'schema.yaml'
next:
type: string
description: URL to the next page


/meshhttproutes:
get:
summary: Returns a list of MeshHTTPRoute from all meshes
tags: [ "MeshHTTPRoute" ]
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
items:
type: array
items:
$ref: 'schema.yaml'
next:
type: string
description: URL to the next page
125 changes: 125 additions & 0 deletions pkg/plugins/policies/meshhttproute/api/v1alpha1/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
properties:
type:
description: 'the type of the resource'
type: string
enum:
- MeshHTTPRoute
mesh:
description: 'Mesh is the name of the Kuma mesh this resource belongs to. It may be omitted for cluster-scoped resources.'
type: string
default: default
name:
description: 'Name of the Kuma resource'
type: string
spec:
description: Spec is the specification of the Kuma MeshHTTPRoute resource.
properties:
targetRef:
description: TargetRef is a reference to the resource the policy takes an effect on. The resource could be either a real store object or virtual resource defined inplace.
properties:
kind:
description: Kind of the referenced resource
enum:
- Mesh
- MeshSubset
- MeshService
- MeshServiceSubset
- MeshGatewayRoute
type: string
mesh:
description: Mesh is reserved for future use to identify cross mesh resources.
type: string
name:
description: 'Name of the referenced resource. Can only be used with kinds: `MeshService`, `MeshServiceSubset` and `MeshGatewayRoute`'
type: string
tags:
additionalProperties:
type: string
description: Tags used to select a subset of proxies by tags. Can only be used with kinds `MeshSubset` and `MeshServiceSubset`
type: object
type: object
to:
description: To matches destination services of requests and holds configuration.
items:
properties:
rules:
description: Rules contains the routing rules applies to a combination of top-level targetRef and the targetRef in this entry.
items:
properties:
default:
description: Default holds routing rules that can be merged with rules from other policies.
properties:
backendRefs:
items:
properties:
kind:
description: Kind of the referenced resource
enum:
- Mesh
- MeshSubset
- MeshService
- MeshServiceSubset
- MeshGatewayRoute
type: string
mesh:
description: Mesh is reserved for future use to identify cross mesh resources.
type: string
name:
description: 'Name of the referenced resource. Can only be used with kinds: `MeshService`, `MeshServiceSubset` and `MeshGatewayRoute`'
type: string
tags:
additionalProperties:
type: string
description: Tags used to select a subset of proxies by tags. Can only be used with kinds `MeshSubset` and `MeshServiceSubset`
type: object
weight:
type: integer
type: object
type: array
filters:
items:
type: object
type: array
type: object
matches:
items:
properties:
path:
properties:
prefix:
type: string
type: object
type: object
type: array
required:
- default
- matches
type: object
type: array
targetRef:
description: TargetRef is a reference to the resource that represents a group of request destinations.
properties:
kind:
description: Kind of the referenced resource
enum:
- Mesh
- MeshSubset
- MeshService
- MeshServiceSubset
- MeshGatewayRoute
type: string
mesh:
description: Mesh is reserved for future use to identify cross mesh resources.
type: string
name:
description: 'Name of the referenced resource. Can only be used with kinds: `MeshService`, `MeshServiceSubset` and `MeshGatewayRoute`'
type: string
tags:
additionalProperties:
type: string
description: Tags used to select a subset of proxies by tags. Can only be used with kinds `MeshSubset` and `MeshServiceSubset`
type: object
type: object
type: object
type: array
type: object
Loading

0 comments on commit 15ed591

Please sign in to comment.