Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit c8f89f6

Browse files
committed
apis/specs: Add traffic specs for v1alpha4
Adds TCPRoute and UDPRoute specs to v1alpha4 api version. Signed-off-by: Shashank Ram <[email protected]>
1 parent 468046e commit c8f89f6

34 files changed

+2471
-14
lines changed

crds/specs.yaml

+83-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
---
22
apiVersion: apiextensions.k8s.io/v1beta1
33
kind: CustomResourceDefinition
4-
metadata:
4+
metadata:
55
name: httproutegroups.specs.smi-spec.io
6-
spec:
6+
spec:
77
group: specs.smi-spec.io
8-
scope: Namespaced
9-
names:
8+
scope: Namespaced
9+
names:
1010
kind: HTTPRouteGroup
11-
shortNames:
11+
shortNames:
1212
- htr
1313
plural: httproutegroups
1414
singular: httproutegroup
15-
version: v1alpha3
15+
version: v1alpha4
1616
versions:
17-
- name: v1alpha3
17+
- name: v1alpha4
1818
served: true
1919
storage: true
20+
- name: v1alpha3
21+
served: false
22+
storage: false
2023
- name: v1alpha2
2124
served: false
2225
storage: false
@@ -72,25 +75,92 @@ spec:
7275
---
7376
apiVersion: apiextensions.k8s.io/v1beta1
7477
kind: CustomResourceDefinition
75-
metadata:
78+
metadata:
7679
name: tcproutes.specs.smi-spec.io
77-
spec:
80+
spec:
7881
group: specs.smi-spec.io
79-
scope: Namespaced
80-
names:
82+
scope: Namespaced
83+
names:
8184
kind: TCPRoute
82-
shortNames:
85+
shortNames:
8386
- tr
8487
plural: tcproutes
8588
singular: tcproute
86-
version: v1alpha3
89+
version: v1alpha4
8790
versions:
91+
- name: v1alpha4
92+
served: true
93+
storage: true
8894
- name: v1alpha3
95+
served: false
96+
storage: false
97+
- name: v1alpha2
98+
served: false
99+
storage: false
100+
- name: v1alpha1
101+
served: false
102+
storage: false
103+
validation:
104+
openAPIV3Schema:
105+
properties:
106+
spec:
107+
required:
108+
- matches
109+
properties:
110+
matches:
111+
description: Match conditions of this route.
112+
type: object
113+
required:
114+
- ports
115+
properties:
116+
ports:
117+
description: Port numbers to match TCP traffic.
118+
type: array
119+
items:
120+
type: integer
121+
---
122+
apiVersion: apiextensions.k8s.io/v1beta1
123+
kind: CustomResourceDefinition
124+
metadata:
125+
name: udproutes.specs.smi-spec.io
126+
spec:
127+
group: specs.smi-spec.io
128+
scope: Namespaced
129+
names:
130+
kind: UDPRoute
131+
shortNames:
132+
- ur
133+
plural: udproutes
134+
singular: udproute
135+
version: v1alpha4
136+
versions:
137+
- name: v1alpha4
89138
served: true
90139
storage: true
140+
- name: v1alpha3
141+
served: false
142+
storage: false
91143
- name: v1alpha2
92144
served: false
93145
storage: false
94146
- name: v1alpha1
95147
served: false
96148
storage: false
149+
validation:
150+
openAPIV3Schema:
151+
properties:
152+
spec:
153+
required:
154+
- matches
155+
properties:
156+
matches:
157+
description: Match conditions of this route.
158+
type: object
159+
required:
160+
- ports
161+
properties:
162+
ports:
163+
description: Port numbers to match UDP traffic.
164+
type: array
165+
items:
166+
type: integer

hack/update-codegen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function generate_client() {
5656
}
5757

5858
echo "##### Generating specs client ######"
59-
generate_client "specs" "v1alpha1,v1alpha2,v1alpha3"
59+
generate_client "specs" "v1alpha1,v1alpha2,v1alpha3,v1alpha4"
6060

6161
echo ""
6262
echo "###### Generating split client ######"

pkg/apis/specs/v1alpha4/doc.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// +k8s:deepcopy-gen=package
2+
// +groupName=specs.smi-spec.io
3+
4+
package v1alpha4

pkg/apis/specs/v1alpha4/helpers.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package v1alpha4
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
)
7+
8+
// UnmarshalJSON converts a given array of single value maps to one map
9+
func (h *httpHeaders) UnmarshalJSON(b []byte) error {
10+
*h = make(map[string]string)
11+
var temp []map[string]string
12+
if err := json.Unmarshal(b, &temp); err != nil {
13+
return err
14+
}
15+
16+
for _, m := range temp {
17+
if len(m) > 1 {
18+
return errors.New("incorrect length of keyval")
19+
}
20+
for key, val := range m {
21+
(*h)[key] = val
22+
}
23+
}
24+
return nil
25+
}
26+
27+
// MarshalJSON converts a given map to array of single value maps
28+
func (h httpHeaders) MarshalJSON() ([]byte, error) {
29+
var returnArr []map[string]string
30+
for key, val := range h {
31+
returnArr = append(returnArr, map[string]string{key: val})
32+
}
33+
return json.Marshal(returnArr)
34+
}

pkg/apis/specs/v1alpha4/http_route.go

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package v1alpha4
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// +genclient
8+
// +genclient:noStatus
9+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
10+
11+
// HTTPRouteGroup is used to describe HTTP/1 and HTTP/2 traffic.
12+
// It enumerates the routes that can be served by an application.
13+
type HTTPRouteGroup struct {
14+
metav1.TypeMeta `json:",inline"`
15+
16+
// Standard object's metadata.
17+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
18+
// +optional
19+
metav1.ObjectMeta `json:"metadata,omitempty"`
20+
21+
Spec HTTPRouteGroupSpec `json:"spec"`
22+
}
23+
24+
// HTTPRouteGroupSpec is the specification for a HTTPRouteGroup
25+
type HTTPRouteGroupSpec struct {
26+
// Routes for inbound traffic
27+
Matches []HTTPMatch `json:"matches,omitempty"`
28+
}
29+
30+
// HTTPMatch defines an individual route for HTTP traffic
31+
type HTTPMatch struct {
32+
// Name is the name of the match for referencing in a TrafficTarget
33+
Name string `json:"name,omitempty"`
34+
35+
// Methods for inbound traffic as defined in RFC 7231
36+
// https://tools.ietf.org/html/rfc7231#section-4
37+
Methods []string `json:"methods,omitempty"`
38+
39+
// PathRegex is a regular expression defining the route
40+
PathRegex string `json:"pathRegex,omitempty"`
41+
42+
// Headers is a list of headers used to match HTTP traffic
43+
Headers httpHeaders `json:"headers,omitempty"`
44+
}
45+
46+
// httpHeaders is a map of key/value pairs which match HTTP header name and value
47+
type httpHeaders map[string]string
48+
49+
// HTTPRouteMethod are methods allowed by the route
50+
type HTTPRouteMethod string
51+
52+
const (
53+
// HTTPRouteMethodAll is a wildcard for all HTTP methods
54+
HTTPRouteMethodAll HTTPRouteMethod = "*"
55+
// HTTPRouteMethodGet HTTP GET method
56+
HTTPRouteMethodGet HTTPRouteMethod = "GET"
57+
// HTTPRouteMethodHead HTTP HEAD method
58+
HTTPRouteMethodHead HTTPRouteMethod = "HEAD"
59+
// HTTPRouteMethodPut HTTP PUT method
60+
HTTPRouteMethodPut HTTPRouteMethod = "PUT"
61+
// HTTPRouteMethodPost HTTP POST method
62+
HTTPRouteMethodPost HTTPRouteMethod = "POST"
63+
// HTTPRouteMethodDelete HTTP DELETE method
64+
HTTPRouteMethodDelete HTTPRouteMethod = "DELETE"
65+
// HTTPRouteMethodConnect HTTP CONNECT method
66+
HTTPRouteMethodConnect HTTPRouteMethod = "CONNECT"
67+
// HTTPRouteMethodOptions HTTP OPTIONS method
68+
HTTPRouteMethodOptions HTTPRouteMethod = "OPTIONS"
69+
// HTTPRouteMethodTrace HTTP TRACE method
70+
HTTPRouteMethodTrace HTTPRouteMethod = "TRACE"
71+
// HTTPRouteMethodPatch HTTP PATCH method
72+
HTTPRouteMethodPatch HTTPRouteMethod = "PATCH"
73+
)
74+
75+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
76+
77+
// HTTPRouteGroupList satisfy K8s code gen requirements
78+
type HTTPRouteGroupList struct {
79+
metav1.TypeMeta `json:",inline"`
80+
metav1.ListMeta `json:"metadata"`
81+
82+
Items []HTTPRouteGroup `json:"items"`
83+
}

pkg/apis/specs/v1alpha4/register.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package v1alpha4
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/apimachinery/pkg/runtime"
6+
"k8s.io/apimachinery/pkg/runtime/schema"
7+
8+
ts "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/specs"
9+
)
10+
11+
// SchemeGroupVersion is the identifier for the API which includes
12+
// the name of the group and the version of the API
13+
var SchemeGroupVersion = schema.GroupVersion{
14+
Group: ts.GroupName,
15+
Version: "v1alpha4",
16+
}
17+
18+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
19+
func Kind(kind string) schema.GroupKind {
20+
return SchemeGroupVersion.WithKind(kind).GroupKind()
21+
}
22+
23+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
24+
func Resource(resource string) schema.GroupResource {
25+
return SchemeGroupVersion.WithResource(resource).GroupResource()
26+
}
27+
28+
var (
29+
// SchemeBuilder collects functions that add things to a scheme. It's to allow
30+
// code to compile without explicitly referencing generated types. You should
31+
// declare one in each package that will have generated deep copy or conversion
32+
// functions.
33+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
34+
35+
// AddToScheme applies all the stored functions to the scheme. A non-nil error
36+
// indicates that one function failed and the attempt was abandoned.
37+
AddToScheme = SchemeBuilder.AddToScheme
38+
)
39+
40+
// Adds the list of known types to Scheme.
41+
func addKnownTypes(scheme *runtime.Scheme) error {
42+
scheme.AddKnownTypes(SchemeGroupVersion,
43+
&HTTPRouteGroup{},
44+
&HTTPRouteGroupList{},
45+
&TCPRoute{},
46+
&TCPRouteList{},
47+
)
48+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
49+
return nil
50+
}

pkg/apis/specs/v1alpha4/tcp_route.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package v1alpha4
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// +genclient
8+
// +genclient:noStatus
9+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
10+
11+
// TCPRoute is used to describe TCP inbound connections
12+
type TCPRoute struct {
13+
metav1.TypeMeta `json:",inline"`
14+
15+
// Standard object's metadata.
16+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
17+
// +optional
18+
metav1.ObjectMeta `json:"metadata,omitempty"`
19+
20+
Spec TCPRouteSpec `json:"spec,omitempty"`
21+
}
22+
23+
// TCPRouteSpec is the specification of a TCPRoute
24+
type TCPRouteSpec struct {
25+
// Route match for inbound traffic
26+
Matches TCPMatch `json:"matches,omitempty"`
27+
}
28+
29+
// TCPMatch defines an individual route for TCP traffic
30+
type TCPMatch struct {
31+
// Name is the name of the match for referencing in a TrafficTarget
32+
Name string `json:"name,omitempty"`
33+
34+
// Ports to allow inbound traffic on
35+
Ports []int `json:"ports,omitempty"`
36+
}
37+
38+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
39+
40+
// TCPRouteList satisfy K8s code gen requirements
41+
type TCPRouteList struct {
42+
metav1.TypeMeta `json:",inline"`
43+
metav1.ListMeta `json:"metadata"`
44+
45+
Items []TCPRoute `json:"items"`
46+
}

0 commit comments

Comments
 (0)