|
| 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:Required |
| 49 | + // +kubebuilder:validation:MinLength=1 |
| 50 | + Configuration string `json:"configuration"` |
| 51 | + // Image holds the image of the bpfman DaemonSets. |
| 52 | + // +required |
| 53 | + // +kubebuilder:validation:Required |
| 54 | + // +kubebuilder:validation:MinLength=1 |
| 55 | + Image string `json:"image"` |
| 56 | + // LogLevel holds the log level for the bpfman-operator. |
| 57 | + // +optional |
| 58 | + LogLevel string `json:"logLevel,omitempty"` |
| 59 | + // Namespace holds the namespace where bpfman-operator resources shall be |
| 60 | + // deployed. |
| 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 | + // +optional |
| 68 | + // +kubebuilder:default=8175 |
| 69 | + // +kubebuilder:validation:Minimum=1 |
| 70 | + // +kubebuilder:validation:Maximum=65535 |
| 71 | + HealthProbePort int `json:"healthProbePort"` |
| 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 *ConfigComponentStatuses `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 | +) |
| 111 | + |
| 112 | +type ConfigComponentStatuses struct { |
| 113 | + // configMap stores the status of the ConfigMap. |
| 114 | + // +optional |
| 115 | + ConfigMap *ConfigComponentStatus `json:"configMap,omitempty"` |
| 116 | + // daemonSet stores the status of the DaemonSet. |
| 117 | + // +optional |
| 118 | + DaemonSet *ConfigComponentStatus `json:"daemonSet,omitempty"` |
| 119 | + // metricsProxyDaemonSet stores the status of the MetricsProxyDaemonSet. |
| 120 | + // +optional |
| 121 | + MetricsProxyDaemonSet *ConfigComponentStatus `json:"metricsProxyDaemonSet,omitempty"` |
| 122 | + // csiDriver stores the status of the CsiDriver. |
| 123 | + // +optional |
| 124 | + CsiDriver *ConfigComponentStatus `json:"csiDriver,omitempty"` |
| 125 | + // scc stores the status of the Scc. |
| 126 | + // +optional |
| 127 | + Scc *ConfigComponentStatus `json:"scc,omitempty"` |
| 128 | +} |
0 commit comments