|
| 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 | + metav1types "k8s.io/apimachinery/pkg/types" |
| 22 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 23 | +) |
| 24 | + |
| 25 | +// BpfApplicationProgramNode defines the desired state of BpfApplication |
| 26 | +// +union |
| 27 | +// +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" |
| 28 | +// +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" |
| 29 | +// // +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" |
| 30 | +// +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" |
| 31 | +// // +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" |
| 32 | +// // +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" |
| 33 | +// // +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" |
| 34 | +// // +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" |
| 35 | +// // +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" |
| 36 | +// // +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" |
| 37 | +type BpfApplicationProgramNode struct { |
| 38 | + // ProgramAttachStatus records whether the program should be loaded and whether |
| 39 | + // the program is loaded. |
| 40 | + ProgramAttachStatus BpfProgramConditionType `json:"programattachstatus"` |
| 41 | + |
| 42 | + // ProgramId is the id of the program in the kernel. Not set until the |
| 43 | + // program is loaded. |
| 44 | + // +optional |
| 45 | + ProgramId *uint32 `json:"program_id"` |
| 46 | + |
| 47 | + // Type specifies the bpf program type |
| 48 | + // +unionDiscriminator |
| 49 | + // +kubebuilder:validation:Required |
| 50 | + // +kubebuilder:validation:Enum:="XDP";"TC";"TCX";"Fentry";"Fexit";"Kprobe";"Kretprobe";"Uprobe";"Uretprobe";"Tracepoint" |
| 51 | + Type EBPFProgType `json:"type,omitempty"` |
| 52 | + |
| 53 | + // xdp defines the desired state of the application's XdpPrograms. |
| 54 | + // +unionMember |
| 55 | + // +optional |
| 56 | + XDP *XdpProgramInfoNode `json:"xdp,omitempty"` |
| 57 | + |
| 58 | + // tc defines the desired state of the application's TcPrograms. |
| 59 | + // +unionMember |
| 60 | + // +optional |
| 61 | + TC *TcProgramInfoNode `json:"tc,omitempty"` |
| 62 | + |
| 63 | + // // tcx defines the desired state of the application's TcxPrograms. |
| 64 | + // // +unionMember |
| 65 | + // // +optional |
| 66 | + // TCX *TcxProgramInfoNode `json:"tcx,omitempty"` |
| 67 | + |
| 68 | + // fentry defines the desired state of the application's FentryPrograms. |
| 69 | + // +unionMember |
| 70 | + // +optional |
| 71 | + Fentry *FentryProgramInfoNode `json:"fentry,omitempty"` |
| 72 | + |
| 73 | + // // fexit defines the desired state of the application's FexitPrograms. |
| 74 | + // // +unionMember |
| 75 | + // // +optional |
| 76 | + // Fexit *FexitProgramInfoNode `json:"fexit,omitempty"` |
| 77 | + |
| 78 | + // // kprobe defines the desired state of the application's KprobePrograms. |
| 79 | + // // +unionMember |
| 80 | + // // +optional |
| 81 | + // Kprobe *KprobeProgramInfoNode `json:"kprobe,omitempty"` |
| 82 | + |
| 83 | + // // kretprobe defines the desired state of the application's KretprobePrograms. |
| 84 | + // // +unionMember |
| 85 | + // // +optional |
| 86 | + // Kretprobe *KprobeProgramInfoNode `json:"kretprobe,omitempty"` |
| 87 | + |
| 88 | + // // uprobe defines the desired state of the application's UprobePrograms. |
| 89 | + // // +unionMember |
| 90 | + // // +optional |
| 91 | + // Uprobe *UprobeProgramInfoNode `json:"uprobe,omitempty"` |
| 92 | + |
| 93 | + // // uretprobe defines the desired state of the application's UretprobePrograms. |
| 94 | + // // +unionMember |
| 95 | + // // +optional |
| 96 | + // Uretprobe *UprobeProgramInfoNode `json:"uretprobe,omitempty"` |
| 97 | + |
| 98 | + // // tracepoint defines the desired state of the application's TracepointPrograms. |
| 99 | + // // +unionMember |
| 100 | + // // +optional |
| 101 | + // Tracepoint *TracepointProgramInfoNode `json:"tracepoint,omitempty"` |
| 102 | +} |
| 103 | + |
| 104 | +// BpfApplicationSpec defines the desired state of BpfApplication |
| 105 | +type BpfApplicationNodeSpec struct { |
| 106 | + // The number of times the BpfApplicationNode has been updated. Set to 1 |
| 107 | + // when the object is created, then it is incremented prior to each update. |
| 108 | + // This allows us to verify that the API server has the updated object prior |
| 109 | + // to starting a new Reconcile operation. |
| 110 | + UpdateCount int64 `json:"updatecount"` |
| 111 | + // AppLoadStatus reflects the status of loading the bpf application on the |
| 112 | + // given node. |
| 113 | + AppLoadStatus BpfProgramConditionType `json:"apploadstatus"` |
| 114 | + // Programs is a list of bpf programs contained in the parent application. |
| 115 | + // It is a map from the bpf program name to BpfApplicationProgramNode |
| 116 | + // elements. |
| 117 | + Programs map[string]BpfApplicationProgramNode `json:"programs,omitempty"` |
| 118 | +} |
| 119 | + |
| 120 | +// +genclient |
| 121 | +// +genclient:nonNamespaced |
| 122 | +// +kubebuilder:object:root=true |
| 123 | +// +kubebuilder:subresource:status |
| 124 | +// +kubebuilder:resource:scope=Cluster |
| 125 | + |
| 126 | +// BpfApplicationNode is the Schema for the bpfapplications API |
| 127 | +// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=".metadata.labels['kubernetes.io/hostname']" |
| 128 | +// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[0].reason` |
| 129 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 130 | +type BpfApplicationNode struct { |
| 131 | + metav1.TypeMeta `json:",inline"` |
| 132 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 133 | + |
| 134 | + Spec BpfApplicationNodeSpec `json:"spec,omitempty"` |
| 135 | + Status BpfAppStatus `json:"status,omitempty"` |
| 136 | +} |
| 137 | + |
| 138 | +// +kubebuilder:object:root=true |
| 139 | +// BpfApplicationList contains a list of BpfApplications |
| 140 | +type BpfApplicationNodeList struct { |
| 141 | + metav1.TypeMeta `json:",inline"` |
| 142 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 143 | + Items []BpfApplicationNode `json:"items"` |
| 144 | +} |
| 145 | + |
| 146 | +func (an BpfApplicationNode) GetName() string { |
| 147 | + return an.Name |
| 148 | +} |
| 149 | + |
| 150 | +func (an BpfApplicationNode) GetUID() metav1types.UID { |
| 151 | + return an.UID |
| 152 | +} |
| 153 | + |
| 154 | +func (an BpfApplicationNode) GetAnnotations() map[string]string { |
| 155 | + return an.Annotations |
| 156 | +} |
| 157 | + |
| 158 | +func (an BpfApplicationNode) GetLabels() map[string]string { |
| 159 | + return an.Labels |
| 160 | +} |
| 161 | + |
| 162 | +func (an BpfApplicationNode) GetStatus() *BpfAppStatus { |
| 163 | + return &an.Status |
| 164 | +} |
| 165 | + |
| 166 | +func (an BpfApplicationNode) GetClientObject() client.Object { |
| 167 | + return &an |
| 168 | +} |
| 169 | + |
| 170 | +func (anl BpfApplicationNodeList) GetItems() []BpfApplicationNode { |
| 171 | + return anl.Items |
| 172 | +} |
0 commit comments