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(policy): add MeshTCPRoute api with validation #6806

Merged
merged 9 commits into from
May 23, 2023
5 changes: 5 additions & 0 deletions pkg/plugins/policies/meshtcproute/api/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v1alpha1

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

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

// MeshTCPRoute
// +kuma:policy:singular_display_name=Mesh TCP 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
// +kuma:policy:skip_registration=true
type MeshTCPRoute 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 in-place.
TargetRef common_api.TargetRef `json:"targetRef"`
// To list makes a match between the consumed services and corresponding
// configurations
To []To `json:"to,omitempty"`
}

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

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

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

type BackendRef struct {
common_api.TargetRef `json:",omitempty"`
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=1
Weight *uint `json:"weight,omitempty"`
}
129 changes: 129 additions & 0 deletions pkg/plugins/policies/meshtcproute/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}/meshtcproutes/{name}:
get:
summary: Returns MeshTCPRoute entity
tags: [ "MeshTCPRoute" ]
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 MeshTCPRoute
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: 'schema.yaml'

put:
summary: Creates or Updates MeshTCPRoute entity
tags: [ "MeshTCPRoute" ]
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 MeshTCPRoute
requestBody:
description: MeshTCPRoute entity
required: true
content:
application/json:
schema:
$ref: 'schema.yaml'
responses:
'200':
description: Updated
'201':
description: Created

delete:
summary: Deletes MeshTCPRoute entity
tags: [ "MeshTCPRoute" ]
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 MeshTCPRoute
responses:
'200':
description: Successful response


/meshes/{mesh}/meshtcproutes:
get:
summary: Returns a list of MeshTCPRoute in the mesh.
tags: [ "MeshTCPRoute" ]
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


/meshtcproutes:
get:
summary: Returns a list of MeshTCPRoute from all meshes
tags: [ "MeshTCPRoute" ]
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
120 changes: 120 additions & 0 deletions pkg/plugins/policies/meshtcproute/api/v1alpha1/schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
type: object
properties:
type:
description: 'the type of the resource'
type: string
enum:
- MeshTCPRoute
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 MeshTCPRoute 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 in-place.
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 list makes a match between the consumed services and corresponding configurations
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:
default: 1
minimum: 0
type: integer
type: object
type: array
type: object
required:
- default
type: object
maxItems: 1
minItems: 1
type: array
targetRef:
description: TargetRef is a reference to the resource that represents a group of 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
required:
- rules
- targetRef
type: object
type: array
required:
- targetRef
type: object
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1alpha1_test

import (
"testing"

"github.com/kumahq/kuma/pkg/test"
)

func TestPlugin(t *testing.T) {
test.RunSpecs(t, "MeshTCPRoute")
}
Loading