|
| 1 | +/* |
| 2 | +Copyright 2023. |
| 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 | + apitypes "github.com/oceanbase/ob-operator/api/types" |
| 21 | + tasktypes "github.com/oceanbase/ob-operator/pkg/task/types" |
| 22 | + |
| 23 | + corev1 "k8s.io/api/core/v1" |
| 24 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 25 | +) |
| 26 | + |
| 27 | +// OBClusterReference identifies an OBCluster resource that this OBProxy connects to. |
| 28 | +type OBClusterReference struct { |
| 29 | + // Namespace of the referenced OBCluster. Defaults to the namespace of the OBProxy resource. |
| 30 | + // +optional |
| 31 | + Namespace string `json:"namespace,omitempty"` |
| 32 | + // Name of the OBCluster resource. |
| 33 | + Name string `json:"name"` |
| 34 | +} |
| 35 | + |
| 36 | +// OBProxySpec defines the desired state of OBProxy |
| 37 | +type OBProxySpec struct { |
| 38 | + // Reference to the target OBCluster. |
| 39 | + OBCluster OBClusterReference `json:"obCluster"` |
| 40 | + |
| 41 | + // ProxyClusterName is the OBProxy cluster (application) name used inside OceanBase proxy. |
| 42 | + ProxyClusterName string `json:"proxyClusterName"` |
| 43 | + |
| 44 | + // ProxySysSecret is the name of a Secret in the same namespace as this OBProxy that holds |
| 45 | + // the root@proxysys password. The Secret must contain a key named "password". |
| 46 | + ProxySysSecret string `json:"proxySysSecret"` |
| 47 | + |
| 48 | + // Image is the OBProxy container image (e.g. oceanbase/obproxy-ce:tag). |
| 49 | + Image string `json:"image"` |
| 50 | + |
| 51 | + // ServiceType is the Kubernetes Service type exposed for SQL access. |
| 52 | + // +kubebuilder:default=ClusterIP |
| 53 | + // +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer;ExternalName |
| 54 | + ServiceType string `json:"serviceType,omitempty"` |
| 55 | + |
| 56 | + // Replicas is the number of OBProxy pods. |
| 57 | + // +kubebuilder:default=1 |
| 58 | + // +kubebuilder:validation:Minimum=1 |
| 59 | + Replicas int32 `json:"replicas"` |
| 60 | + |
| 61 | + // Resource limits and requests for each OBProxy pod. |
| 62 | + Resource *apitypes.ResourceSpec `json:"resource"` |
| 63 | + |
| 64 | + // Parameters are optional OBProxy configuration key-value pairs (mapped to proxy startup config). |
| 65 | + // +optional |
| 66 | + Parameters []apitypes.Parameter `json:"parameters,omitempty"` |
| 67 | + |
| 68 | + // ServiceAccount is the name of the ServiceAccount to use for OBProxy pods. |
| 69 | + // +kubebuilder:default=default |
| 70 | + // +optional |
| 71 | + ServiceAccount string `json:"serviceAccount,omitempty"` |
| 72 | + |
| 73 | + // NodeSelector constrains OBProxy pods to nodes matching these labels. |
| 74 | + // +optional |
| 75 | + NodeSelector map[string]string `json:"nodeSelector,omitempty"` |
| 76 | + |
| 77 | + // Affinity defines scheduling affinity rules for OBProxy pods. |
| 78 | + // +optional |
| 79 | + Affinity *corev1.Affinity `json:"affinity,omitempty"` |
| 80 | + |
| 81 | + // Tolerations allow OBProxy pods to be scheduled on tainted nodes. |
| 82 | + // +optional |
| 83 | + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` |
| 84 | +} |
| 85 | + |
| 86 | +// OBProxyStatus defines the observed state of OBProxy |
| 87 | +type OBProxyStatus struct { |
| 88 | + // High-level phase, e.g. Running, Pending, Failed. |
| 89 | + Status string `json:"status,omitempty"` |
| 90 | + |
| 91 | + // Image is the container image currently running in the Deployment (observed). |
| 92 | + Image string `json:"image,omitempty"` |
| 93 | + |
| 94 | + // Replicas is the replica count currently set in the Deployment (observed). |
| 95 | + Replicas int32 `json:"replicas,omitempty"` |
| 96 | + |
| 97 | + // ReadyReplicas is the number of ready OBProxy pods (observed). |
| 98 | + ReadyReplicas int32 `json:"readyReplicas,omitempty"` |
| 99 | + |
| 100 | + // RSList is the RS_LIST env value currently set in the Deployment (observed). |
| 101 | + // +optional |
| 102 | + RSList string `json:"rsList,omitempty"` |
| 103 | + |
| 104 | + // RSListSource indicates how RSList was last resolved: "k8s" or "sql". |
| 105 | + // +optional |
| 106 | + RSListSource string `json:"rsListSource,omitempty"` |
| 107 | + |
| 108 | + // ServiceIP is the ClusterIP of the managed Service (observed). |
| 109 | + // +optional |
| 110 | + ServiceIP string `json:"serviceIP,omitempty"` |
| 111 | + |
| 112 | + // Conditions holds granular state for diagnostic purposes. |
| 113 | + // Known types: OBClusterAvailable, OBClusterReady, RSListAvailable. |
| 114 | + // +optional |
| 115 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 116 | + |
| 117 | + // OperationContext carries long-running task progress when using the operator task flow. |
| 118 | + // +optional |
| 119 | + OperationContext *tasktypes.OperationContext `json:"operationContext,omitempty"` |
| 120 | +} |
| 121 | + |
| 122 | +//+kubebuilder:object:root=true |
| 123 | +//+kubebuilder:subresource:status |
| 124 | +//+kubebuilder:resource:shortName=obp |
| 125 | +//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status" |
| 126 | +//+kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".status.replicas" |
| 127 | +//+kubebuilder:printcolumn:name="Ready",type="integer",JSONPath=".status.readyReplicas" |
| 128 | +//+kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".spec.obCluster.name" |
| 129 | +//+kubebuilder:printcolumn:name="RSListSrc",type="string",JSONPath=".status.rsListSource" |
| 130 | +//+kubebuilder:printcolumn:name="ServiceIP",type="string",JSONPath=".status.serviceIP",priority=1 |
| 131 | +//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 132 | + |
| 133 | +// OBProxy is the Schema for the obproxies API |
| 134 | +type OBProxy struct { |
| 135 | + metav1.TypeMeta `json:",inline"` |
| 136 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 137 | + |
| 138 | + Spec OBProxySpec `json:"spec,omitempty"` |
| 139 | + Status OBProxyStatus `json:"status,omitempty"` |
| 140 | +} |
| 141 | + |
| 142 | +//+kubebuilder:object:root=true |
| 143 | + |
| 144 | +// OBProxyList contains a list of OBProxy |
| 145 | +type OBProxyList struct { |
| 146 | + metav1.TypeMeta `json:",inline"` |
| 147 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 148 | + Items []OBProxy `json:"items"` |
| 149 | +} |
| 150 | + |
| 151 | +func init() { |
| 152 | + SchemeBuilder.Register(&OBProxy{}, &OBProxyList{}) |
| 153 | +} |
0 commit comments