|
| 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 | +} |
0 commit comments