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

Commit a81ede5

Browse files
author
Michelle Noorali
committed
feat(*): add traffic access v1alpha3 api
- update traffic access struct to make rule and source required as per servicemeshinterface/smi-spec#192 Signed-off-by: Michelle Noorali <[email protected]>
1 parent 582f6b2 commit a81ede5

23 files changed

+1059
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ vendor
1515
Gopkg.lock
1616

1717
.vscode
18+
19+
.DS_Store

hack/update-codegen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ generate_client "split" "v1alpha1,v1alpha2,v1alpha3"
6464

6565
echo ""
6666
echo "##### Generating access client ######"
67-
generate_client "access" "v1alpha1,v1alpha2"
67+
generate_client "access" "v1alpha1,v1alpha2,v1alpha3"
6868

6969
echo ""
7070
echo "##### Generating metrics client ######"

pkg/apis/access/v1alpha3/doc.go

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

pkg/apis/access/v1alpha3/register.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package v1alpha3
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/access"
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: "v1alpha3",
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+
&TrafficTarget{},
44+
&TrafficTargetList{},
45+
)
46+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
47+
return nil
48+
}
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package v1alpha3
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+
// TrafficTarget associates a set of traffic definitions (rules) with a service identity which is allocated to a group of pods.
12+
// Access is controlled via referenced TrafficSpecs and by a list of source service identities.
13+
// * If a pod which holds the referenced service identity makes a call to the destination on one of the defined routes then access
14+
// will be allowed
15+
// * Any pod which attempts to connect and is not in the defined list of sources will be denied
16+
// * Any pod which is in the defined list, but attempts to connect on a route which is not in the list of the
17+
// TrafficSpecs will be denied
18+
type TrafficTarget struct {
19+
metav1.TypeMeta `json:",inline"`
20+
// Standard object's metadata.
21+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
22+
// +optional
23+
metav1.ObjectMeta `json:"metadata,omitempty"`
24+
25+
Spec TrafficTargetSpec `json:"spec"`
26+
}
27+
28+
// TrafficTargetSpec is the specification of a TrafficTarget
29+
type TrafficTargetSpec struct {
30+
// Selector is the pod or group of pods to allow ingress traffic
31+
Destination IdentityBindingSubject `json:"destination"`
32+
33+
// Sources are the pod or group of pods to allow ingress traffic
34+
Sources []IdentityBindingSubject `json:"sources,omitempty"`
35+
36+
// Rules are the traffic rules to allow (HTTPRoutes | TCPRoute)
37+
Rules []TrafficTargetRule `json:"rules,omitempty"`
38+
}
39+
40+
// TrafficTargetRule is the TrafficSpec to allow for a TrafficTarget
41+
type TrafficTargetRule struct {
42+
// Kind is the kind of TrafficSpec to allow
43+
Kind string `json:"kind"`
44+
45+
// Name of the TrafficSpec to use
46+
Name string `json:"name"`
47+
48+
// Matches is a list of TrafficSpec routes to allow traffic for
49+
// +optional
50+
Matches []string `json:"matches,omitempty"`
51+
}
52+
53+
// IdentityBindingSubject is a Kubernetes objects which should be allowed access to the TrafficTarget
54+
type IdentityBindingSubject struct {
55+
// Kind is the type of Subject to allow ingress (ServiceAccount | Group)
56+
Kind string `json:"kind"`
57+
58+
// Name of the Subject, i.e. ServiceAccountName
59+
Name string `json:"name"`
60+
61+
// Namespace where the Subject is deployed
62+
// +optional
63+
Namespace string `json:"namespace,omitempty"`
64+
65+
// Port defines a TCP port to apply the TrafficTarget to
66+
// +optional
67+
Port *int `json:"port,omitempty"`
68+
}
69+
70+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
71+
//
72+
// TrafficTargetList satisfy K8s code gen requirements
73+
type TrafficTargetList struct {
74+
metav1.TypeMeta `json:",inline"`
75+
metav1.ListMeta `json:"metadata"`
76+
77+
Items []TrafficTarget `json:"items"`
78+
}

pkg/apis/access/v1alpha3/zz_generated.deepcopy.go

+156
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/gen/client/access/clientset/versioned/clientset.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/gen/client/access/clientset/versioned/fake/clientset_generated.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)