Skip to content

Commit 75ef901

Browse files
committed
chore: parameters controller impl
1 parent c8628de commit 75ef901

File tree

154 files changed

+4667
-7446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+4667
-7446
lines changed

apis/apps/v1/componentdefinition_types.go

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ type ComponentDefinitionSpec struct {
318318
// +listType=map
319319
// +listMapKey=name
320320
// +optional
321-
Configs []ComponentConfigSpec `json:"configs,omitempty"`
321+
Configs []ComponentTemplateSpec `json:"configs,omitempty"`
322322

323323
// Defines the types of logs generated by instances of the Component and their corresponding file paths.
324324
// These logs can be collected for further analysis and monitoring.
@@ -1056,81 +1056,6 @@ type ComponentTemplateSpec struct {
10561056
DefaultMode *int32 `json:"defaultMode,omitempty" protobuf:"varint,3,opt,name=defaultMode"`
10571057
}
10581058

1059-
type ComponentConfigSpec struct {
1060-
ComponentTemplateSpec `json:",inline"`
1061-
1062-
// Specifies the configuration files within the ConfigMap that support dynamic updates.
1063-
//
1064-
// A configuration template (provided in the form of a ConfigMap) may contain templates for multiple
1065-
// configuration files.
1066-
// Each configuration file corresponds to a key in the ConfigMap.
1067-
// Some of these configuration files may support dynamic modification and reloading without requiring
1068-
// a pod restart.
1069-
//
1070-
// If empty or omitted, all configuration files in the ConfigMap are assumed to support dynamic updates,
1071-
// and ConfigConstraint applies to all keys.
1072-
//
1073-
// +listType=set
1074-
// +optional
1075-
Keys []string `json:"keys,omitempty"`
1076-
1077-
// Specifies the name of the referenced configuration constraints object.
1078-
//
1079-
// +kubebuilder:validation:MaxLength=63
1080-
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
1081-
// +optional
1082-
ConfigConstraintRef string `json:"constraintRef,omitempty"`
1083-
1084-
// Specifies the containers to inject the ConfigMap parameters as environment variables.
1085-
//
1086-
// This is useful when application images accept parameters through environment variables and
1087-
// generate the final configuration file in the startup script based on these variables.
1088-
//
1089-
// This field allows users to specify a list of container names, and KubeBlocks will inject the environment
1090-
// variables converted from the ConfigMap into these designated containers. This provides a flexible way to
1091-
// pass the configuration items from the ConfigMap to the container without modifying the image.
1092-
//
1093-
// Deprecated: `asEnvFrom` has been deprecated since 0.9.0 and will be removed in 0.10.0.
1094-
// Use `injectEnvTo` instead.
1095-
//
1096-
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0 and will be removed in 0.10.0"
1097-
// +listType=set
1098-
// +optional
1099-
AsEnvFrom []string `json:"asEnvFrom,omitempty"`
1100-
1101-
// Specifies the containers to inject the ConfigMap parameters as environment variables.
1102-
//
1103-
// This is useful when application images accept parameters through environment variables and
1104-
// generate the final configuration file in the startup script based on these variables.
1105-
//
1106-
// This field allows users to specify a list of container names, and KubeBlocks will inject the environment
1107-
// variables converted from the ConfigMap into these designated containers. This provides a flexible way to
1108-
// pass the configuration items from the ConfigMap to the container without modifying the image.
1109-
//
1110-
//
1111-
// +listType=set
1112-
// +optional
1113-
InjectEnvTo []string `json:"injectEnvTo,omitempty"`
1114-
1115-
// Specifies whether the configuration needs to be re-rendered after v-scale or h-scale operations to reflect changes.
1116-
//
1117-
// In some scenarios, the configuration may need to be updated to reflect the changes in resource allocation
1118-
// or cluster topology. Examples:
1119-
//
1120-
// - Redis: adjust maxmemory after v-scale operation.
1121-
// - MySQL: increase max connections after v-scale operation.
1122-
// - Zookeeper: update zoo.cfg with new node addresses after h-scale operation.
1123-
//
1124-
// +listType=set
1125-
// +optional
1126-
ReRenderResourceTypes []RerenderResourceType `json:"reRenderResourceTypes,omitempty"`
1127-
1128-
// Whether to store the final rendered parameters as a secret.
1129-
//
1130-
// +optional
1131-
AsSecret *bool `json:"asSecret,omitempty"`
1132-
}
1133-
11341059
type ConfigTemplateExtension struct {
11351060
// Specifies the name of the referenced configuration template ConfigMap object.
11361061
//

apis/apps/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/operations/v1alpha1/opsrequest_types.go

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -525,31 +525,12 @@ type Reconfigure struct {
525525
// Specifies the name of the Component.
526526
ComponentOps `json:",inline"`
527527

528-
// Contains a list of ConfigurationItem objects, specifying the Component's configuration template name,
529-
// upgrade policy, and parameter key-value pairs to be updated.
528+
// Specifies a list of key-value pairs representing parameters and their corresponding values
529+
// within a single configuration file.
530+
// This field is used to override or set the values of parameters without modifying the entire configuration file.
530531
//
531-
// +kubebuilder:validation:Required
532-
// +kubebuilder:validation:MinItems=1
533-
// +patchMergeKey=name
534-
// +patchStrategy=merge,retainKeys
535-
// +listType=map
536-
// +listMapKey=name
537-
Configurations []ConfigurationItem `json:"configurations" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`
538-
539-
// Indicates the duration for which the parameter changes are valid.
540-
// +optional
541-
// TTL *int64 `json:"ttl,omitempty"`
542-
543-
// Specifies the time when the parameter changes should be applied.
544-
// +kubebuilder:validation:MaxLength=19
545-
// +kubebuilder:validation:MinLength=19
546-
// +kubebuilder:validation:Pattern:=`^([0-9]{2})/([0-9]{2})/([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$`
547-
// +optional
548-
// TriggeringTime *string `json:"triggeringTime,omitempty"`
549-
550-
// Identifies the component to be reconfigured.
551532
// +optional
552-
// Selector *metav1.LabelSelector `json:"selector,omitempty"`
533+
Parameters []appsv1.ComponentParameter `json:"parameters,omitempty"`
553534
}
554535

555536
type ConfigurationItem struct {
@@ -1017,10 +998,6 @@ type OpsRequestStatus struct {
1017998
// +optional
1018999
CancelTimestamp metav1.Time `json:"cancelTimestamp,omitempty"`
10191000

1020-
// Records the status of a reconfiguring operation if `opsRequest.spec.type` equals to "Reconfiguring".
1021-
// +optional
1022-
ReconfiguringStatusAsComponent map[string]*ReconfiguringStatus `json:"reconfiguringStatusAsComponent,omitempty"`
1023-
10241001
// Describes the detailed status of the OpsRequest.
10251002
// Possible condition types include "Cancelled", "WaitForProgressing", "Validated", "Succeed", "Failed", "Restarting",
10261003
// "VerticalScaling", "HorizontalScaling", "VolumeExpanding", "Reconfigure", "Switchover", "Stopping", "Starting",
@@ -1178,77 +1155,6 @@ type PreCheckResult struct {
11781155
Message string `json:"message,omitempty"`
11791156
}
11801157

1181-
type ReconfiguringStatus struct {
1182-
// Describes the reconfiguring detail status.
1183-
// Possible condition types include "Creating", "Init", "Running", "Pending", "Merged", "MergeFailed", "FailedAndPause",
1184-
// "Upgrading", "Deleting", "FailedAndRetry", "Finished", "ReconfigurePersisting", "ReconfigurePersisted".
1185-
// +optional
1186-
// +patchMergeKey=type
1187-
// +patchStrategy=merge
1188-
// +listType=map
1189-
// +listMapKey=type
1190-
Conditions []metav1.Condition `json:"conditions,omitempty"`
1191-
1192-
// Describes the status of the component reconfiguring.
1193-
// +kubebuilder:validation:Required
1194-
// +patchMergeKey=name
1195-
// +patchStrategy=merge,retainKeys
1196-
// +listType=map
1197-
// +listMapKey=name
1198-
ConfigurationStatus []ConfigurationItemStatus `json:"configurationStatus"`
1199-
}
1200-
1201-
type ConfigurationItemStatus struct {
1202-
// Indicates the name of the configuration template (as ConfigMap).
1203-
// +kubebuilder:validation:Required
1204-
// +kubebuilder:validation:MaxLength=63
1205-
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
1206-
Name string `json:"name"`
1207-
1208-
// Records the UpgradePolicy of the configuration change operation.
1209-
// +optional
1210-
UpdatePolicy appsv1alpha1.UpgradePolicy `json:"updatePolicy,omitempty"`
1211-
1212-
// Represents the current state of the reconfiguration state machine.
1213-
// Possible values include "Creating", "Init", "Running", "Pending", "Merged", "MergeFailed", "FailedAndPause",
1214-
// "Upgrading", "Deleting", "FailedAndRetry", "Finished", "ReconfigurePersisting", "ReconfigurePersisted".
1215-
// +optional
1216-
Status string `json:"status,omitempty"`
1217-
1218-
// Provides details about the operation.
1219-
// +optional
1220-
Message string `json:"message,omitempty"`
1221-
1222-
// Records the number of pods successfully updated following a configuration change.
1223-
// +kubebuilder:default=0
1224-
// +optional
1225-
SucceedCount int32 `json:"succeedCount"`
1226-
1227-
// Represents the total count of pods intended to be updated by a configuration change.
1228-
// +kubebuilder:default=-1
1229-
// +optional
1230-
ExpectedCount int32 `json:"expectedCount"`
1231-
1232-
// Records the last state of the reconfiguration finite state machine.
1233-
// Possible values include "None", "Retry", "Failed", "NotSupport", "FailedAndRetry".
1234-
//
1235-
// - "None" describes fsm has finished and quit.
1236-
// - "Retry" describes fsm is running.
1237-
// - "Failed" describes fsm is failed and exited.
1238-
// - "NotSupport" describes fsm does not support the feature.
1239-
// - "FailedAndRetry" describes fsm is failed in current state, but can be retried.
1240-
// +optional
1241-
LastAppliedStatus string `json:"lastStatus,omitempty"`
1242-
1243-
// Stores the last applied configuration.
1244-
// +optional
1245-
LastAppliedConfiguration map[string]string `json:"lastAppliedConfiguration,omitempty"`
1246-
1247-
// Contains the updated parameters.
1248-
// +optional
1249-
UpdatedParameters UpdatedParameters `json:"updatedParameters"`
1250-
}
1251-
12521158
// UpdatedParameters holds details about the modifications made to configuration parameters.
12531159
// Example:
12541160
//

apis/operations/v1alpha1/opsrequest_validation.go

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ func (r *OpsRequest) ValidateOps(ctx context.Context,
139139
return r.validateVolumeExpansion(ctx, k8sClient, cluster)
140140
case RestartType:
141141
return r.validateRestart(cluster)
142-
case ReconfiguringType:
143-
return r.validateReconfigure(ctx, k8sClient, cluster)
144142
case SwitchoverType:
145143
return r.validateSwitchover(ctx, k8sClient, cluster)
146144
case ExposeType:
@@ -245,61 +243,6 @@ func (r *OpsRequest) validateVerticalScaling(cluster *appsv1.Cluster) error {
245243
return r.checkComponentExistence(cluster, compOpsList)
246244
}
247245

248-
// validateVerticalScaling validate api is legal when spec.type is VerticalScaling
249-
func (r *OpsRequest) validateReconfigure(ctx context.Context,
250-
k8sClient client.Client,
251-
cluster *appsv1.Cluster) error {
252-
if len(r.Spec.Reconfigures) == 0 {
253-
return notEmptyError("spec.reconfigures")
254-
}
255-
for _, reconfigure := range r.Spec.Reconfigures {
256-
if err := r.validateReconfigureParams(ctx, k8sClient, cluster, &reconfigure); err != nil {
257-
return err
258-
}
259-
}
260-
return nil
261-
}
262-
263-
func (r *OpsRequest) validateReconfigureParams(ctx context.Context,
264-
k8sClient client.Client,
265-
cluster *appsv1.Cluster,
266-
reconfigure *Reconfigure) error {
267-
if cluster.Spec.GetComponentByName(reconfigure.ComponentName) == nil {
268-
return fmt.Errorf("component %s not found", reconfigure.ComponentName)
269-
}
270-
for _, configuration := range reconfigure.Configurations {
271-
cmObj, err := r.getConfigMap(ctx, k8sClient, fmt.Sprintf("%s-%s-%s", r.Spec.GetClusterName(), reconfigure.ComponentName, configuration.Name))
272-
if err != nil {
273-
return err
274-
}
275-
for _, key := range configuration.Keys {
276-
// check add file
277-
if _, ok := cmObj.Data[key.Key]; !ok && key.FileContent == "" {
278-
return errors.Errorf("key %s not found in configmap %s", key.Key, configuration.Name)
279-
}
280-
if key.FileContent == "" && len(key.Parameters) == 0 {
281-
return errors.New("key.fileContent and key.parameters cannot be empty at the same time")
282-
}
283-
}
284-
}
285-
return nil
286-
}
287-
288-
func (r *OpsRequest) getConfigMap(ctx context.Context,
289-
k8sClient client.Client,
290-
cmName string) (*corev1.ConfigMap, error) {
291-
cmObj := &corev1.ConfigMap{}
292-
cmKey := client.ObjectKey{
293-
Namespace: r.Namespace,
294-
Name: cmName,
295-
}
296-
297-
if err := k8sClient.Get(ctx, cmKey, cmObj); err != nil {
298-
return nil, err
299-
}
300-
return cmObj, nil
301-
}
302-
303246
// compareRequestsAndLimits compares the resource requests and limits
304247
func compareRequestsAndLimits(resources corev1.ResourceRequirements) (string, error) {
305248
requests := resources.Requests

0 commit comments

Comments
 (0)