github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/apis/apps/v1alpha1/configuration_types.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package v1alpha1 21 22 import ( 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 ) 25 26 // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! 27 // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 28 29 type ConfigurationItemDetail struct { 30 // Specify the name of configuration template. 31 // +kubebuilder:validation:Required 32 // +kubebuilder:validation:MaxLength=63 33 // +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$` 34 Name string `json:"name"` 35 36 // version is the version of configuration template. 37 // +optional 38 Version string `json:"version,omitempty"` 39 40 // configSpec is used to set the configuration template. 41 // +optional 42 ConfigSpec *ComponentConfigSpec `json:"configSpec"` 43 44 // Specify the configuration template. 45 // +optional 46 ImportTemplateRef *ConfigTemplateExtension `json:"importTemplateRef"` 47 48 // configFileParams is used to set the parameters to be updated. 49 // +optional 50 ConfigFileParams map[string]ConfigParams `json:"configFileParams,omitempty"` 51 } 52 53 // ConfigurationSpec defines the desired state of Configuration 54 type ConfigurationSpec struct { 55 // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster 56 // Important: Run "make" to regenerate code after modifying this file 57 58 // clusterRef references Cluster name. 59 // +kubebuilder:validation:Required 60 // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.clusterRef" 61 ClusterRef string `json:"clusterRef"` 62 63 // componentName is cluster component name. 64 // +kubebuilder:validation:Required 65 // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.clusterRef" 66 ComponentName string `json:"componentName"` 67 68 // customConfigurationItems describes user-defined config template. 69 // +optional 70 // +patchMergeKey=name 71 // +patchStrategy=merge,retainKeys 72 // +listType=map 73 // +listMapKey=name 74 ConfigItemDetails []ConfigurationItemDetail `json:"configItemDetails,omitempty"` 75 } 76 77 type ReconcileDetail struct { 78 // policy is the policy of the latest execution. 79 // +optional 80 Policy string `json:"policy"` 81 // execResult is the result of the latest execution. 82 // +optional 83 ExecResult string `json:"execResult"` 84 85 // currentRevision is the current revision of configurationItem. 86 // +optional 87 CurrentRevision string `json:"currentRevision,omitempty"` 88 89 // succeedCount is the number of pods for which configuration changes were successfully executed. 90 // +kubebuilder:default=-1 91 // +optional 92 SucceedCount int32 `json:"succeedCount,omitempty"` 93 94 // expectedCount is the number of pods that need to be executed for configuration changes. 95 // +kubebuilder:default=-1 96 // +optional 97 ExpectedCount int32 `json:"expectedCount,omitempty"` 98 99 // errMessage is the error message when the configuration change execution fails. 100 // +optional 101 ErrMessage string `json:"errMessage,omitempty"` 102 } 103 104 type ConfigurationItemDetailStatus struct { 105 // name is a config template name. 106 // +kubebuilder:validation:Required 107 // +kubebuilder:validation:MaxLength=63 108 // +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$` 109 Name string `json:"name"` 110 111 // phase is status of configurationItem. 112 // +optional 113 Phase ConfigurationPhase `json:"phase,omitempty"` 114 115 // lastDoneRevision is the last done revision of configurationItem. 116 // +optional 117 LastDoneRevision string `json:"lastDoneRevision,omitempty"` 118 119 // currentRevision is the current revision of configurationItem. 120 // +optional 121 // CurrentRevision string `json:"currentRevision,omitempty"` 122 123 // updateRevision is the update revision of configurationItem. 124 // +optional 125 UpdateRevision string `json:"updateRevision,omitempty"` 126 127 // message field describes the reasons of abnormal status. 128 // +optional 129 Message *string `json:"message,omitempty"` 130 131 // reconcileDetail describes the details of the configuration change execution. 132 // +optional 133 ReconcileDetail *ReconcileDetail `json:"reconcileDetail,omitempty"` 134 } 135 136 // ConfigurationStatus defines the observed state of Configuration 137 type ConfigurationStatus struct { 138 // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster 139 // Important: Run "make" to regenerate code after modifying this file 140 141 // message field describes the reasons of abnormal status. 142 // +optional 143 Message string `json:"message,omitempty"` 144 145 // observedGeneration is the latest generation observed for this 146 // ClusterDefinition. It refers to the ConfigConstraint's generation, which is 147 // updated by the API Server. 148 // +optional 149 ObservedGeneration int64 `json:"observedGeneration,omitempty"` 150 151 // conditions describes opsRequest detail status. 152 // +optional 153 // +patchMergeKey=type 154 // +patchStrategy=merge 155 // +listType=map 156 // +listMapKey=type 157 Conditions []metav1.Condition `json:"conditions,omitempty"` 158 159 // configurationStatus describes the status of the component reconfiguring. 160 // +patchMergeKey=name 161 // +patchStrategy=merge,retainKeys 162 // +listType=map 163 // +listMapKey=name 164 ConfigurationItemStatus []ConfigurationItemDetailStatus `json:"configurationStatus"` 165 } 166 167 //+kubebuilder:object:root=true 168 //+kubebuilder:subresource:status 169 170 // Configuration is the Schema for the configurations API 171 type Configuration struct { 172 metav1.TypeMeta `json:",inline"` 173 metav1.ObjectMeta `json:"metadata,omitempty"` 174 175 Spec ConfigurationSpec `json:"spec,omitempty"` 176 Status ConfigurationStatus `json:"status,omitempty"` 177 } 178 179 //+kubebuilder:object:root=true 180 181 // ConfigurationList contains a list of Configuration 182 type ConfigurationList struct { 183 metav1.TypeMeta `json:",inline"` 184 metav1.ListMeta `json:"metadata,omitempty"` 185 Items []Configuration `json:"items"` 186 } 187 188 func init() { 189 SchemeBuilder.Register(&Configuration{}, &ConfigurationList{}) 190 } 191 192 func (configuration *ConfigurationSpec) GetConfigurationItem(name string) *ConfigurationItemDetail { 193 for i := range configuration.ConfigItemDetails { 194 configItem := &configuration.ConfigItemDetails[i] 195 if configItem.Name == name { 196 return configItem 197 } 198 } 199 return nil 200 } 201 202 func (status *ConfigurationStatus) GetItemStatus(name string) *ConfigurationItemDetailStatus { 203 for i := range status.ConfigurationItemStatus { 204 itemStatus := &status.ConfigurationItemStatus[i] 205 if itemStatus.Name == name { 206 return itemStatus 207 } 208 } 209 return nil 210 }