Skip to content

Commit

Permalink
feat: support reconfigure operation for multi component (#5906)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt authored Dec 6, 2023
1 parent acb3113 commit 8902ee7
Show file tree
Hide file tree
Showing 11 changed files with 900 additions and 112 deletions.
11 changes: 9 additions & 2 deletions apis/apps/v1alpha1/opsrequest_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func NewReconfigureCondition(ops *OpsRequest) *metav1.Condition {
LastTransitionTime: metav1.Now(),
Message: fmt.Sprintf("Start to reconfigure in Cluster: %s, Component: %s",
ops.Spec.ClusterRef,
ops.Spec.Reconfigure.ComponentName),
getComponentName(ops.Spec)),
}
}

Expand All @@ -301,7 +301,7 @@ func NewReconfigureRunningCondition(ops *OpsRequest, conditionType string, confi
}
message := fmt.Sprintf("Reconfiguring in Cluster: %s, Component: %s, ConfigSpec: %s",
ops.Spec.ClusterRef,
ops.Spec.Reconfigure.ComponentName,
getComponentName(ops.Spec),
configSpecName)
if len(info) > 0 {
message = message + ", info: " + info[0]
Expand All @@ -315,6 +315,13 @@ func NewReconfigureRunningCondition(ops *OpsRequest, conditionType string, confi
}
}

func getComponentName(request OpsRequestSpec) string {
if request.Reconfigure != nil {
return request.Reconfigure.ComponentName
}
return ""
}

// NewReconfigureFailedCondition creates a condition for the failed reconfigure.
func NewReconfigureFailedCondition(ops *OpsRequest, err error) *metav1.Condition {
var msg string
Expand Down
25 changes: 24 additions & 1 deletion apis/apps/v1alpha1/opsrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,22 @@ type OpsRequestSpec struct {
// +listMapKey=componentName
VerticalScalingList []VerticalScaling `json:"verticalScaling,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"componentName"`

// Deprecate: replace by reconfigures.

// reconfigure defines the variables that need to input when updating configuration.
// +optional
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="forbidden to update spec.reconfigure"
// +kubebuilder:validation:XValidation:rule="self.configurations.size() > 0", message="Value can not be empty"
Reconfigure *Reconfigure `json:"reconfigure,omitempty"`

// reconfigure defines the variables that need to input when updating configuration.
// +optional
// +patchMergeKey=componentName
// +patchStrategy=merge,retainKeys
// +listType=map
// +listMapKey=componentName
Reconfigures []Reconfigure `json:"reconfigures,omitempty"`

// expose defines services the component needs to expose.
// +optional
// +patchMergeKey=componentName
Expand Down Expand Up @@ -487,10 +497,16 @@ type OpsRequestStatus struct {
// +optional
CancelTimestamp metav1.Time `json:"cancelTimestamp,omitempty"`

// Deprecate: replace by ReconfiguringStatusAsComponent.

// reconfiguringStatus defines the status information of reconfiguring.
// +optional
ReconfiguringStatus *ReconfiguringStatus `json:"reconfiguringStatus,omitempty"`

// reconfiguringStatus defines the status information of reconfiguring.
// +optional
ReconfiguringStatusAsComponent map[string]*ReconfiguringStatus `json:"reconfiguringStatusAsComponent,omitempty"`

// conditions describes opsRequest detail status.
// +optional
// +patchMergeKey=type
Expand Down Expand Up @@ -594,9 +610,16 @@ type OpsRequestComponentStatus struct {
}

type ReconfiguringStatus struct {
// conditions describes reconfiguring detail status.
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`

// configurationStatus describes the status of the component reconfiguring.
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
// +listType=map
Expand Down
17 changes: 16 additions & 1 deletion apis/apps/v1alpha1/opsrequest_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,24 @@ func (r *OpsRequest) validateReconfigure(ctx context.Context,
k8sClient client.Client,
cluster *Cluster) error {
reconfigure := r.Spec.Reconfigure
if reconfigure == nil {
if reconfigure == nil && len(r.Spec.Reconfigures) == 0 {
return notEmptyError("spec.reconfigure")
}
if reconfigure != nil {
return r.validateReconfigureParams(ctx, k8sClient, cluster, reconfigure)
}
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 *Cluster,
reconfigure *Reconfigure) error {
if cluster.Spec.GetComponentByName(reconfigure.ComponentName) == nil {
return fmt.Errorf("component %s not found", reconfigure.ComponentName)
}
Expand Down
29 changes: 29 additions & 0 deletions apis/apps/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 8902ee7

Please sign in to comment.