Skip to content

Commit 10366ab

Browse files
committed
WIP: Starting work on BpfApplicationNode CRD
This commit includes an initial version of the BpfApplicationNode CRD which will be managed by the bpfman agent and contain the per-node info for a single BpfApplication CRD. TODO: Make it work. Changes are likely as the implementation details are worked out. Signed-off-by: Andre Fredette <[email protected]>
1 parent 8bf9338 commit 10366ab

32 files changed

+2455
-44
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
Copyright 2023 The bpfman Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// BpfApplicationProgramNode defines the desired state of BpfApplication
24+
// +union
25+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'XDP' ? has(self.xdp) : !has(self.xdp)",message="xdp configuration is required when type is XDP, and forbidden otherwise"
26+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'TC' ? has(self.tc) : !has(self.tc)",message="tc configuration is required when type is TC, and forbidden otherwise"
27+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'TCX' ? has(self.tcx) : !has(self.tcx)",message="tcx configuration is required when type is TCX, and forbidden otherwise"
28+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'Fentry' ? has(self.fentry) : !has(self.fentry)",message="fentry configuration is required when type is Fentry, and forbidden otherwise"
29+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'Fexit' ? has(self.fexit) : !has(self.fexit)",message="fexit configuration is required when type is Fexit, and forbidden otherwise"
30+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'Kprobe' ? has(self.kprobe) : !has(self.kprobe)",message="kprobe configuration is required when type is Kprobe, and forbidden otherwise"
31+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'Kretprobe' ? has(self.kretprobe) : !has(self.kretprobe)",message="kretprobe configuration is required when type is Kretprobe, and forbidden otherwise"
32+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'Uprobe' ? has(self.uprobe) : !has(self.uprobe)",message="uprobe configuration is required when type is Uprobe, and forbidden otherwise"
33+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'Uretprobe' ? has(self.uretprobe) : !has(self.uretprobe)",message="uretprobe configuration is required when type is Uretprobe, and forbidden otherwise"
34+
// +kubebuilder:validation:XValidation:rule="has(self.type) && self.type == 'Tracepoint' ? has(self.tracepoint) : !has(self.tracepoint)",message="tracepoint configuration is required when type is Tracepoint, and forbidden otherwise"
35+
type BpfApplicationProgramNode struct {
36+
// Type specifies the bpf program type
37+
// +unionDiscriminator
38+
// +kubebuilder:validation:Required
39+
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Fentry";"Fexit";"Kprobe";"Kretprobe";"Uprobe";"Uretprobe";"Tracepoint"
40+
Type EBPFProgType `json:"type,omitempty"`
41+
42+
// xdp defines the desired state of the application's XdpPrograms.
43+
// +unionMember
44+
// +optional
45+
XDP *XdpProgramInfoNode `json:"xdp,omitempty"`
46+
47+
// tc defines the desired state of the application's TcPrograms.
48+
// +unionMember
49+
// +optional
50+
TC *TcProgramInfoNode `json:"tc,omitempty"`
51+
52+
// // tcx defines the desired state of the application's TcxPrograms.
53+
// // +unionMember
54+
// // +optional
55+
// TCX *TcxProgramInfoNode `json:"tcx,omitempty"`
56+
57+
// fentry defines the desired state of the application's FentryPrograms.
58+
// +unionMember
59+
// +optional
60+
Fentry *FentryProgramInfoNode `json:"fentry,omitempty"`
61+
62+
// // fexit defines the desired state of the application's FexitPrograms.
63+
// // +unionMember
64+
// // +optional
65+
// Fexit *FexitProgramInfoNode `json:"fexit,omitempty"`
66+
67+
// // kprobe defines the desired state of the application's KprobePrograms.
68+
// // +unionMember
69+
// // +optional
70+
// Kprobe *KprobeProgramInfoNode `json:"kprobe,omitempty"`
71+
72+
// // kretprobe defines the desired state of the application's KretprobePrograms.
73+
// // +unionMember
74+
// // +optional
75+
// Kretprobe *KprobeProgramInfoNode `json:"kretprobe,omitempty"`
76+
77+
// // uprobe defines the desired state of the application's UprobePrograms.
78+
// // +unionMember
79+
// // +optional
80+
// Uprobe *UprobeProgramInfoNode `json:"uprobe,omitempty"`
81+
82+
// // uretprobe defines the desired state of the application's UretprobePrograms.
83+
// // +unionMember
84+
// // +optional
85+
// Uretprobe *UprobeProgramInfoNode `json:"uretprobe,omitempty"`
86+
87+
// // tracepoint defines the desired state of the application's TracepointPrograms.
88+
// // +unionMember
89+
// // +optional
90+
// Tracepoint *TracepointProgramInfoNode `json:"tracepoint,omitempty"`
91+
}
92+
93+
// BpfApplicationSpec defines the desired state of BpfApplication
94+
type BpfApplicationNodeSpec struct {
95+
// Programs is a list of bpf programs contained in the parent application.
96+
// It is a map from the bpf program name to BpfApplicationProgramNode
97+
// elements.
98+
Programs map[string]BpfApplicationProgramNode `json:"programs,omitempty"`
99+
}
100+
101+
// BpfApplicationStatus defines the observed state of BpfApplication
102+
type BpfApplicationNodeStatus struct {
103+
BpfAppStatus `json:",inline"`
104+
}
105+
106+
// +genclient
107+
// +genclient:nonNamespaced
108+
// +kubebuilder:object:root=true
109+
// +kubebuilder:subresource:status
110+
// +kubebuilder:resource:scope=Cluster
111+
112+
// BpfApplicationNode is the Schema for the bpfapplications API
113+
// +kubebuilder:printcolumn:name="NodeSelector",type=string,JSONPath=`.spec.nodeselector`
114+
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[0].reason`
115+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
116+
type BpfApplicationNode struct {
117+
metav1.TypeMeta `json:",inline"`
118+
metav1.ObjectMeta `json:"metadata,omitempty"`
119+
120+
Spec BpfApplicationNodeSpec `json:"spec,omitempty"`
121+
Status BpfAppStatus `json:"status,omitempty"`
122+
}
123+
124+
// +kubebuilder:object:root=true
125+
// BpfApplicationList contains a list of BpfApplications
126+
type BpfApplicationNodeList struct {
127+
metav1.TypeMeta `json:",inline"`
128+
metav1.ListMeta `json:"metadata,omitempty"`
129+
Items []BpfApplicationNode `json:"items"`
130+
}

apis/v1alpha1/fentryProgram_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,22 @@ type FentryProgramList struct {
7373
metav1.ListMeta `json:"metadata,omitempty"`
7474
Items []FentryProgram `json:"items"`
7575
}
76+
77+
type FentryProgramInfoNode struct {
78+
AppProgramStatus `json:",inline"`
79+
// The list of points to which the program should be attached.
80+
// FentryAttachInfoNode is similar to FentryAttachInfo, but the interface and
81+
// container selectors are expanded, and we have one instance of
82+
// FentryAttachInfoNode for each unique attach point. The list is optional and
83+
// may be udated after the bpf program has been loaded.
84+
// +optional
85+
AttachPoint FentryAttachInfoNode `json:"attach_points"`
86+
}
87+
88+
type FentryAttachInfoNode struct {
89+
AttachStatus `json:",inline"`
90+
// An identifier for the attach point assigned by bpfman. This field is
91+
// empty until the program is successfully attached and bpfman returns the
92+
// id.
93+
attachId *uint32 `json:"attachid"`
94+
}

apis/v1alpha1/shared_types.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,50 @@ type BpfAppCommon struct {
100100
ByteCode BytecodeSelector `json:"bytecode"`
101101
}
102102

103-
// BpfAppStatus defines the BpfProgram status
103+
// BpfAppStatus reflects the status of a BpfApplication or BpfApplicationNode object
104104
type BpfAppStatus struct {
105-
// Conditions houses the global cluster state for the eBPFProgram. The explicit
106-
// condition types are defined internally.
105+
// For a BpfApplication object, Conditions contains the global cluster state
106+
// for the object. For a BpfApplicationNode object, Conditions contains the
107+
// state of the BpfApplication object on the given node.
107108
// +patchMergeKey=type
108109
// +patchStrategy=merge
109110
// +listType=map
110111
// +listMapKey=type
111112
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
112113
}
113114

115+
// AppProgramStatus defines the status for a given bpf application program on a given node.
116+
type AppProgramStatus struct {
117+
// ShouldLoad reflects whether the program should be loaded.
118+
// +patchMergeKey=type
119+
// +patchStrategy=merge
120+
// +listType=map
121+
// +listMapKey=type
122+
ShouldLoad []metav1.Condition `json:"should_load,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
123+
// IsLoaded reflects whether the program should be loaded.
124+
// +patchMergeKey=type
125+
// +patchStrategy=merge
126+
// +listType=map
127+
// +listMapKey=type
128+
IsLoaded []metav1.Condition `json:"is_loaded,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
129+
}
130+
131+
// AttachStatus defines the status for one attach point for a given bpf application program
132+
type AttachStatus struct {
133+
// ShouldAttach reflects whether the attachment should exist.
134+
// +patchMergeKey=type
135+
// +patchStrategy=merge
136+
// +listType=map
137+
// +listMapKey=type
138+
ShouldAttach []metav1.Condition `json:"should_attach,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
139+
// IsAttached reflects whether the attachment exists.
140+
// +patchMergeKey=type
141+
// +patchStrategy=merge
142+
// +listType=map
143+
// +listMapKey=type
144+
IsAttached []metav1.Condition `json:"is_attached,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
145+
}
146+
114147
// PullPolicy describes a policy for if/when to pull a container image
115148
// +kubebuilder:validation:Enum=Always;Never;IfNotPresent
116149
type PullPolicy string

apis/v1alpha1/tcProgram_types.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,46 @@ type TcProgramList struct {
9999
metav1.ListMeta `json:"metadata,omitempty"`
100100
Items []TcProgram `json:"items"`
101101
}
102+
103+
type TcProgramInfoNode struct {
104+
AppProgramStatus `json:",inline"`
105+
// The list of points to which the program should be attached.
106+
// TcAttachInfoNode is similar to TcAttachInfo, but the interface and
107+
// container selectors are expanded, and we have one instance of
108+
// TcAttachInfoNode for each unique attach point. The list is optional and
109+
// may be udated after the bpf program has been loaded.
110+
// +optional
111+
AttachPoints []TcAttachInfoNode `json:"attach_points"`
112+
}
113+
114+
type TcAttachInfoNode struct {
115+
AttachStatus `json:",inline"`
116+
// An identifier for the attach point assigned by bpfman. This field is
117+
// empty until the program is successfully attached and bpfman returns the
118+
// id.
119+
attachId *uint32 `json:"attachid"`
120+
121+
// Interface name to attach the tc program to.
122+
ifName string `json:"ifname"`
123+
124+
// Optional container pid to attach the tc program in.
125+
// +optional
126+
containerPid *uint32 `json:"containerpid"`
127+
128+
// Priority specifies the priority of the tc program in relation to
129+
// other programs of the same type with the same attach point. It is a value
130+
// from 0 to 1000 where lower values have higher precedence.
131+
// +kubebuilder:validation:Minimum=0
132+
// +kubebuilder:validation:Maximum=1000
133+
Priority int32 `json:"priority"`
134+
135+
// Direction specifies the direction of traffic the tc program should
136+
// attach to for a given network device.
137+
// +kubebuilder:validation:Enum=ingress;egress
138+
Direction string `json:"direction"`
139+
140+
// ProceedOn allows the user to call other tc programs in chain on this exit code.
141+
// Multiple values are supported by repeating the parameter.
142+
// +kubebuilder:validation:MaxItems=11
143+
ProceedOn []TcProceedOnValue `json:"proceedon"`
144+
}

apis/v1alpha1/xdpProgram_types.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,41 @@ type XdpProgramList struct {
9999
metav1.ListMeta `json:"metadata,omitempty"`
100100
Items []XdpProgram `json:"items"`
101101
}
102+
103+
type XdpProgramInfoNode struct {
104+
AppProgramStatus `json:",inline"`
105+
// The list of points to which the program should be attached.
106+
// XdpAttachInfoNode is similar to XdpAttachInfo, but the interface and
107+
// container selectors are expanded, and we have one instance of
108+
// XdpAttachInfoNode for each unique attach point. The list is optional and
109+
// may be udated after the bpf program has been loaded.
110+
// +optional
111+
AttachPoints []XdpAttachInfoNode `json:"attach_points"`
112+
}
113+
114+
type XdpAttachInfoNode struct {
115+
AttachStatus `json:",inline"`
116+
// An identifier for the attach point assigned by bpfman. This field is
117+
// empty until the program is successfully attached and bpfman returns the
118+
// id.
119+
AttachId *uint32 `json:"attachid"`
120+
121+
// Interface name to attach the xdp program to.
122+
IfName string `json:"ifname"`
123+
124+
// Optional container pid to attach the xdp program in.
125+
// +optional
126+
ContainerPid *uint32 `json:"containerpid"`
127+
128+
// Priority specifies the priority of the xdp program in relation to
129+
// other programs of the same type with the same attach point. It is a value
130+
// from 0 to 1000 where lower values have higher precedence.
131+
// +kubebuilder:validation:Minimum=0
132+
// +kubebuilder:validation:Maximum=1000
133+
Priority int32 `json:"priority"`
134+
135+
// ProceedOn allows the user to call other xdp programs in chain on this exit code.
136+
// Multiple values are supported by repeating the parameter.
137+
// +kubebuilder:validation:MaxItems=6
138+
ProceedOn []XdpProceedOnValue `json:"proceedon"`
139+
}

0 commit comments

Comments
 (0)