Skip to content

Commit 9cc9c9f

Browse files
Merge pull request projectcalico#521 from tigera/SAAS-1546
[SAAS-1546] Add DPI resource
2 parents 390db56 + 5b2d840 commit 9cc9c9f

17 files changed

+1429
-1
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: (devel)
8+
creationTimestamp: null
9+
name: deeppacketinspections.crd.projectcalico.org
10+
spec:
11+
group: crd.projectcalico.org
12+
names:
13+
kind: DeepPacketInspection
14+
listKind: DeepPacketInspectionList
15+
plural: deeppacketinspections
16+
singular: deeppacketinspection
17+
scope: Namespaced
18+
versions:
19+
- name: v1
20+
schema:
21+
openAPIV3Schema:
22+
properties:
23+
apiVersion:
24+
description: 'APIVersion defines the versioned schema of this representation
25+
of an object. Servers should convert recognized schemas to the latest
26+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
27+
type: string
28+
kind:
29+
description: 'Kind is a string value representing the REST resource this
30+
object represents. Servers may infer this from the endpoint the client
31+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
32+
type: string
33+
metadata:
34+
type: object
35+
spec:
36+
description: DeepPacketInspectionSpec contains the values of the deep
37+
packet inspection.
38+
properties:
39+
selector:
40+
description: "The selector is an expression used to pick out the endpoints
41+
for which deep packet inspection should be performed on. The selector
42+
will only match endpoints in the same namespace as the DeepPacketInspection
43+
resource. \n Selector expressions follow this syntax: \n \tlabel
44+
== \"string_literal\" -> comparison, e.g. my_label == \"foo bar\"
45+
\tlabel != \"string_literal\" -> not equal; also matches if label
46+
is not present \tlabel in { \"a\", \"b\", \"c\", ... } -> true
47+
if the value of label X is one of \"a\", \"b\", \"c\" \tlabel not
48+
in { \"a\", \"b\", \"c\", ... } -> true if the value of label
49+
X is not one of \"a\", \"b\", \"c\" \thas(label_name) -> True if
50+
that label is present \t! expr -> negation of expr \texpr && expr
51+
\ -> Short-circuit and \texpr || expr -> Short-circuit or \t( expr
52+
) -> parens for grouping \tall() or the empty selector -> matches
53+
all endpoints. \n Label names are allowed to contain alphanumerics,
54+
-, _ and /. String literals are more permissive but they do not
55+
support escape characters. \n Examples (with made-up labels): \n
56+
\ttype == \"webserver\" && deployment == \"prod\" \ttype in {\"frontend\",
57+
\"backend\"} \tdeployment != \"dev\" \t! has(label_name)"
58+
type: string
59+
type: object
60+
status:
61+
description: DeepPacketInspectionStatus contains status of deep packet
62+
inspection in each node.
63+
properties:
64+
nodes:
65+
items:
66+
properties:
67+
active:
68+
properties:
69+
lastUpdated:
70+
description: Timestamp of when the active status was last
71+
updated.
72+
format: date-time
73+
type: string
74+
success:
75+
description: Success indicates if deep packet inspection
76+
is running on all workloads matching the selector.
77+
type: boolean
78+
type: object
79+
errorConditions:
80+
items:
81+
properties:
82+
lastUpdated:
83+
description: Timestamp of when this error message was
84+
added.
85+
format: date-time
86+
type: string
87+
message:
88+
description: Message from deep packet inspection error.
89+
type: string
90+
type: object
91+
maxItems: 10
92+
type: array
93+
node:
94+
description: Node identifies with a physical node from the cluster
95+
via its hostname.
96+
type: string
97+
type: object
98+
type: array
99+
type: object
100+
type: object
101+
served: true
102+
storage: true
103+
subresources:
104+
status: {}
105+
status:
106+
acceptedNames:
107+
kind: ""
108+
plural: ""
109+
conditions: []
110+
storedVersions: []
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2021 Tigera, Inc. All rights reserved.
2+
3+
package v1
4+
5+
import (
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
8+
v3 "github.com/projectcalico/libcalico-go/lib/apis/v3"
9+
)
10+
11+
// +genclient
12+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
13+
14+
// +kubebuilder:subresource:status
15+
// +k8s:openapi-gen=true
16+
type DeepPacketInspection struct {
17+
metav1.TypeMeta `json:",inline"`
18+
metav1.ObjectMeta `json:"metadata,omitempty"`
19+
Spec v3.DeepPacketInspectionSpec `json:"spec,omitempty"`
20+
Status v3.DeepPacketInspectionStatus `json:"status,omitempty"`
21+
}

lib/apis/v3/deeppacketinspection.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright (c) 2021 Tigera, Inc. All rights reserved.
2+
3+
package v3
4+
5+
import (
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
)
8+
9+
const (
10+
KindDeepPacketInspection = "DeepPacketInspection"
11+
KindDeepPacketInspectionList = "DeepPacketInspectionList"
12+
)
13+
14+
// +genclient
15+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
16+
// +kubebuilder:subresource:status
17+
18+
type DeepPacketInspection struct {
19+
metav1.TypeMeta `json:",inline"`
20+
// Standard object's metadata.
21+
metav1.ObjectMeta `json:"metadata,omitempty"`
22+
// Specification of the DeepPacketInspection.
23+
Spec DeepPacketInspectionSpec `json:"spec,omitempty"`
24+
// Status of the DeepPacketInspection.
25+
Status DeepPacketInspectionStatus `json:"status,omitempty"`
26+
}
27+
28+
// DeepPacketInspectionSpec contains the values of the deep packet inspection.
29+
type DeepPacketInspectionSpec struct {
30+
// The selector is an expression used to pick out the endpoints for which deep packet inspection should
31+
// be performed on. The selector will only match endpoints in the same namespace as the
32+
// DeepPacketInspection resource.
33+
//
34+
// Selector expressions follow this syntax:
35+
//
36+
// label == "string_literal" -> comparison, e.g. my_label == "foo bar"
37+
// label != "string_literal" -> not equal; also matches if label is not present
38+
// label in { "a", "b", "c", ... } -> true if the value of label X is one of "a", "b", "c"
39+
// label not in { "a", "b", "c", ... } -> true if the value of label X is not one of "a", "b", "c"
40+
// has(label_name) -> True if that label is present
41+
// ! expr -> negation of expr
42+
// expr && expr -> Short-circuit and
43+
// expr || expr -> Short-circuit or
44+
// ( expr ) -> parens for grouping
45+
// all() or the empty selector -> matches all endpoints.
46+
//
47+
// Label names are allowed to contain alphanumerics, -, _ and /. String literals are more permissive
48+
// but they do not support escape characters.
49+
//
50+
// Examples (with made-up labels):
51+
//
52+
// type == "webserver" && deployment == "prod"
53+
// type in {"frontend", "backend"}
54+
// deployment != "dev"
55+
// ! has(label_name)
56+
Selector string `json:"selector,omitempty" validate:"selector"`
57+
}
58+
59+
// DeepPacketInspectionStatus contains status of deep packet inspection in each node.
60+
type DeepPacketInspectionStatus struct {
61+
Nodes []DPINode `json:"nodes,omitempty"`
62+
}
63+
64+
type DPINode struct {
65+
// Node identifies with a physical node from the cluster via its hostname.
66+
Node string `json:"node,omitempty"`
67+
Active DPIActive `json:"active,omitempty"`
68+
// +kubebuilder:validation:MaxItems:=10
69+
ErrorConditions []DPIErrorCondition `json:"errorConditions,omitempty"`
70+
}
71+
72+
type DPIActive struct {
73+
// Success indicates if deep packet inspection is running on all workloads matching the selector.
74+
Success bool `json:"success,omitempty"`
75+
// Timestamp of when the active status was last updated.
76+
LastUpdated *metav1.Time `json:"lastUpdated,omitempty"`
77+
}
78+
79+
type DPIErrorCondition struct {
80+
// Message from deep packet inspection error.
81+
Message string `json:"message,omitempty"`
82+
// Timestamp of when this error message was added.
83+
LastUpdated *metav1.Time `json:"lastUpdated,omitempty"`
84+
}
85+
86+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
87+
88+
// DeepPacketInspectionList contains list of DeepPacketInspection resource.
89+
type DeepPacketInspectionList struct {
90+
metav1.TypeMeta `json:",inline"`
91+
metav1.ListMeta `json:"metadata"`
92+
Items []DeepPacketInspection `json:"items"`
93+
}
94+
95+
// NewDeepPacketInspection creates a new (zeroed) DeepPacketInspection struct with the TypeMetadata
96+
// initialized to the current version.
97+
func NewDeepPacketInspection() *DeepPacketInspection {
98+
return &DeepPacketInspection{
99+
TypeMeta: metav1.TypeMeta{
100+
Kind: KindDeepPacketInspection,
101+
APIVersion: GroupVersionCurrent,
102+
},
103+
}
104+
}
105+
106+
// NewDeepPacketInspectionList creates a new zeroed) DeepPacketInspectionList struct with the TypeMetadata
107+
// initialized to the current version.
108+
func NewDeepPacketInspectionList() *DeepPacketInspectionList {
109+
return &DeepPacketInspectionList{
110+
TypeMeta: metav1.TypeMeta{
111+
Kind: KindDeepPacketInspectionList,
112+
APIVersion: GroupVersionCurrent,
113+
},
114+
}
115+
}

0 commit comments

Comments
 (0)