github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/apis/apps/v1alpha1/configconstraint_types.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 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 corev1 "k8s.io/api/core/v1" 21 apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 ) 24 25 // ConfigConstraintSpec defines the desired state of ConfigConstraint 26 type ConfigConstraintSpec struct { 27 // reloadOptions indicates whether the process supports reload. 28 // if set, the controller will determine the behavior of the engine instance based on the configuration templates, 29 // restart or reload depending on whether any parameters in the StaticParameters have been modified. 30 // +optional 31 ReloadOptions *ReloadOptions `json:"reloadOptions,omitempty"` 32 33 // toolConfig used to config init container. 34 // +optional 35 ToolsImageSpec *ToolsImageSpec `json:"toolsImageSpec,omitempty"` 36 // ToolConfigs []ToolConfig `json:"toolConfigs,omitempty"` 37 38 // downwardAPIOptions is used to watch pod fields. 39 // +optional 40 DownwardAPIOptions []DownwardAPIOption `json:"downwardAPIOptions,omitempty"` 41 42 // scriptConfigs, list of ScriptConfig, witch these scripts can be used by volume trigger,downward trigger, or tool image 43 // +optional 44 // +patchMergeKey=scriptConfigMapRef 45 // +patchStrategy=merge,retainKeys 46 // +listType=map 47 // +listMapKey=scriptConfigMapRef 48 ScriptConfigs []ScriptConfig `json:"scriptConfigs,omitempty"` 49 50 // cfgSchemaTopLevelName is cue type name, which generates openapi schema. 51 // +optional 52 CfgSchemaTopLevelName string `json:"cfgSchemaTopLevelName,omitempty"` 53 54 // configurationSchema imposes restrictions on database parameter's rule. 55 // +optional 56 ConfigurationSchema *CustomParametersValidation `json:"configurationSchema,omitempty"` 57 58 // staticParameters, list of StaticParameter, modifications of them trigger a process restart. 59 // +listType=set 60 // +optional 61 StaticParameters []string `json:"staticParameters,omitempty"` 62 63 // dynamicParameters, list of DynamicParameter, modifications of them trigger a config dynamic reload without process restart. 64 // +listType=set 65 // +optional 66 DynamicParameters []string `json:"dynamicParameters,omitempty"` 67 68 // immutableParameters describes parameters that prohibit user from modification. 69 // +listType=set 70 // +optional 71 ImmutableParameters []string `json:"immutableParameters,omitempty"` 72 73 // selector is used to match the label on the pod, 74 // for example, a pod of the primary is match on the patroni cluster. 75 Selector *metav1.LabelSelector `json:"selector,omitempty"` 76 77 // formatterConfig describes the format of the configuration file, the controller 78 // 1. parses configuration file 79 // 2. analyzes the modified parameters 80 // 3. applies corresponding policies. 81 // +kubebuilder:validation:Required 82 FormatterConfig *FormatterConfig `json:"formatterConfig"` 83 } 84 85 // ConfigConstraintStatus defines the observed state of ConfigConstraint. 86 type ConfigConstraintStatus struct { 87 // phase is status of configuration template, when set to CCAvailablePhase, it can be referenced by ClusterDefinition or ClusterVersion. 88 // +optional 89 Phase ConfigConstraintPhase `json:"phase,omitempty"` 90 91 // message field describes the reasons of abnormal status. 92 // +optional 93 Message string `json:"message,omitempty"` 94 95 // observedGeneration is the latest generation observed for this 96 // ClusterDefinition. It refers to the ConfigConstraint's generation, which is 97 // updated by the API Server. 98 // +optional 99 ObservedGeneration int64 `json:"observedGeneration,omitempty"` 100 } 101 102 func (cs ConfigConstraintStatus) IsConfigConstraintTerminalPhases() bool { 103 return cs.Phase == CCAvailablePhase 104 } 105 106 type CustomParametersValidation struct { 107 // schema provides a way for providers to validate the changed parameters through json. 108 // +kubebuilder:validation:Schemaless 109 // +kubebuilder:validation:ComponentDefRef=object 110 // +kubebuilder:pruning:PreserveUnknownFields 111 Schema *apiext.JSONSchemaProps `json:"schema,omitempty"` 112 113 // cue that to let provider verify user configuration through cue language. 114 // +optional 115 CUE string `json:"cue,omitempty"` 116 } 117 118 // ReloadOptions defines reload options 119 // Only one of its members may be specified. 120 type ReloadOptions struct { 121 // unixSignalTrigger used to reload by sending a signal. 122 // +optional 123 UnixSignalTrigger *UnixSignalTrigger `json:"unixSignalTrigger,omitempty"` 124 125 // shellTrigger performs the reload command. 126 // +optional 127 ShellTrigger *ShellTrigger `json:"shellTrigger,omitempty"` 128 129 // goTplTrigger performs the reload command. 130 // +optional 131 TPLScriptTrigger *TPLScriptTrigger `json:"tplScriptTrigger"` 132 } 133 134 type UnixSignalTrigger struct { 135 // signal is valid for unix signal. 136 // e.g: SIGHUP 137 // url: ../../pkg/configuration/configmap/handler.go:allUnixSignals 138 // +kubebuilder:validation:Required 139 Signal SignalType `json:"signal"` 140 141 // processName is process name, sends unix signal to proc. 142 // +kubebuilder:validation:Required 143 ProcessName string `json:"processName"` 144 } 145 146 type ToolsImageSpec struct { 147 // auto generate 148 // volumeName is the volume name of PodTemplate, which the configuration file produced through the configuration template will be mounted to the corresponding volume. 149 // The volume name must be defined in podSpec.containers[*].volumeMounts. 150 // +kubebuilder:validation:Required 151 // +kubebuilder:validation:MaxLength=32 152 // VolumeName string `json:"volumeName"` 153 154 // mountPoint is the mount point of the scripts file. 155 // +kubebuilder:validation:Required 156 // +kubebuilder:validation:MaxLength=128 157 MountPoint string `json:"mountPoint"` 158 159 // toolConfig used to config init container. 160 // +optional 161 ToolConfigs []ToolConfig `json:"toolConfigs,omitempty"` 162 } 163 164 type ToolConfig struct { 165 // Specify the name of initContainer. Must be a DNS_LABEL name. 166 // +kubebuilder:validation:Required 167 // +kubebuilder:validation:MaxLength=63 168 // +kubebuilder:validation:Pattern:=`^[a-z]([a-z0-9\-]*[a-z0-9])?$` 169 Name string `json:"name,omitempty"` 170 171 // tools Container image name. 172 // +optional 173 Image string `json:"image,omitempty"` 174 175 // exec used to execute for init containers. 176 // +kubebuilder:validation:Required 177 Command []string `json:"command"` 178 } 179 180 type DownwardAPIOption struct { 181 // Specify the name of the field. 182 // +kubebuilder:validation:Required 183 // +kubebuilder:validation:MaxLength=63 184 // +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$` 185 Name string `json:"name"` 186 187 // mountPoint is the mount point of the scripts file. 188 // +kubebuilder:validation:Required 189 // +kubebuilder:validation:MaxLength=128 190 MountPoint string `json:"mountPoint"` 191 192 // Items is a list of downward API volume file 193 // +kubebuilder:validation:Required 194 Items []corev1.DownwardAPIVolumeFile `json:"items"` 195 196 // command used to execute for downwrad api. 197 // +optional 198 Command []string `json:"command,omitempty"` 199 } 200 201 type ScriptConfig struct { 202 // scriptConfigMapRef used to execute for reload. 203 // +kubebuilder:validation:Required 204 ScriptConfigMapRef string `json:"scriptConfigMapRef"` 205 206 // Specify the namespace of the referenced the tpl script ConfigMap object. 207 // An empty namespace is equivalent to the "default" namespace. 208 // +kubebuilder:validation:MaxLength=63 209 // +kubebuilder:default="default" 210 // +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\-]*[a-z0-9])?$` 211 // +optional 212 Namespace string `json:"namespace,omitempty"` 213 } 214 215 type ShellTrigger struct { 216 // command used to execute for reload. 217 // +kubebuilder:validation:Required 218 Command []string `json:"command"` 219 220 // Specify synchronize updates parameters to the config manager. 221 // +optional 222 Sync *bool `json:"sync,omitempty"` 223 } 224 225 type TPLScriptTrigger struct { 226 ScriptConfig `json:",inline"` 227 228 // Specify synchronize updates parameters to the config manager. 229 // +optional 230 Sync *bool `json:"sync,omitempty"` 231 } 232 233 type FormatterConfig struct { 234 // The FormatterOptions represents the special options of configuration file. 235 // This is optional for now. If not specified. 236 // +optional 237 FormatterOptions `json:",inline"` 238 239 // The configuration file format. Valid values are ini, xml, yaml, json, 240 // hcl, dotenv, properties and toml. 241 // 242 // ini: a configuration file that consists of a text-based content with a structure and syntax comprising key–value pairs for properties, reference wiki: https://en.wikipedia.org/wiki/INI_file 243 // xml: reference wiki: https://en.wikipedia.org/wiki/XML 244 // yaml: a configuration file support for complex data types and structures. 245 // json: reference wiki: https://en.wikipedia.org/wiki/JSON 246 // hcl: : The HashiCorp Configuration Language (HCL) is a configuration language authored by HashiCorp, reference url: https://www.linode.com/docs/guides/introduction-to-hcl/ 247 // dotenv: this was a plain text file with simple key–value pairs, reference wiki: https://en.wikipedia.org/wiki/Configuration_file#MS-DOS 248 // properties: a file extension mainly used in Java, reference wiki: https://en.wikipedia.org/wiki/.properties 249 // toml: reference wiki: https://en.wikipedia.org/wiki/TOML 250 // props-plus: a file extension mainly used in Java, support CamelCase(e.g: brokerMaxConnectionsPerIp) 251 // +kubebuilder:validation:Required 252 Format CfgFileFormat `json:"format"` 253 } 254 255 // FormatterOptions represents the special options of configuration file. 256 // Only one of its members may be specified. 257 type FormatterOptions struct { 258 // iniConfig represents the ini options. 259 // +optional 260 IniConfig *IniConfig `json:"iniConfig,omitempty"` 261 262 // xmlConfig represents the ini options. 263 // XMLConfig *XMLConfig `json:"xmlConfig,omitempty"` 264 } 265 266 type IniConfig struct { 267 // sectionName describes ini section. 268 // +optional 269 SectionName string `json:"sectionName,omitempty"` 270 } 271 272 // +genclient 273 // +genclient:nonNamespaced 274 // +k8s:openapi-gen=true 275 // +kubebuilder:object:root=true 276 // +kubebuilder:subresource:status 277 // +kubebuilder:resource:categories={kubeblocks},scope=Cluster,shortName=cc 278 // +kubebuilder:printcolumn:name="PHASE",type="string",JSONPath=".status.phase",description="status phase" 279 // +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" 280 281 // ConfigConstraint is the Schema for the configconstraint API 282 type ConfigConstraint struct { 283 metav1.TypeMeta `json:",inline"` 284 metav1.ObjectMeta `json:"metadata,omitempty"` 285 286 Spec ConfigConstraintSpec `json:"spec,omitempty"` 287 Status ConfigConstraintStatus `json:"status,omitempty"` 288 } 289 290 // +kubebuilder:object:root=true 291 292 // ConfigConstraintList contains a list of ConfigConstraints. 293 type ConfigConstraintList struct { 294 metav1.TypeMeta `json:",inline"` 295 metav1.ListMeta `json:"metadata,omitempty"` 296 Items []ConfigConstraint `json:"items"` 297 } 298 299 func init() { 300 SchemeBuilder.Register(&ConfigConstraint{}, &ConfigConstraintList{}) 301 }