Skip to content

Commit 60d0115

Browse files
committed
WIP: Initial pass at BpfApplication CRD update for load/attach split
The main change is that a separate optional list of attach points is included with each program (except for fentry and fexit programs that just include an attach boolean). Otherwise, the info is all the same. The list of attach points may be updated any time after the programs are loaded, which allows the program to be loaded before any attachments are made, and allows attachments to be added after the program has been loaded. Existing controllers have been updated to work with new CRDs, but they only work with a single attach point per program. I've updated the bpfman.io_v1alpha1_bpfapplication.yaml, but the others still have the old format and won't work with the current code. TODO: Add a per-node CRD (BpfProgram analog) to maintain the per-node state for the BpfApplication. Signed-off-by: Andre Fredette <[email protected]>
1 parent 1165a8c commit 60d0115

File tree

56 files changed

+2944
-2471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2944
-2471
lines changed

apis/v1alpha1/bpfapplication_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ type BpfApplicationSpec struct {
138138

139139
// BpfApplicationStatus defines the observed state of BpfApplication
140140
type BpfApplicationStatus struct {
141-
BpfProgramStatusCommon `json:",inline"`
141+
BpfAppStatus `json:",inline"`
142142
}
143143

144144
// +genclient
@@ -155,8 +155,8 @@ type BpfApplication struct {
155155
metav1.TypeMeta `json:",inline"`
156156
metav1.ObjectMeta `json:"metadata,omitempty"`
157157

158-
Spec BpfApplicationSpec `json:"spec,omitempty"`
159-
Status BpfApplicationStatus `json:"status,omitempty"`
158+
Spec BpfApplicationSpec `json:"spec,omitempty"`
159+
Status BpfAppStatus `json:"status,omitempty"`
160160
}
161161

162162
// +kubebuilder:object:root=true

apis/v1alpha1/fentryProgram_types.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ type FentryProgram struct {
3737
metav1.TypeMeta `json:",inline"`
3838
metav1.ObjectMeta `json:"metadata,omitempty"`
3939

40-
Spec FentryProgramSpec `json:"spec"`
41-
// +optional
42-
Status FentryProgramStatus `json:"status,omitempty"`
40+
Spec FentryProgramSpec `json:"spec"`
41+
Status BpfAppStatus `json:"status,omitempty"`
4342
}
4443

4544
// FentryProgramSpec defines the desired state of FentryProgram
@@ -52,13 +51,19 @@ type FentryProgramSpec struct {
5251
// FentryProgramInfo defines the Fentry program details
5352
type FentryProgramInfo struct {
5453
BpfProgramCommon `json:",inline"`
55-
// Function to attach the fentry to.
56-
FunctionName string `json:"func_name"`
54+
FentryLoadInfo `json:",inline"`
55+
// Whether the program should be attached to the function.
56+
// This may be updated after the program has been loaded.
57+
// +optional
58+
// +kubebuilder:default=false
59+
Attach bool `json:"attach,omitempty"`
5760
}
5861

59-
// FentryProgramStatus defines the observed state of FentryProgram
60-
type FentryProgramStatus struct {
61-
BpfProgramStatusCommon `json:",inline"`
62+
// FentryLoadInfo contains the program-specific load information for Fentry
63+
// programs
64+
type FentryLoadInfo struct {
65+
// FunctionName is the name of the function to attach the Fentry program to.
66+
FunctionName string `json:"function_name"`
6267
}
6368

6469
// +kubebuilder:object:root=true

apis/v1alpha1/fexitProgram_types.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ type FexitProgram struct {
3737
metav1.TypeMeta `json:",inline"`
3838
metav1.ObjectMeta `json:"metadata,omitempty"`
3939

40-
Spec FexitProgramSpec `json:"spec"`
41-
// +optional
42-
Status FexitProgramStatus `json:"status,omitempty"`
40+
Spec FexitProgramSpec `json:"spec"`
41+
Status BpfAppStatus `json:"status,omitempty"`
4342
}
4443

4544
// FexitProgramSpec defines the desired state of FexitProgram
@@ -52,13 +51,19 @@ type FexitProgramSpec struct {
5251
// FexitProgramInfo defines the Fexit program details
5352
type FexitProgramInfo struct {
5453
BpfProgramCommon `json:",inline"`
55-
// Function to attach the fexit to.
56-
FunctionName string `json:"func_name"`
54+
FexitLoadInfo `json:",inline"`
55+
// Whether the program should be attached to the function.
56+
// This may be updated after the program has been loaded.
57+
// +optional
58+
// +kubebuilder:default=false
59+
Attach bool `json:"attach,omitempty"`
5760
}
5861

59-
// FexitProgramStatus defines the observed state of FexitProgram
60-
type FexitProgramStatus struct {
61-
BpfProgramStatusCommon `json:",inline"`
62+
// FexitLoadInfo contains the program-specific load information for Fexit
63+
// programs
64+
type FexitLoadInfo struct {
65+
// FunctionName is the name of the function to attach the Fexit program to.
66+
FunctionName string `json:"function_name"`
6267
}
6368

6469
// +kubebuilder:object:root=true

apis/v1alpha1/kprobeProgram_types.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ type KprobeProgram struct {
3939
metav1.TypeMeta `json:",inline"`
4040
metav1.ObjectMeta `json:"metadata,omitempty"`
4141

42-
Spec KprobeProgramSpec `json:"spec"`
43-
// +optional
44-
Status KprobeProgramStatus `json:"status,omitempty"`
42+
Spec KprobeProgramSpec `json:"spec"`
43+
Status BpfAppStatus `json:"status,omitempty"`
4544
}
4645

4746
// KprobeProgramSpec defines the desired state of KprobeProgram
4847
// +kubebuilder:printcolumn:name="FunctionName",type=string,JSONPath=`.spec.func_name`
4948
// +kubebuilder:printcolumn:name="Offset",type=integer,JSONPath=`.spec.offset`
5049
// +kubebuilder:printcolumn:name="RetProbe",type=boolean,JSONPath=`.spec.retprobe`
51-
// +kubebuilder:validation:XValidation:message="offset cannot be set for kretprobes",rule="self.retprobe == false || self.offset == 0"
5250
type KprobeProgramSpec struct {
5351
KprobeProgramInfo `json:",inline"`
5452
BpfAppCommon `json:",inline"`
@@ -57,7 +55,14 @@ type KprobeProgramSpec struct {
5755
// KprobeProgramInfo defines the common fields for KprobeProgram
5856
type KprobeProgramInfo struct {
5957
BpfProgramCommon `json:",inline"`
58+
// The list of points to which the program should be attached. The list is
59+
// optional and may be udated after the bpf program has been loaded
60+
// +optional
61+
AttachPoints []KprobeAttachInfo `json:"attach_points"`
62+
}
6063

64+
// +kubebuilder:validation:XValidation:message="offset cannot be set for kretprobes",rule="self.retprobe == false || self.offset == 0"
65+
type KprobeAttachInfo struct {
6166
// Functions to attach the kprobe to.
6267
FunctionName string `json:"func_name"`
6368

@@ -71,15 +76,6 @@ type KprobeProgramInfo struct {
7176
// +optional
7277
// +kubebuilder:default:=false
7378
RetProbe bool `json:"retprobe"`
74-
75-
// // Host PID of container to attach the uprobe in. (Not supported yet by bpfman.)
76-
// // +optional
77-
// ContainerPid string `json:"containerpid"`
78-
}
79-
80-
// KprobeProgramStatus defines the observed state of KprobeProgram
81-
type KprobeProgramStatus struct {
82-
BpfProgramStatusCommon `json:",inline"`
8379
}
8480

8581
// +kubebuilder:object:root=true

apis/v1alpha1/shared_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ type ContainerSelector struct {
5353
ContainerNames *[]string `json:"containernames,omitempty"`
5454
}
5555

56-
// BpfProgramCommon defines the common attributes for all BPF programs
56+
// BpfProgramCommon defines the common attributes required to load all BPF
57+
// programs.
5758
type BpfProgramCommon struct {
5859
// BpfFunctionName is the name of the function that is the entry point for the BPF
5960
// program
@@ -86,8 +87,8 @@ type BpfAppCommon struct {
8687
ByteCode BytecodeSelector `json:"bytecode"`
8788
}
8889

89-
// BpfProgramStatusCommon defines the BpfProgram status
90-
type BpfProgramStatusCommon struct {
90+
// BpfAppStatus defines the BpfProgram status
91+
type BpfAppStatus struct {
9192
// Conditions houses the global cluster state for the eBPFProgram. The explicit
9293
// condition types are defined internally.
9394
// +patchMergeKey=type

apis/v1alpha1/tcProgram_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ type TcProgram struct {
4040
metav1.TypeMeta `json:",inline"`
4141
metav1.ObjectMeta `json:"metadata,omitempty"`
4242

43-
Spec TcProgramSpec `json:"spec"`
44-
// +optional
45-
Status TcProgramStatus `json:"status,omitempty"`
43+
Spec TcProgramSpec `json:"spec"`
44+
Status BpfAppStatus `json:"status,omitempty"`
4645
}
4746

4847
// +kubebuilder:validation:Enum=unspec;ok;reclassify;shot;pipe;stolen;queued;repeat;redirect;trap;dispatcher_return
@@ -57,7 +56,13 @@ type TcProgramSpec struct {
5756
// TcProgramInfo defines the tc program details
5857
type TcProgramInfo struct {
5958
BpfProgramCommon `json:",inline"`
59+
// The list of points to which the program should be attached. The list is
60+
// optional and may be udated after the bpf program has been loaded
61+
// +optional
62+
AttachPoints []TcAttachInfo `json:"attach_points"`
63+
}
6064

65+
type TcAttachInfo struct {
6166
// Selector to determine the network interface (or interfaces)
6267
InterfaceSelector InterfaceSelector `json:"interfaceselector"`
6368

@@ -87,11 +92,6 @@ type TcProgramInfo struct {
8792
ProceedOn []TcProceedOnValue `json:"proceedon"`
8893
}
8994

90-
// TcProgramStatus defines the observed state of TcProgram
91-
type TcProgramStatus struct {
92-
BpfProgramStatusCommon `json:",inline"`
93-
}
94-
9595
// +kubebuilder:object:root=true
9696
// TcProgramList contains a list of TcPrograms
9797
type TcProgramList struct {

apis/v1alpha1/tcxProgram_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ type TcxProgram struct {
4040
metav1.TypeMeta `json:",inline"`
4141
metav1.ObjectMeta `json:"metadata,omitempty"`
4242

43-
Spec TcxProgramSpec `json:"spec"`
44-
// +optional
45-
Status TcxProgramStatus `json:"status,omitempty"`
43+
Spec TcxProgramSpec `json:"spec"`
44+
Status BpfAppStatus `json:"status,omitempty"`
4645
}
4746

4847
// TcxProgramSpec defines the desired state of TcxProgram
@@ -54,7 +53,13 @@ type TcxProgramSpec struct {
5453
// TcxProgramInfo defines the tc program details
5554
type TcxProgramInfo struct {
5655
BpfProgramCommon `json:",inline"`
56+
// The list of points to which the program should be attached. The list is
57+
// optional and may be udated after the bpf program has been loaded
58+
// +optional
59+
AttachPoints []TcxAttachInfo `json:"attach_points"`
60+
}
5761

62+
type TcxAttachInfo struct {
5863
// Selector to determine the network interface (or interfaces)
5964
InterfaceSelector InterfaceSelector `json:"interfaceselector"`
6065

@@ -77,11 +82,6 @@ type TcxProgramInfo struct {
7782
Priority int32 `json:"priority"`
7883
}
7984

80-
// TcxProgramStatus defines the observed state of TcProgram
81-
type TcxProgramStatus struct {
82-
BpfProgramStatusCommon `json:",inline"`
83-
}
84-
8585
// +kubebuilder:object:root=true
8686
// TcxProgramList contains a list of TcxPrograms
8787
type TcxProgramList struct {

apis/v1alpha1/tracepointProgram_types.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ type TracepointProgram struct {
3737
metav1.TypeMeta `json:",inline"`
3838
metav1.ObjectMeta `json:"metadata,omitempty"`
3939

40-
Spec TracepointProgramSpec `json:"spec"`
41-
// +optional
42-
Status TracepointProgramStatus `json:"status,omitempty"`
40+
Spec TracepointProgramSpec `json:"spec"`
41+
Status BpfAppStatus `json:"status,omitempty"`
4342
}
4443

4544
// TracepointProgramSpec defines the desired state of TracepointProgram
@@ -52,15 +51,16 @@ type TracepointProgramSpec struct {
5251
// TracepointProgramInfo defines the Tracepoint program details
5352
type TracepointProgramInfo struct {
5453
BpfProgramCommon `json:",inline"`
55-
56-
// Names refers to the names of kernel tracepoints to attach the
57-
// bpf program to.
58-
Names []string `json:"names"`
54+
// The list of points to which the program should be attached. The list is
55+
// optional and may be udated after the bpf program has been loaded
56+
// +optional
57+
AttachPoints []TracepointAttachInfo `json:"attach_points"`
5958
}
6059

61-
// TracepointProgramStatus defines the observed state of TracepointProgram
62-
type TracepointProgramStatus struct {
63-
BpfProgramStatusCommon `json:",inline"`
60+
type TracepointAttachInfo struct {
61+
// Name refers to the name of a kernel tracepoint to attach the
62+
// bpf program to.
63+
Name string `json:"name"`
6464
}
6565

6666
// +kubebuilder:object:root=true

apis/v1alpha1/uprobeProgram_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ type UprobeProgram struct {
4141
metav1.TypeMeta `json:",inline"`
4242
metav1.ObjectMeta `json:"metadata,omitempty"`
4343

44-
Spec UprobeProgramSpec `json:"spec"`
45-
// +optional
46-
Status UprobeProgramStatus `json:"status,omitempty"`
44+
Spec UprobeProgramSpec `json:"spec"`
45+
Status BpfAppStatus `json:"status,omitempty"`
4746
}
4847

4948
// UprobeProgramSpec defines the desired state of UprobeProgram
@@ -60,7 +59,13 @@ type UprobeProgramSpec struct {
6059
// UprobeProgramInfo contains the information about the uprobe program
6160
type UprobeProgramInfo struct {
6261
BpfProgramCommon `json:",inline"`
62+
// The list of points to which the program should be attached. The list is
63+
// optional and may be udated after the bpf program has been loaded
64+
// +optional
65+
AttachPoints []UprobeAttachInfo `json:"attach_points"`
66+
}
6367

68+
type UprobeAttachInfo struct {
6469
// Function to attach the uprobe to.
6570
// +optional
6671
FunctionName string `json:"func_name"`
@@ -93,11 +98,6 @@ type UprobeProgramInfo struct {
9398
Containers *ContainerSelector `json:"containers"`
9499
}
95100

96-
// UprobeProgramStatus defines the observed state of UprobeProgram
97-
type UprobeProgramStatus struct {
98-
BpfProgramStatusCommon `json:",inline"`
99-
}
100-
101101
// +kubebuilder:object:root=true
102102
// UprobeProgramList contains a list of UprobePrograms
103103
type UprobeProgramList struct {

apis/v1alpha1/xdpProgram_types.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ type XdpProgram struct {
3939
metav1.TypeMeta `json:",inline"`
4040
metav1.ObjectMeta `json:"metadata,omitempty"`
4141

42-
Spec XdpProgramSpec `json:"spec"`
43-
// +optional
44-
Status XdpProgramStatus `json:"status,omitempty"`
42+
Spec XdpProgramSpec `json:"spec"`
43+
Status BpfAppStatus `json:"status,omitempty"`
4544
}
4645

4746
// +kubebuilder:validation:Enum=aborted;drop;pass;tx;redirect;dispatcher_return
@@ -56,6 +55,13 @@ type XdpProgramSpec struct {
5655
// XdpProgramInfo defines the common fields for all XdpProgram types
5756
type XdpProgramInfo struct {
5857
BpfProgramCommon `json:",inline"`
58+
// The list of points to which the program should be attached. The list is
59+
// optional and may be udated after the bpf program has been loaded
60+
// +optional
61+
AttachPoints []XdpAttachInfo `json:"attach_points"`
62+
}
63+
64+
type XdpAttachInfo struct {
5965
// Selector to determine the network interface (or interfaces)
6066
InterfaceSelector InterfaceSelector `json:"interfaceselector"`
6167

@@ -83,7 +89,7 @@ type XdpProgramInfo struct {
8389

8490
// XdpProgramStatus defines the observed state of XdpProgram
8591
type XdpProgramStatus struct {
86-
BpfProgramStatusCommon `json:",inline"`
92+
BpfAppStatus `json:",inline"`
8793
}
8894

8995
// +kubebuilder:object:root=true

0 commit comments

Comments
 (0)