|
| 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 | +// +genclient |
| 24 | +// +genclient:nonNamespaced |
| 25 | +// +kubebuilder:object:root=true |
| 26 | +// +kubebuilder:subresource:status |
| 27 | +// +kubebuilder:resource:scope=Cluster |
| 28 | + |
| 29 | +// Config holds the configuration for bpfman-operator. |
| 30 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 31 | +// +kubebuilder:printcolumn:name="Progressing",type="string",JSONPath=".status.conditions[?(@.type=='Progressing')].status" |
| 32 | +// +kubebuilder:printcolumn:name="Available",type="string",JSONPath=".status.conditions[?(@.type=='Available')].status" |
| 33 | +type Config struct { |
| 34 | + metav1.TypeMeta `json:",inline"` |
| 35 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 36 | + |
| 37 | + Spec ConfigSpec `json:"spec,omitempty"` |
| 38 | + Status ConfigStatus `json:"status,omitempty"` |
| 39 | +} |
| 40 | + |
| 41 | +// spec defines the desired state of the bpfman-operator. |
| 42 | +type ConfigSpec struct { |
| 43 | + // agent holds the configuration for the bpfman agent. |
| 44 | + // +required |
| 45 | + Agent AgentSpec `json:"agent,omitempty"` |
| 46 | + // configuration holds the content of bpfman.toml. |
| 47 | + // +required |
| 48 | + // +kubebuilder:validation:MinLength=1 |
| 49 | + Configuration string `json:"configuration"` |
| 50 | + // image holds the image of the bpfman DaemonSets. |
| 51 | + // +required |
| 52 | + // +kubebuilder:validation:MinLength=1 |
| 53 | + Image string `json:"image"` |
| 54 | + // logLevel holds the log level for the bpfman-operator. |
| 55 | + // +optional |
| 56 | + LogLevel string `json:"logLevel,omitempty"` |
| 57 | + // namespace holds the namespace where bpfman-operator resources shall be |
| 58 | + // deployed. If not specified, resources will be deployed in the default |
| 59 | + // bpfman namespace. |
| 60 | + // +optional |
| 61 | + Namespace string `json:"namespace,omitempty"` |
| 62 | +} |
| 63 | + |
| 64 | +// AgentSpec defines the desired state of the bpfman agent. |
| 65 | +type AgentSpec struct { |
| 66 | + // healthProbePort holds the health probe bind port for the bpfman agent. |
| 67 | + // The default port is 8175. The value or behavior is subject to change over time. |
| 68 | + // +optional |
| 69 | + // +kubebuilder:validation:Minimum=0 |
| 70 | + // +kubebuilder:validation:Maximum=65535 |
| 71 | + HealthProbePort int `json:"healthProbePort,omitempty"` |
| 72 | + // image holds the image for the bpfman agent. |
| 73 | + // +required |
| 74 | + // +kubebuilder:validation:Required |
| 75 | + // +kubebuilder:validation:MinLength=1 |
| 76 | + Image string `json:"image"` |
| 77 | + // logLevel holds the log level for the bpfman agent. |
| 78 | + // +optional |
| 79 | + LogLevel string `json:"logLevel,omitempty"` |
| 80 | +} |
| 81 | + |
| 82 | +// status reflects the status of the bpfman-operator configuration. |
| 83 | +type ConfigStatus struct { |
| 84 | + // conditions store the status conditions of the bpfman-operator components. |
| 85 | + // +patchMergeKey=type |
| 86 | + // +patchStrategy=merge |
| 87 | + // +listType=map |
| 88 | + // +listMapKey=type |
| 89 | + Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` |
| 90 | + |
| 91 | + // components stores the status of all components. |
| 92 | + // +optional |
| 93 | + Components map[string]ConfigComponentStatus `json:"components,omitempty"` |
| 94 | +} |
| 95 | + |
| 96 | +// +kubebuilder:object:root=true |
| 97 | +// ConfigList contains a list of Configs. |
| 98 | +type ConfigList struct { |
| 99 | + metav1.TypeMeta `json:",inline"` |
| 100 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 101 | + Items []Config `json:"items"` |
| 102 | +} |
| 103 | + |
| 104 | +type ConfigComponentStatus string |
| 105 | + |
| 106 | +const ( |
| 107 | + ConfigStatusUnknown ConfigComponentStatus = "Unknown" |
| 108 | + ConfigStatusProgressing ConfigComponentStatus = "Progressing" |
| 109 | + ConfigStatusReady ConfigComponentStatus = "Ready" |
| 110 | +) |
0 commit comments