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

feat(MeshHTTPRoute): initial plugin #5530

Merged
merged 16 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// +kubebuilder:object:generate=true
package v1alpha1

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

// MeshHTTPRoute
// +kuma:policy:skip_registration=true
//
// 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"`
}

// This type exists to avoid a NPE in controller-tools
type Empty struct{}

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"`

// Default is here to satisfy the many assumptions of the policy generation
// code that it exists. It isn't included in the schema.
Default Empty `json:",omitempty"`
michaelbeaumont marked this conversation as resolved.
Show resolved Hide resolved
michaelbeaumont marked this conversation as resolved.
Show resolved Hide resolved
}

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