This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apis/specs: Add traffic specs for v1alpha4
Adds TCPRoute and UDPRoute specs to v1alpha4 api version. Signed-off-by: Shashank Ram <shashr2204@gmail.com>
- Loading branch information
1 parent
468046e
commit c8f89f6
Showing
34 changed files
with
2,471 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// +k8s:deepcopy-gen=package | ||
// +groupName=specs.smi-spec.io | ||
|
||
package v1alpha4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package v1alpha4 | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
) | ||
|
||
// UnmarshalJSON converts a given array of single value maps to one map | ||
func (h *httpHeaders) UnmarshalJSON(b []byte) error { | ||
*h = make(map[string]string) | ||
var temp []map[string]string | ||
if err := json.Unmarshal(b, &temp); err != nil { | ||
return err | ||
} | ||
|
||
for _, m := range temp { | ||
if len(m) > 1 { | ||
return errors.New("incorrect length of keyval") | ||
} | ||
for key, val := range m { | ||
(*h)[key] = val | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// MarshalJSON converts a given map to array of single value maps | ||
func (h httpHeaders) MarshalJSON() ([]byte, error) { | ||
var returnArr []map[string]string | ||
for key, val := range h { | ||
returnArr = append(returnArr, map[string]string{key: val}) | ||
} | ||
return json.Marshal(returnArr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package v1alpha4 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// +genclient | ||
// +genclient:noStatus | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// HTTPRouteGroup is used to describe HTTP/1 and HTTP/2 traffic. | ||
// It enumerates the routes that can be served by an application. | ||
type HTTPRouteGroup struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// Standard object's metadata. | ||
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata | ||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec HTTPRouteGroupSpec `json:"spec"` | ||
} | ||
|
||
// HTTPRouteGroupSpec is the specification for a HTTPRouteGroup | ||
type HTTPRouteGroupSpec struct { | ||
// Routes for inbound traffic | ||
Matches []HTTPMatch `json:"matches,omitempty"` | ||
} | ||
|
||
// HTTPMatch defines an individual route for HTTP traffic | ||
type HTTPMatch struct { | ||
// Name is the name of the match for referencing in a TrafficTarget | ||
Name string `json:"name,omitempty"` | ||
|
||
// Methods for inbound traffic as defined in RFC 7231 | ||
// https://tools.ietf.org/html/rfc7231#section-4 | ||
Methods []string `json:"methods,omitempty"` | ||
|
||
// PathRegex is a regular expression defining the route | ||
PathRegex string `json:"pathRegex,omitempty"` | ||
|
||
// Headers is a list of headers used to match HTTP traffic | ||
Headers httpHeaders `json:"headers,omitempty"` | ||
} | ||
|
||
// httpHeaders is a map of key/value pairs which match HTTP header name and value | ||
type httpHeaders map[string]string | ||
|
||
// HTTPRouteMethod are methods allowed by the route | ||
type HTTPRouteMethod string | ||
|
||
const ( | ||
// HTTPRouteMethodAll is a wildcard for all HTTP methods | ||
HTTPRouteMethodAll HTTPRouteMethod = "*" | ||
// HTTPRouteMethodGet HTTP GET method | ||
HTTPRouteMethodGet HTTPRouteMethod = "GET" | ||
// HTTPRouteMethodHead HTTP HEAD method | ||
HTTPRouteMethodHead HTTPRouteMethod = "HEAD" | ||
// HTTPRouteMethodPut HTTP PUT method | ||
HTTPRouteMethodPut HTTPRouteMethod = "PUT" | ||
// HTTPRouteMethodPost HTTP POST method | ||
HTTPRouteMethodPost HTTPRouteMethod = "POST" | ||
// HTTPRouteMethodDelete HTTP DELETE method | ||
HTTPRouteMethodDelete HTTPRouteMethod = "DELETE" | ||
// HTTPRouteMethodConnect HTTP CONNECT method | ||
HTTPRouteMethodConnect HTTPRouteMethod = "CONNECT" | ||
// HTTPRouteMethodOptions HTTP OPTIONS method | ||
HTTPRouteMethodOptions HTTPRouteMethod = "OPTIONS" | ||
// HTTPRouteMethodTrace HTTP TRACE method | ||
HTTPRouteMethodTrace HTTPRouteMethod = "TRACE" | ||
// HTTPRouteMethodPatch HTTP PATCH method | ||
HTTPRouteMethodPatch HTTPRouteMethod = "PATCH" | ||
) | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// HTTPRouteGroupList satisfy K8s code gen requirements | ||
type HTTPRouteGroupList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata"` | ||
|
||
Items []HTTPRouteGroup `json:"items"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package v1alpha4 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
|
||
ts "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/specs" | ||
) | ||
|
||
// SchemeGroupVersion is the identifier for the API which includes | ||
// the name of the group and the version of the API | ||
var SchemeGroupVersion = schema.GroupVersion{ | ||
Group: ts.GroupName, | ||
Version: "v1alpha4", | ||
} | ||
|
||
// Kind takes an unqualified kind and returns back a Group qualified GroupKind | ||
func Kind(kind string) schema.GroupKind { | ||
return SchemeGroupVersion.WithKind(kind).GroupKind() | ||
} | ||
|
||
// Resource takes an unqualified resource and returns a Group qualified GroupResource | ||
func Resource(resource string) schema.GroupResource { | ||
return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
} | ||
|
||
var ( | ||
// SchemeBuilder collects functions that add things to a scheme. It's to allow | ||
// code to compile without explicitly referencing generated types. You should | ||
// declare one in each package that will have generated deep copy or conversion | ||
// functions. | ||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) | ||
|
||
// AddToScheme applies all the stored functions to the scheme. A non-nil error | ||
// indicates that one function failed and the attempt was abandoned. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) | ||
|
||
// Adds the list of known types to Scheme. | ||
func addKnownTypes(scheme *runtime.Scheme) error { | ||
scheme.AddKnownTypes(SchemeGroupVersion, | ||
&HTTPRouteGroup{}, | ||
&HTTPRouteGroupList{}, | ||
&TCPRoute{}, | ||
&TCPRouteList{}, | ||
) | ||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package v1alpha4 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// +genclient | ||
// +genclient:noStatus | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// TCPRoute is used to describe TCP inbound connections | ||
type TCPRoute struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
||
// Standard object's metadata. | ||
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata | ||
// +optional | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec TCPRouteSpec `json:"spec,omitempty"` | ||
} | ||
|
||
// TCPRouteSpec is the specification of a TCPRoute | ||
type TCPRouteSpec struct { | ||
// Route match for inbound traffic | ||
Matches TCPMatch `json:"matches,omitempty"` | ||
} | ||
|
||
// TCPMatch defines an individual route for TCP traffic | ||
type TCPMatch struct { | ||
// Name is the name of the match for referencing in a TrafficTarget | ||
Name string `json:"name,omitempty"` | ||
|
||
// Ports to allow inbound traffic on | ||
Ports []int `json:"ports,omitempty"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// TCPRouteList satisfy K8s code gen requirements | ||
type TCPRouteList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata"` | ||
|
||
Items []TCPRoute `json:"items"` | ||
} |
Oops, something went wrong.