Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor parameters partⅣ: parameters-related controller impl #8619

Draft
wants to merge 6 commits into
base: support/improvement-parameters-api-part1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 1 addition & 76 deletions apis/apps/v1/componentdefinition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ type ComponentDefinitionSpec struct {
// +listType=map
// +listMapKey=name
// +optional
Configs []ComponentConfigSpec `json:"configs,omitempty"`
Configs []ComponentTemplateSpec `json:"configs,omitempty"`

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

type ComponentConfigSpec struct {
ComponentTemplateSpec `json:",inline"`

// Specifies the configuration files within the ConfigMap that support dynamic updates.
//
// A configuration template (provided in the form of a ConfigMap) may contain templates for multiple
// configuration files.
// Each configuration file corresponds to a key in the ConfigMap.
// Some of these configuration files may support dynamic modification and reloading without requiring
// a pod restart.
//
// If empty or omitted, all configuration files in the ConfigMap are assumed to support dynamic updates,
// and ConfigConstraint applies to all keys.
//
// +listType=set
// +optional
Keys []string `json:"keys,omitempty"`

// Specifies the name of the referenced configuration constraints object.
//
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
// +optional
ConfigConstraintRef string `json:"constraintRef,omitempty"`

// Specifies the containers to inject the ConfigMap parameters as environment variables.
//
// This is useful when application images accept parameters through environment variables and
// generate the final configuration file in the startup script based on these variables.
//
// This field allows users to specify a list of container names, and KubeBlocks will inject the environment
// variables converted from the ConfigMap into these designated containers. This provides a flexible way to
// pass the configuration items from the ConfigMap to the container without modifying the image.
//
// Deprecated: `asEnvFrom` has been deprecated since 0.9.0 and will be removed in 0.10.0.
// Use `injectEnvTo` instead.
//
// +kubebuilder:deprecatedversion:warning="This field has been deprecated since 0.9.0 and will be removed in 0.10.0"
// +listType=set
// +optional
AsEnvFrom []string `json:"asEnvFrom,omitempty"`

// Specifies the containers to inject the ConfigMap parameters as environment variables.
//
// This is useful when application images accept parameters through environment variables and
// generate the final configuration file in the startup script based on these variables.
//
// This field allows users to specify a list of container names, and KubeBlocks will inject the environment
// variables converted from the ConfigMap into these designated containers. This provides a flexible way to
// pass the configuration items from the ConfigMap to the container without modifying the image.
//
//
// +listType=set
// +optional
InjectEnvTo []string `json:"injectEnvTo,omitempty"`

// Specifies whether the configuration needs to be re-rendered after v-scale or h-scale operations to reflect changes.
//
// In some scenarios, the configuration may need to be updated to reflect the changes in resource allocation
// or cluster topology. Examples:
//
// - Redis: adjust maxmemory after v-scale operation.
// - MySQL: increase max connections after v-scale operation.
// - Zookeeper: update zoo.cfg with new node addresses after h-scale operation.
//
// +listType=set
// +optional
ReRenderResourceTypes []RerenderResourceType `json:"reRenderResourceTypes,omitempty"`

// Whether to store the final rendered parameters as a secret.
//
// +optional
AsSecret *bool `json:"asSecret,omitempty"`
}

type ConfigTemplateExtension struct {
// Specifies the name of the referenced configuration template ConfigMap object.
//
Expand Down
43 changes: 1 addition & 42 deletions apis/apps/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 4 additions & 98 deletions apis/operations/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,31 +524,12 @@ type Reconfigure struct {
// Specifies the name of the Component.
ComponentOps `json:",inline"`

// Contains a list of ConfigurationItem objects, specifying the Component's configuration template name,
// upgrade policy, and parameter key-value pairs to be updated.
// Specifies a list of key-value pairs representing parameters and their corresponding values
// within a single configuration file.
// This field is used to override or set the values of parameters without modifying the entire configuration file.
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=name
Configurations []ConfigurationItem `json:"configurations" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`

// Indicates the duration for which the parameter changes are valid.
// +optional
// TTL *int64 `json:"ttl,omitempty"`

// Specifies the time when the parameter changes should be applied.
// +kubebuilder:validation:MaxLength=19
// +kubebuilder:validation:MinLength=19
// +kubebuilder:validation:Pattern:=`^([0-9]{2})/([0-9]{2})/([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$`
// +optional
// TriggeringTime *string `json:"triggeringTime,omitempty"`

// Identifies the component to be reconfigured.
// +optional
// Selector *metav1.LabelSelector `json:"selector,omitempty"`
Parameters []appsv1.ComponentParameter `json:"parameters,omitempty"`
}

type ConfigurationItem struct {
Expand Down Expand Up @@ -1016,10 +997,6 @@ type OpsRequestStatus struct {
// +optional
CancelTimestamp metav1.Time `json:"cancelTimestamp,omitempty"`

// Records the status of a reconfiguring operation if `opsRequest.spec.type` equals to "Reconfiguring".
// +optional
ReconfiguringStatusAsComponent map[string]*ReconfiguringStatus `json:"reconfiguringStatusAsComponent,omitempty"`

// Describes the detailed status of the OpsRequest.
// Possible condition types include "Cancelled", "WaitForProgressing", "Validated", "Succeed", "Failed", "Restarting",
// "VerticalScaling", "HorizontalScaling", "VolumeExpanding", "Reconfigure", "Switchover", "Stopping", "Starting",
Expand Down Expand Up @@ -1177,77 +1154,6 @@ type PreCheckResult struct {
Message string `json:"message,omitempty"`
}

type ReconfiguringStatus struct {
// Describes the reconfiguring detail status.
// Possible condition types include "Creating", "Init", "Running", "Pending", "Merged", "MergeFailed", "FailedAndPause",
// "Upgrading", "Deleting", "FailedAndRetry", "Finished", "ReconfigurePersisting", "ReconfigurePersisted".
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`

// Describes the status of the component reconfiguring.
// +kubebuilder:validation:Required
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=name
ConfigurationStatus []ConfigurationItemStatus `json:"configurationStatus"`
}

type ConfigurationItemStatus struct {
// Indicates the name of the configuration template (as ConfigMap).
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
Name string `json:"name"`

// Records the UpgradePolicy of the configuration change operation.
// +optional
UpdatePolicy appsv1alpha1.UpgradePolicy `json:"updatePolicy,omitempty"`

// Represents the current state of the reconfiguration state machine.
// Possible values include "Creating", "Init", "Running", "Pending", "Merged", "MergeFailed", "FailedAndPause",
// "Upgrading", "Deleting", "FailedAndRetry", "Finished", "ReconfigurePersisting", "ReconfigurePersisted".
// +optional
Status string `json:"status,omitempty"`

// Provides details about the operation.
// +optional
Message string `json:"message,omitempty"`

// Records the number of pods successfully updated following a configuration change.
// +kubebuilder:default=0
// +optional
SucceedCount int32 `json:"succeedCount"`

// Represents the total count of pods intended to be updated by a configuration change.
// +kubebuilder:default=-1
// +optional
ExpectedCount int32 `json:"expectedCount"`

// Records the last state of the reconfiguration finite state machine.
// Possible values include "None", "Retry", "Failed", "NotSupport", "FailedAndRetry".
//
// - "None" describes fsm has finished and quit.
// - "Retry" describes fsm is running.
// - "Failed" describes fsm is failed and exited.
// - "NotSupport" describes fsm does not support the feature.
// - "FailedAndRetry" describes fsm is failed in current state, but can be retried.
// +optional
LastAppliedStatus string `json:"lastStatus,omitempty"`

// Stores the last applied configuration.
// +optional
LastAppliedConfiguration map[string]string `json:"lastAppliedConfiguration,omitempty"`

// Contains the updated parameters.
// +optional
UpdatedParameters UpdatedParameters `json:"updatedParameters"`
}

// UpdatedParameters holds details about the modifications made to configuration parameters.
// Example:
//
Expand Down
57 changes: 0 additions & 57 deletions apis/operations/v1alpha1/opsrequest_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ func (r *OpsRequest) ValidateOps(ctx context.Context,
return r.validateVolumeExpansion(ctx, k8sClient, cluster)
case RestartType:
return r.validateRestart(cluster)
case ReconfiguringType:
return r.validateReconfigure(ctx, k8sClient, cluster)
case SwitchoverType:
return r.validateSwitchover(cluster)
case ExposeType:
Expand Down Expand Up @@ -245,61 +243,6 @@ func (r *OpsRequest) validateVerticalScaling(cluster *appsv1.Cluster) error {
return r.checkComponentExistence(cluster, compOpsList)
}

// validateVerticalScaling validate api is legal when spec.type is VerticalScaling
func (r *OpsRequest) validateReconfigure(ctx context.Context,
k8sClient client.Client,
cluster *appsv1.Cluster) error {
if len(r.Spec.Reconfigures) == 0 {
return notEmptyError("spec.reconfigures")
}
for _, reconfigure := range r.Spec.Reconfigures {
if err := r.validateReconfigureParams(ctx, k8sClient, cluster, &reconfigure); err != nil {
return err
}
}
return nil
}

func (r *OpsRequest) validateReconfigureParams(ctx context.Context,
k8sClient client.Client,
cluster *appsv1.Cluster,
reconfigure *Reconfigure) error {
if cluster.Spec.GetComponentByName(reconfigure.ComponentName) == nil {
return fmt.Errorf("component %s not found", reconfigure.ComponentName)
}
for _, configuration := range reconfigure.Configurations {
cmObj, err := r.getConfigMap(ctx, k8sClient, fmt.Sprintf("%s-%s-%s", r.Spec.GetClusterName(), reconfigure.ComponentName, configuration.Name))
if err != nil {
return err
}
for _, key := range configuration.Keys {
// check add file
if _, ok := cmObj.Data[key.Key]; !ok && key.FileContent == "" {
return errors.Errorf("key %s not found in configmap %s", key.Key, configuration.Name)
}
if key.FileContent == "" && len(key.Parameters) == 0 {
return errors.New("key.fileContent and key.parameters cannot be empty at the same time")
}
}
}
return nil
}

func (r *OpsRequest) getConfigMap(ctx context.Context,
k8sClient client.Client,
cmName string) (*corev1.ConfigMap, error) {
cmObj := &corev1.ConfigMap{}
cmKey := client.ObjectKey{
Namespace: r.Namespace,
Name: cmName,
}

if err := k8sClient.Get(ctx, cmKey, cmObj); err != nil {
return nil, err
}
return cmObj, nil
}

// compareRequestsAndLimits compares the resource requests and limits
func compareRequestsAndLimits(resources corev1.ResourceRequirements) (string, error) {
requests := resources.Requests
Expand Down
Loading
Loading