Skip to content

Commit

Permalink
Support the rest of the program types
Browse files Browse the repository at this point in the history
Unit tests are passing, but I havn't tested the new types on kind yet.

Signed-off-by: Andre Fredette <[email protected]>
  • Loading branch information
anfredette committed Feb 5, 2025
1 parent f46a02d commit 01546e9
Show file tree
Hide file tree
Showing 56 changed files with 3,724 additions and 1,429 deletions.
63 changes: 25 additions & 38 deletions apis/v1alpha1/bpfApplicationState_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ import (
// BpfApplicationProgramState defines the desired state of BpfApplication
// +union
// +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"
// // +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"
// +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"
// +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"
// +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"
// // +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"
// // +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"
// // +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"
// // +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"
// // +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"
// // +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"
// +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"
// +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"
// +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"
// +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"
type BpfApplicationProgramState struct {
BpfProgramStateCommon `json:",inline"`
// Type specifies the bpf program type
// +unionDiscriminator
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Fentry";"Fexit";"Kprobe";"Kretprobe";"Uprobe";"Uretprobe";"Tracepoint"
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Fentry";"Fexit";"Kprobe";"Uprobe";"Tracepoint"
Type EBPFProgType `json:"type,omitempty"`

// xdp defines the desired state of the application's XdpPrograms.
Expand All @@ -62,35 +60,25 @@ type BpfApplicationProgramState struct {
// +optional
Fentry *FentryProgramInfoState `json:"fentry,omitempty"`

// // fexit defines the desired state of the application's FexitPrograms.
// // +unionMember
// // +optional
// Fexit *FexitProgramInfoState `json:"fexit,omitempty"`

// // kprobe defines the desired state of the application's KprobePrograms.
// // +unionMember
// // +optional
// Kprobe *KprobeProgramInfoState `json:"kprobe,omitempty"`

// // kretprobe defines the desired state of the application's KretprobePrograms.
// // +unionMember
// // +optional
// Kretprobe *KprobeProgramInfoState `json:"kretprobe,omitempty"`

// // uprobe defines the desired state of the application's UprobePrograms.
// // +unionMember
// // +optional
// Uprobe *UprobeProgramInfoState `json:"uprobe,omitempty"`

// // uretprobe defines the desired state of the application's UretprobePrograms.
// // +unionMember
// // +optional
// Uretprobe *UprobeProgramInfoState `json:"uretprobe,omitempty"`

// // tracepoint defines the desired state of the application's TracepointPrograms.
// // +unionMember
// // +optional
// Tracepoint *TracepointProgramInfoState `json:"tracepoint,omitempty"`
// fexit defines the desired state of the application's FexitPrograms.
// +unionMember
// +optional
Fexit *FexitProgramInfoState `json:"fexit,omitempty"`

// kprobe defines the desired state of the application's KprobePrograms.
// +unionMember
// +optional
Kprobe *KprobeProgramInfoState `json:"kprobe,omitempty"`

// uprobe defines the desired state of the application's UprobePrograms.
// +unionMember
// +optional
Uprobe *UprobeProgramInfoState `json:"uprobe,omitempty"`

// tracepoint defines the desired state of the application's TracepointPrograms.
// +unionMember
// +optional
Tracepoint *TracepointProgramInfoState `json:"tracepoint,omitempty"`
}

// BpfApplicationSpec defines the desired state of BpfApplication
Expand Down Expand Up @@ -118,7 +106,6 @@ type BpfApplicationStateSpec struct {
// +kubebuilder:resource:scope=Cluster

// BpfApplicationState contains the per-node state of a BpfApplication.
// ANF-TODO: I can't get the Node to display in the kubectl output.
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=".spec.node"
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[0].reason`
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
Expand Down
27 changes: 4 additions & 23 deletions apis/v1alpha1/bpfApplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,9 @@ const (
// ProgTypeKprobe refers to the Kprobe program type.
ProgTypeKprobe EBPFProgType = "Kprobe"

// ProgTypeKretprobe refers to the Kprobe program type.
ProgTypeKretprobe EBPFProgType = "Kretprobe"

// ProgTypeUprobe refers to the Uprobe program type.
ProgTypeUprobe EBPFProgType = "Uprobe"

// ProgTypeUretprobe refers to the Uretprobe program type.
ProgTypeUretprobe EBPFProgType = "Uretprobe"

// ProgTypeTracepoint refers to the Tracepoint program type.
ProgTypeTracepoint EBPFProgType = "Tracepoint"
)
Expand All @@ -62,17 +56,14 @@ const (
// +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"
// +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"
// +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"
// +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"
// +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"
// +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"
// +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"
// +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"
type BpfApplicationProgram struct {
BpfProgramCommon `json:",inline"`
// Type specifies the bpf program type
// +unionDiscriminator
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Fentry";"Fexit";"Kprobe";"Kretprobe";"Uprobe";"Uretprobe";"Tracepoint"
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Fentry";"Fexit";"Kprobe";"Uprobe";"Tracepoint"
Type EBPFProgType `json:"type,omitempty"`

// xdp defines the desired state of the application's XdpPrograms.
Expand Down Expand Up @@ -105,21 +96,11 @@ type BpfApplicationProgram struct {
// +optional
Kprobe *KprobeProgramInfo `json:"kprobe,omitempty"`

// kretprobe defines the desired state of the application's KretprobePrograms.
// +unionMember
// +optional
Kretprobe *KprobeProgramInfo `json:"kretprobe,omitempty"`

// uprobe defines the desired state of the application's UprobePrograms.
// +unionMember
// +optional
Uprobe *UprobeProgramInfo `json:"uprobe,omitempty"`

// uretprobe defines the desired state of the application's UretprobePrograms.
// +unionMember
// +optional
Uretprobe *UprobeProgramInfo `json:"uretprobe,omitempty"`

// tracepoint defines the desired state of the application's TracepointPrograms.
// +unionMember
// +optional
Expand All @@ -137,9 +118,9 @@ type BpfApplicationSpec struct {

// +genclient
// +genclient:nonNamespaced
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// BpfApplication is the Schema for the bpfapplications API
// +kubebuilder:printcolumn:name="NodeSelector",type=string,JSONPath=`.spec.nodeselector`
Expand Down
28 changes: 11 additions & 17 deletions apis/v1alpha1/bpfNsApplicationState_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,36 @@ import (
// BpfNsApplicationProgramState defines the desired state of BpfNsApplication
// +union
// +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"
// // +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"
// +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"
// +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"
// // +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"
// // +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"
// +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"
type BpfNsApplicationProgramState struct {
BpfProgramStateCommon `json:",inline"`
// Type specifies the bpf program type
// +unionDiscriminator
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Fentry";"Fexit";"Kprobe";"Kretprobe";"Uprobe";"Uretprobe";"Tracepoint"
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Uprobe"
Type EBPFProgType `json:"type,omitempty"`

// xdp defines the desired state of the application's XdpPrograms.
// +unionMember
// +optional
XDP *XdpNsProgramInfoState `json:"xdp,omitempty"`

// // tc defines the desired state of the application's TcPrograms.
// // +unionMember
// // +optional
// TC *TcProgramInfoState `json:"tc,omitempty"`
// tc defines the desired state of the application's TcPrograms.
// +unionMember
// +optional
TC *TcNsProgramInfoState `json:"tc,omitempty"`

// tcx defines the desired state of the application's TcxPrograms.
// +unionMember
// +optional
TCX *TcxNsProgramInfoState `json:"tcx,omitempty"`

// // uprobe defines the desired state of the application's UprobePrograms.
// // +unionMember
// // +optional
// Uprobe *UprobeProgramInfoState `json:"uprobe,omitempty"`

// // uretprobe defines the desired state of the application's UretprobePrograms.
// // +unionMember
// // +optional
// Uretprobe *UprobeProgramInfoState `json:"uretprobe,omitempty"`
// uprobe defines the desired state of the application's UprobePrograms.
// +unionMember
// +optional
Uprobe *UprobeNsProgramInfoState `json:"uprobe,omitempty"`
}

// BpfNsApplicationSpec defines the desired state of BpfNsApplication
Expand Down
14 changes: 4 additions & 10 deletions apis/v1alpha1/bpfNsApplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ import (
// +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"
// +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"
// +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"
// +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"
type BpfNsApplicationProgram struct {
BpfProgramCommon `json:",inline"`
// Type specifies the bpf program type
// +unionDiscriminator
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Uprobe";"Uretprobe"
// +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Uprobe"
Type EBPFProgType `json:"type,omitempty"`

// xdp defines the desired state of the application's XdpNsPrograms.
Expand All @@ -54,11 +53,6 @@ type BpfNsApplicationProgram struct {
// +unionMember
// +optional
Uprobe *UprobeNsProgramInfo `json:"uprobe,omitempty"`

// uretprobe defines the desired state of the application's UretprobeNsPrograms.
// +unionMember
// +optional
Uretprobe *UprobeNsProgramInfo `json:"uretprobe,omitempty"`
}

// BpfApplicationSpec defines the desired state of BpfApplication
Expand All @@ -73,9 +67,9 @@ type BpfNsApplicationSpec struct {
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Namespaced

// BpfNsApplication is the Schema for the bpfapplications API
// +kubebuilder:printcolumn:name="NodeSelector",type=string,JSONPath=`.spec.nodeselector`
Expand Down
6 changes: 3 additions & 3 deletions apis/v1alpha1/bpfNsProgram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
)

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// BpfNsProgram is the Schema for the Bpfnsprograms API
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`
Expand All @@ -41,7 +41,7 @@ type BpfNsProgram struct {
Status BpfProgramStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// BpfNsProgramList contains a list of BpfProgram
type BpfNsProgramList struct {
Expand Down
8 changes: 4 additions & 4 deletions apis/v1alpha1/bpfProgram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (

// +genclient
// +genclient:nonNamespaced
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// BpfProgram is the Schema for the Bpfprograms API
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`
Expand Down Expand Up @@ -63,7 +63,7 @@ type BpfProgramStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// BpfProgramList contains a list of BpfProgram
type BpfProgramList struct {
Expand Down
10 changes: 5 additions & 5 deletions apis/v1alpha1/fentryProgram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

// +genclient
// +genclient:nonNamespaced
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// FentryProgram is the Schema for the FentryPrograms API
// +kubebuilder:printcolumn:name="BpfFunctionName",type=string,JSONPath=`.spec.bpffunctionname`
Expand Down Expand Up @@ -84,6 +84,6 @@ type FentryProgramInfoState struct {
}

type FentryAttachInfoState struct {
AttachInfoCommon `json:",inline"`
Attach bool `json:"attach"`
AttachInfoStateCommon `json:",inline"`
Attach bool `json:"attach"`
}
16 changes: 13 additions & 3 deletions apis/v1alpha1/fexitProgram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

// +genclient
// +genclient:nonNamespaced
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// FexitProgram is the Schema for the FexitPrograms API
// +kubebuilder:printcolumn:name="BpfFunctionName",type=string,JSONPath=`.spec.bpffunctionname`
Expand Down Expand Up @@ -76,3 +76,13 @@ type FexitProgramList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []FexitProgram `json:"items"`
}

type FexitProgramInfoState struct {
FexitLoadInfo `json:",inline"`
FexitAttachInfoState `json:",inline"`
}

type FexitAttachInfoState struct {
AttachInfoStateCommon `json:",inline"`
Attach bool `json:"attach"`
}
29 changes: 25 additions & 4 deletions apis/v1alpha1/kprobeProgram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

// +genclient
// +genclient:nonNamespaced
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster

// KprobeProgram is the Schema for the KprobePrograms API
// +kubebuilder:printcolumn:name="BpfFunctionName",type=string,JSONPath=`.spec.bpffunctionname`
Expand Down Expand Up @@ -63,7 +63,7 @@ type KprobeProgramInfo struct {

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

// Offset added to the address of the function for kprobe.
Expand All @@ -85,3 +85,24 @@ type KprobeProgramList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []KprobeProgram `json:"items"`
}

type KprobeProgramInfoState struct {
// The list of points to which the program should be attached. The list is
// optional and may be udated after the bpf program has been loaded.
// +optional
AttachPoints []KprobeAttachInfoState `json:"attach_points"`
}

type KprobeAttachInfoState struct {
AttachInfoStateCommon `json:",inline"`

// Function to attach the kprobe to.
FunctionName string `json:"func_name"`

// Offset added to the address of the function for kprobe.
// Not allowed for kretprobes.
Offset uint64 `json:"offset"`

// Whether the program is a kretprobe.
RetProbe bool `json:"retprobe"`
}
Loading

0 comments on commit 01546e9

Please sign in to comment.